Skip to content

Solar System - D19#32

Open
paigepwilcox wants to merge 16 commits intoAda-C19:mainfrom
paigepwilcox:main
Open

Solar System - D19#32
paigepwilcox wants to merge 16 commits intoAda-C19:mainfrom
paigepwilcox:main

Conversation

@paigepwilcox
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 Paige! I've left some comments & questions, let me know here or on Slack if there's anything I can clarify 😊

Comment thread app/__init__.py
app = Flask(__name__)

if not test_config:
app.config['AQLALCHEMY_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 looks like there's a typo in the spelling of the dictionary key, so this setting might not be respected when the server runs.

Comment thread app/__init__.py
Comment on lines +14 to +21
if not test_config:
app.config['AQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("SQLALCHEMY_DATABASE_URI")
else:
app.config["TESTING"] = True
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get(
"SQLALCHEMY_TEST_DATABASE_URI")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Both side of the if/else contain app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False, we could D.R.Y. up our code by moving that line above the if/else:

app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
if not test_config:
    app.config['SQLALCHEMY_DATABASE_URI'] = os.environ.get("SQLALCHEMY_DATABASE_URI")
else:
    app.config["TESTING"] = True
    app.config["SQLALCHEMY_DATABASE_URI"] = os.environ.get("SQLALCHEMY_TEST_DATABASE_URI")

Comment thread app/routes.py
try:
model_id = int(model_id)
except:
abort(make_response({"message":f"planet {model_id} 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.

Our function will always return text that says planet, we could replace that with something like cls.__name__ if we want to read the name off the class we pass as the first parameter.

Comment thread app/routes.py
Comment on lines +40 to +42
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 great place for a list comprehension:

planets_response = [planet.to_dict() for planet in planets]

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

return make_response(jsonify(f"Planet {new_planet.name} successfully created"), 201)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Some lines across the file are a little long for style best practices, how could we split them up?

Comment thread app/models/planets.py
Comment on lines +18 to +22
# planets = [
# Planets(1, "Saturn", "Gaseous planet with rings"),
# Planets(2, "Jupiter", "Strom planet"),
# Planets(3, "Venus", "Where girls come from")
# ] 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.

We typically want to delete commented out code before opening PRs. We can rely on our commit history if we need to check out how something used to look =]

Comment thread app/routes.py
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 really appreciate the clarity of the code across the routes, really nice use of descriptive names and spacing to make it easy to read! ^_^

Comment thread tests/conftest.py
return app.test_client()

@pytest.fixture
def get_one_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.

Since we aren't returning a planet, I would consider updating the function name to reflect that we're storing one planet in the database. This applies to read_all_planets below as well, how could we rename it to reflect that the function stores 2 planets?

Comment thread tests/test_routes.py
@@ -0,0 +1,74 @@

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

It looks like this test is checking that if the database is empty, we return an empty list for the get all endpoint. How could we rename this test to include those details about the route and input?

Comment thread tests/test_routes.py
Comment on lines +33 to +37





Copy link
Copy Markdown

Choose a reason for hiding this comment

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

One of the things to look at when we are in our code clean up phase is whitespace across a file. The general guideline is one new line between functions inside of a class, 2 new lines for top level functions in a file - but what's most important is to be consistent across a codebase. A little extra whitespace is often used as a visual separation between groups of related functions, or to make it clear where imports end and implementation code begins. We lose the ability to have a visual separation have meaning if we are not consistent with how they are applied. The PEP 8 style guide has a little more info on their recommendations: https://peps.python.org/pep-0008/#blank-lines

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