Giter Site home page Giter Site logo

python-p4-flask-sqlalchemy-lab's Introduction

Flask-SQLAlchemy Lab

Learning Goals

  • Build and run a Flask application on your computer.
  • Extend a Flask application to meet the unique requirements of different projects.

Key Vocab

  • Web Framework: software that is designed to support the development of web applications. Web frameworks provide built-in tools for generating web servers, turning Python objects into HTML, and more.
  • Extension: a package or module that adds functionality to a Flask application that it does not have by default.
  • Request: an attempt by one machine to contact another over the internet.
  • Client: an application or machine that accesses services being provided by a server through the internet.
  • Web Server: a combination of software and hardware that uses Hypertext Transfer Protocol (HTTP) and other protocols to respond to requests made over the internet.
  • Web Server Gateway Interface (WSGI): an interface between web servers and applications.
  • Template Engine: software that takes in strings with tokenized values, replacing the tokens with their values as output in a web browser.

Instructions

This is a test-driven lab. Run pipenv install to create your virtual environment and pipenv shell to enter the virtual environment. Then run pytest -x to run your tests. Use these instructions and pytest's error messages to complete your work in the server/ folder.

Instructions begin here:

  • Design a Flask application that displays information from a database created using Flask-SQLAlchemy and Flask-Migrate.
  • flask db init has already been run. You will need to direct your Flask app to a database at app.db, create models, run a migration with flask db revision --autogenerate -m'<your message>' and create the database file with flask db upgrade.
  • Your database should represent a zoo. There should be three tables: animals, zookeepers, and enclosures.
  • The Animal model should contain a String name, a String species, a zookeeper_id, and an enclosure_id. It should be related to zookeepers and enclosures using db.relationship().
    • Reminder: You can test any model by itself with pytest testing/models/{modelname}_test.py.
  • The Zookeeper model should contain a String name, a String birthday, and a list of animals that they take care of using db.relationship().
  • The Enclosure model should contain a String environment (grass, sand, or water), a Boolean open_to_visitors, and a list of animals using db.relationship().
  • Your application should contain three views: animal_by_id, zookeeper_by_id, and enclosure_by_id. Their routes should be animal/<int:id>, zookeeper/<int:id>, and enclosure/<int:id>, respectively.
  • Each view should display all attributes as line items (ul). If there is a one-to-many relationship, each of the many should have its own line item.
  • A seed script, server/seed.py, has been provided to generate test data once your models have been built and migrated to a database. Make sure to run this so that there are resources for the test suite to visit.

Once all of your tests are passing, commit and push your work using git to submit.

Examples

Animal View

animal ID 1, name Logan, species Snake, zookeeper Dylan Taylor, enclosure trees

Zookeeper View

zookeeper name Stephanie Contreras, birthday 1996-9-20, 6 animals

Enclosure View

enclosure with pond environment, not open to visitors, 8 animals


Resources

python-p4-flask-sqlalchemy-lab's People

Contributors

jlboba avatar linda-seiter avatar lizbur10 avatar professor-ben avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

python-p4-flask-sqlalchemy-lab's Issues

Pytest Issues

Canvas Link

https://learning.flatironschool.com/courses/6259/assignments/233459?module_item_id=547383

Concern

I encountered a few issues with running Pytest for this lab:

  • By default, only the shorthand output (with .’s and F’s for each passed/failed test within a test file) for the tests shows in the terminal, not the descriptions of what each test is, which is what usually renders (and is really helpful information for these test-driven labs).

  • I ended up getting the descriptions to show up by running pytest -v, but usually, that format is the default, and I don’t need to include the flag.

  • This shorthand output was particularly confusing in this case because Pytest was also getting stuck/hung on the first ‘route_has_one_to_many_attr’ test that hadn’t passed and wouldn’t exit to the test summary until I hit Ctrl+C to interrupt it.

  • I eventually got all tests to pass when running on my machine, but the tests failed when uploaded to CodeGrade.

Additional Context

No response

Suggested Changes

No response

db.init_app(app) still in solution seed file

Canvas Link

https://learning.flatironschool.com/courses/6259/assignments/233459?module_item_id=547383

Concern

I see the db.init_app(app) was removed from the seed file, but it is still in the solution code for that file. Just letting you know!

I also saw Matt's issue about constraints and wanted to mention that I didn't see a note about not enforcing the constraints for the environment or that constraints would be covered later.

Additional Context

No response

Suggested Changes

No response

Seed data not reporting everything

Canvas Link

https://learning.flatironschool.com/courses/6463/assignments/250500?module_item_id=591862

Concern

All of my pytest's passed and when I went to open the port in the browser, I noticed some information was missing.

On the animal route, the Zookeeper & Enclosure are showing as none on the front end. On the backend, the Animal table is showing null for the ID's. This information is missing from the seed file.

