Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sarah and Brooke - Pine - Part 1 #16

Open
wants to merge 25 commits into
base: main
Choose a base branch
from

Conversation

sarahstandish
Copy link

No description provided.

Copy link

@jbieniosek jbieniosek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work on this project! This project is green.

app/planets.py Outdated
Comment on lines 14 to 20
def create_planet_dictionary(self):
return {
"id": self.id,
"name": self.name,
"description": self.description,
"has moons": self.has_moons
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great helper function!

app/routes.py Outdated
def handle_planet(planet_id):
for planet in planets:
if int(planet_id) == planet.id:
return jsonify(planet.create_planet_dictionary())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

self.description = description
self.has_moons = has_moons
self.id = Planet.number_of_planets
Planet.increase_number_of_planets()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neat idea!

Copy link

@CheezItMan CheezItMan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work Sarah & Brooke, you hit the learning goals here. Well done.

Comment on lines +17 to +23
if not test_config:
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('DATABASE_CONNECTION_STRING')
else:
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get('TEST_DATABASE_CONNECTION_STRING')
app.config['TESTING'] = True

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice use of env variables

description = db.Column(db.String(200))
has_moons = db.Column(db.Boolean)

def create_planet_dictionary(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great helper function, maybe call this to_dict instead?

Comment on lines +13 to +15
if type(request_body) == list:
for planet in request_body:
new_planet = Planet(name = planet["name"], description = planet["description"], has_moons = planet["has_moons"])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No input validation?

Comment on lines +29 to +35
elif request.method == "GET":
planets = Planet.query.all()
planet_list = []
for planet in planets:
planet_list.append(planet.create_planet_dictionary())

return jsonify(planet_list), 200

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

return { "Error" : f"Planet {planet_id} was not found."}, 404

if request.method == "GET":
return jsonify(planet.create_planet_dictionary())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability in these cases I suggest also including a response code

Suggested change
return jsonify(planet.create_planet_dictionary())
return jsonify(planet.create_planet_dictionary()), 200

"id" : 2
}]

def test_post_all_planets_returns_201(client):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Great that you added tests, future tests would cover the error cases like for post requests with missing or invalid data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants