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

wave 1 and 2 completed #32

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

wave 1 and 2 completed #32

wants to merge 19 commits into from

Conversation

n2020h
Copy link

@n2020h n2020h commented Oct 26, 2022

Tigers - Neema and Maria

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.

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

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"]
)

Choose a reason for hiding this comment

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

Good helper methods

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

Choose a reason for hiding this comment

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

Great helper function



@planets_bp.route("", methods=["POST"])
def handle_planets():

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

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 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}

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}
]



# 4.POST /books with a JSON request body returns a 201
def test_create_one_book(client):

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.


# DELETE RESOURCE
@planets_bp.route("/<id>", methods=["DELETE"])
def delete_planet(id):

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.


# UPDATE RESOURCE
@planets_bp.route("/<id>", methods=["PUT"])
def update_planet(id):

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