On the enclosure route, the animal is showing an empty array (from the way it's coded in the seed file).

On the zookeeper route, it's showing the same empty array for the animal.

As a student, I was excited that the tests passing and confused that I may have done something wrong since the information wasn't showing correctly (like the examples in the lab).

Please let me know if there is anything else I can contribute!

Additional Context

No response

Suggested Changes

The seed file needs to be updated to include the correct information.

Use check constraints?

Canvas Link

https://learning.flatironschool.com/courses/6182/assignments/208460?module_item_id=480475

Concern

Was our intention to have students use a check constraint on our environment column for enclosures? We specify that the environment type should belong to one of three different types. If we want them to be familiar with constraints at this point, we might want to give a brief example of how to use them with flask-sqlalchemy (basically just prepend CheckConstraint withdb.). The docs don't explain this in any detail, and I managed to figure it out through trial and error.

If we are going to talk about this later on, we may not want to tell students that the environment can only be one of three types, as this could be confusing or misleading to students.

Additional Context

No response

Suggested Changes

No response

Duplicate ForeignKeys

Canvas Link

https://learning.flatironschool.com/courses/6463/assignments/250500?module_item_id=591862

Concern

There are duplicate ForeignKey definitions in the models.py solution code:
zookeeper_id = db.Column(db.Integer, db.ForeignKey('zookeepers.id'))
enclosure_id = db.Column(db.Integer, db.ForeignKey('enclosures.id'))
zookeeper_id = db.Column(db.Integer, db.ForeignKey('zookeepers.id'))
enclosure_id = db.Column(db.Integer, db.ForeignKey('enclosures.id'))
(lines 35-38)

Additional Context

No response

Suggested Changes

It seems that the code is correct but has been duplicated by mistake.

Passes Pytest but not CodeGrade

Canvas Link

https://learning.flatironschool.com/courses/6193/assignments/234443?module_item_id=549347

Concern

After passing all of the Pytests in this lab, my code still fails the CodeGrade assessment. Attached code in additional context for review. I am not sure if it is an issue with CodeGrade or if I am missing something. Thank you for your time!

Additional Context

Here is my code, which passes the Pytests but fails CodeGrade:

https://github.com/jessicavaughn619/python-p4-flask-sqlalchemy-lab

Suggested Changes

No response

The instructions are not only wrong but out of order to run the test

Canvas Link

https://learning.flatironschool.com/courses/6275/assignments/237710?module_item_id=558386

Concern

The instructions for the dliverables are not only confusing but in the wrong order.

Instructions begin here:

Design a Flask application that displays information from a database created using Flask-SQLAlchemy and Flask-Migrate.

flask db init has already been run. You will need to direct your Flask app to a database at app.db, create models, run a migration with flask db revision --autogenerate -m'' and create the database file with flask db upgrade.

Your database should represent a zoo. There should be three tables: animals, zookeepers, and enclosures.

The Animal model should contain a name, a species, a zookeeper, and an enclosure.

The Zookeeper model should contain a name, a birthday, and a list of animals that they take care of.

The Enclosure model should contain an environment (grass, sand, or water), an open_to_visitors boolean, and a list of animals.

Your application should contain three views: animal_by_id, zookeeper_by_id, and enclosure_by_id. Their routes should be animal/int:id, zookeeper/int:id, and enclosure/int:id, respectively.

Each view should display all attributes as line items (ul). If there is a one-to-many relationship, each of the many should have its own line item.

A seed script, server/seed.py, has been provided to generate test data once your models have been built and migrated to a database. Make sure to run this so that there are resources for the test suite to visit.

Additional Context

the task should be reordered.

Suggested Changes

It should be this for less confusion.

You actually cant run the test until your models are done

Your database should represent a zoo. There should be three tables: animals, zookeepers, and enclosures.

The Animal model should contain a name, a species, a zookeeper, and an enclosure.

The Zookeeper model should contain a name, a birthday, and a list of animals that they take care of.

The Enclosure model should contain an environment (grass, sand, or water), an open_to_visitors boolean, and a list of animals.

this step is already done

remove the following step -flask db init has already been run. You will need to direct your Flask app to a database at app.db, create models
because - the direction is already done this shouldnt even be in here

Run a migration with flask db revision --autogenerate -m'' and create the database file with flask db upgrade head

do this step next so you can actually have information for the test to work

A seed script, server/seed.py, has been provided to generate test data once your models have been built and migrated to a database. Make sure to run this so that there are resources for the test suite to visit.

Now running pytest -x will allow the test to generate instead of errors and you can finish this "test-driven-lab"*

Your application should contain three views: animal_by_id, zookeeper_by_id, and enclosure_by_id. Their routes should be animal/int:id, zookeeper/int:id, and enclosure/int:id, respectively.

Each view should display all attributes as line items (ul). If there is a one-to-many relationship, each of the many should have its own line item.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.