Skip to content

Zoisite- Katherine G and Madi J#20

Open
Kguarnizo wants to merge 29 commits intoAda-C19:mainfrom
Kguarnizo:main
Open

Zoisite- Katherine G and Madi J#20
Kguarnizo wants to merge 29 commits intoAda-C19:mainfrom
Kguarnizo:main

Conversation

@Kguarnizo
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@kelsey-steven-ada kelsey-steven-ada 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 waves 1 and 2 for Solar System, Katherine & Madi! It looks like you've got a handle on creating a blueprint, registering it with your Flask app, and writing routes. I like the code refactors so that the routes can stay short and sweet!

Comment thread app/routes.py Outdated
Comment on lines +28 to +30
planets_response = []
for planet in planets:
planets_response.append(planet.to_dict())
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This would be a good candidate for a list comprehension, what could that look like?

Copy link
Copy Markdown

@kelsey-steven-ada kelsey-steven-ada 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 Madi & Katherine! I've left a few comments & questions, feel free to reply here or message me on Slack if you have questions on the feedback 🙂

Comment thread app/__init__.py

else:
app.config["TESTING"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The line app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False is duplicated in both parts of the if/else. We could move that line to either above or below the if/else, so it only needs to be written once.

Comment thread app/helper.py
from app.models.planet import Planet
from flask import Blueprint, jsonify, abort, make_response, request

def validate_model(cls,model_id):
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tiny style best practices note: we should add a space between each parameter to a function to give readers a visual separation, this helps people read and parse lines easier & faster.

Comment thread app/helper.py
try:
model_id = int(model_id)
except:
abort(make_response({"error message": f"{cls.__name__} {model_id} is invalid"}, 400))
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These lines are a little long for PEP8 best practices, how could we rearrange things over a couple lines to stay under 79 characters?

Comment thread app/helper.py
@@ -0,0 +1,16 @@
from app import db
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 helper.py for organization ^_^

Comment thread app/models/planet.py

class Planet(db.Model):
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String, nullable=False)
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 nullable, it'd be hard to know what planet we're working with if it doesn't have a name!

Comment thread app/routes.py
Comment on lines +52 to +54
planet.name = request_body["name"]
planet.description = request_body["description"]
planet.num_moons = request_body["num_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.

What happens if the user forgot a key? What error handling could be helpful for the user?

Comment thread app/routes.py

db.session.commit()

return make_response(f"Planet {planet.id} successfully updated")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

If we want to be sure we're consistent about the format we're using to send back messages, we could wrap the message in a call to jsonify like we do in create_planets to ensure the response is in JSON format.

Comment thread tests/conftest.py
Comment on lines +21 to +22


Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Tiny style nitpick: our whitespace should be meaningful inside a file. Is there a distinction we're trying to draw between the app fixture and other fixtures in this file? If not, I suggest using a single blank line to separate the functions for consistency.

Comment thread tests/conftest.py
)
db.session.add(planet)
db.session.commit()
return planet
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 choice to return the planet so you can use its values for the assertions in the test test_get_one_planet_returns_seeded_planet.

Comment thread tests/test_routes.py
Comment on lines +66 to +68
assert planet_one.name == EXPECTED_PLANET_ONE_NAME["name"]
assert planet_two.description == EXPECTED_PLANET_TWO_DESCRIPTION["description"]
assert planet_three.num_moons == EXPECTED_PLANET_THREE_NUM_MOONS["num_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.

We've confirmed a single attribute's value on each model, but this doesn't guarantee the data is accurate on all the models. It's better practice to check all the attributes on the relevant models to ensure there are no strange issues. (A hypothetical situation: what if the name field wasn't being saved after the first model was created? By only checking the name on the first Planet, we wouldn't catch this.)

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.

3 participants