Skip to content

Sarah and Brooke - Pine - Part 1#16

Open
sarahstandish wants to merge 25 commits intoAda-C16:mainfrom
sarahstandish:main
Open

Sarah and Brooke - Pine - Part 1#16
sarahstandish wants to merge 25 commits intoAda-C16:mainfrom
sarahstandish:main

Conversation

@sarahstandish
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@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.

Comment thread 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
} No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Great helper function!

Comment thread 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()) No newline at end of file
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💯

Comment thread app/planets.py
self.description = description
self.has_moons = has_moons
self.id = Planet.number_of_planets
Planet.increase_number_of_planets()
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Neat idea!

Copy link
Copy Markdown

@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 thread app/__init__.py
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
Copy link
Copy Markdown

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

Comment thread app/models/planet.py
description = db.Column(db.String(200))
has_moons = db.Column(db.Boolean)

def create_planet_dictionary(self):
Copy link
Copy Markdown

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 thread app/routes.py
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"])
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No input validation?

Comment thread app/routes.py
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
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

👍

Comment thread app/routes.py
return { "Error" : f"Planet {planet_id} was not found."}, 404

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

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

Comment thread tests/test_routes.py
"id" : 2
}]

def test_post_all_planets_returns_201(client):
Copy link
Copy Markdown

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