Skip to content

Kunzite - Abby & Aisha#24

Open
aimo22 wants to merge 17 commits intoAda-C19:mainfrom
abbymachines:main
Open

Kunzite - Abby & Aisha#24
aimo22 wants to merge 17 commits intoAda-C19:mainfrom
abbymachines:main

Conversation

@aimo22
Copy link
Copy Markdown

@aimo22 aimo22 commented Apr 25, 2023

No description provided.

Copy link
Copy Markdown

@marciaga marciaga left a comment

Choose a reason for hiding this comment

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

Good work with Waves 01-02! Please see specific comments below.

Comment thread app/routes.py Outdated
"id": planet.id,
"name": planet.name,
"description": planet.description,
"chemical composition": planet.composition
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 here the key being used is "chemical composition" but in the Planet class, the attribute is called composition. It's very important to keep these attributes/keys consistent because any clients who consume this data as returned from your API will be relying on that uniformity. I'd recommend sticking with composition or if you prefer a compound word, use the Python convention of an underscore, i.e. chemical_composition.

Comment thread app/routes.py Outdated

abort(make_response({"message": f"planet {planet_id} not found"}, 404))

def make_dict(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.

Following what we did in Flasky, it's advisable to make this function an instance method in your Planet class, so you can call it on instances of the class!

Comment thread app/routes.py Outdated

def make_dict(planet):
return dict(
id = 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.

within dict(), the convention is to not have spaces around the assignment operators. It's perhaps more important to be consistent with the approach, so if you're using spaces around assignment operators, do that everywhere you use it. But the PEP8 preference here is to omit the spaces, so

dict(
  id=planet.id,
  name=planet.name,
  description=planet.description,
  composition=planet.composition
)

Copy link
Copy Markdown

@marciaga marciaga 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! Only thing worth mentioning is to avoid committing commented out code. Nice job with the tests as well!

Comment thread app/__init__.py
def create_app(test_config=None):
app = Flask(__name__)

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

It's a good practice to remove extraneous commented out code.

Comment thread app/__init__.py
"SQLALCHEMY_DATABASE_URI")
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.

Since this line of code is in both the else and the if blocks, it could be moved outside this control flow structure so we don't repeat it.

Comment thread app/models/planet.py
@@ -0,0 +1,23 @@
from app import db

class Planet(db.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.

Nice job with this!

Comment thread app/routes/routes.py
bp = Blueprint("planets", __name__, url_prefix="/planets")
# @bp.route("",methods=["GET"])

# # helper function
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Again, get in the habit of deleting commented out code.

Comment thread tests/conftest.py
composition="second")

db.session.add_all([first_planet, second_planet])
db.session.commit() 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 will work to get these planets in the db but if you want to use the data in your tests, you should return something from this function (that will be passed to the test function). You could then use some of that test data instead of hard-coding. For example if you had a one_saved_planet fixture, you could use its id in the test_get_first_planet instead of hard-coding the get("planets/1").

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