Skip to content

wave 1 and 2 completed#32

Open
n2020h wants to merge 19 commits intoAda-C18:mainfrom
n2020h:main
Open

wave 1 and 2 completed#32
n2020h wants to merge 19 commits intoAda-C18:mainfrom
n2020h:main

Conversation

@n2020h
Copy link
Copy Markdown

@n2020h n2020h commented Oct 26, 2022

Tigers - Neema and Maria

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.

Overall nice work. I left some comments and suggestions. Let me know if you have any questions via slack.

Comment thread app/models/planet.py
Comment on lines +10 to +24
def to_dict(self):
planet_as_dict = {}
planet_as_dict["id"] = self.id
planet_as_dict["name"] = self.name
planet_as_dict["description"] = self.description
planet_as_dict["moons"]=self.moons

return planet_as_dict

def from_json(cls, req_body):
return cls(
name = req_body["name"],
description = req_body["description"],
moons = req_body["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.

Good helper methods

Comment thread app/routes/routes.py
Comment on lines +10 to +21
def validate_model(cls, model_id):
try:
model_id = int(model_id)
except:
abort(make_response({"message":f"{cls.__name__} {model_id} invalid"}, 400))

model = cls.query.get(model_id)

if not model:
abort(make_response({"message":f"{cls.__name__} {model_id} not found"}, 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 helper function

Comment thread app/routes/routes.py


@planets_bp.route("", methods=["POST"])
def handle_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.

Why name this function handle_planets and not create_planet?

Comment thread app/routes/routes.py
Comment on lines +68 to +71
planet.name = request_body["name"]
planet.description = request_body["description"]
planet.moons = request_body["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.

Doing some validation on the request body here would be good. i.e. make sure it has the given fields and they are valid.

Comment thread tests/test_routes.py
Comment on lines +46 to +56
assert response_body[0] == {
'id': 1,
'name': 'Mars',
'description': 'Too hot',
'moons': 2}

assert response_body[1] == {
'id': 2,
'name' : 'Earth',
'description' : 'Home Sweet Home',
'moons': 1}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You could also do:

Suggested change
assert response_body[0] == {
'id': 1,
'name': 'Mars',
'description': 'Too hot',
'moons': 2}
assert response_body[1] == {
'id': 2,
'name' : 'Earth',
'description' : 'Home Sweet Home',
'moons': 1}
assert response_body == [{
'id': 1,
'name': 'Mars',
'description': 'Too hot',
'moons': 2
},
{
'id': 2,
'name' : 'Earth',
'description' : 'Home Sweet Home',
'moons': 1}
]

Comment thread tests/test_routes.py


# 4.POST /books with a JSON request body returns a 201
def test_create_one_book(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.

You should also have a test that checks what happens when the request body is invalid.

Comment thread app/routes/routes.py

# DELETE RESOURCE
@planets_bp.route("/<id>", methods=["DELETE"])
def delete_planet(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.

Just note this route is untested.

Comment thread app/routes/routes.py

# UPDATE RESOURCE
@planets_bp.route("/<id>", methods=["PUT"])
def update_planet(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.

Just note this route is untested.

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