Skip to content

Zoisite - Raissa Barbossa, Sabs Ford, Liz Trejo#23

Open
lizforloops wants to merge 15 commits intoAda-C19:mainfrom
raissaglaucie:main
Open

Zoisite - Raissa Barbossa, Sabs Ford, Liz Trejo#23
lizforloops wants to merge 15 commits intoAda-C19:mainfrom
raissaglaucie:main

Conversation

@lizforloops
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

This looks great, y'all! Well done!

Comment thread app/__init__.py Outdated
from .routes import planet_bp
app.register_blueprint(planet_bp)

return app 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.

Looks good!

Comment thread app/routes.py Outdated
Planet(6, "Saturn", "ringed planet", 72367),
Planet(7, "Neptune", "blue planet", 30599),
Planet(8, "Uranus", "furthest planet", 31518)
]
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Well done setting up the planet class and your planets list!

Comment thread app/routes.py Outdated
@planet_bp.route("", methods=["GET"])
def read_planets():
planet_list = [planet.make_dict() for planet in planets]
return jsonify(planet_list)
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 use of a list comprehension here!

Copy link
Copy Markdown

@apradoada apradoada left a comment

Choose a reason for hiding this comment

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

Well done, y'all! This looks really great!

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.

Notice that lines 16 and 22 are the same. This can be pulled out of the conditional to avoid duplicate code!

Comment thread app/models/planet.py
id = db.Column(db.Integer, primary_key=True, autoincrement=True)
name = db.Column(db.String)
description = db.Column(db.String)
diameter= db.Column(db.Float)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

When designing your class, think about whether or not each attribute should be required. I can see a case for name being a required attribute!

Comment thread app/models/planet.py
name=planet_data['name'],
description=planet_data['description'],
diameter=planet_data['diameter']
) 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/routes.py
message = f"{cls.__name__} {model_id} not found"
abort(make_response({"message": message}, 404))

return model
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 job modifying the validate method to be non-class specific!

Comment thread app/routes.py
"message": "Invalid request body",
"error": str(e)
}
abort(make_response(jsonify(error_dict), 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.

I love the error handling y'all did here! Great idea making sure the appropriate keys are included in the request. As mentioned before, if you are going to include this error handling, it's a good idea to be consistent and make the class' attributes non-nullable!

Comment thread app/routes.py
"message": "Invalid request body",
"error": str(e)
}
abort(make_response(jsonify(error_dict), 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.

Well done with the error handling here as well!

Comment thread app/routes.py
db.session.commit()

message = f"Planet #{planet.id} {planet.name} successfully deleted"
return make_response(jsonify(message)), 200 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 tests/conftest.py
diameter="86881")

db.session.add_all([mercury_planet, jupter_planet])
db.session.commit()
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 job creating a custom fixture that will update the database!

Comment thread tests/test_routes.py
def test_validate_model_invalid_id(two_saved_planets):
# Act & Assert
with pytest.raises(HTTPException):
result_planet = validate_model(Planet, "dog") 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.

This is how you do testing. This is so robust and well done! Great job y'all!

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