Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

python code you need to setup the project and add the remote interpreter for the project using the Dockerfile or docker-compose flask service. You are

python code

you need to setup the project and add the remote interpreter for the project using the Dockerfile or docker-compose flask service. You are required to add a new field to the database model called address and populate it with an address using the faker library. The address field should appear when a user is selected from the /users route. You will need to set the seed to 4321 in the conftest.py file order to generate the same data set that I use for my tests. Your first record should be "Jason Brown" and the address should be, "9335 Gloria Street Suite 675 Mathisport, PR 63759".

My teacher test is looking for this address.

Your users/1 page should look like this Screenshot.

You need to run the tests/test_add_user.py (below) file with pytest, so that it creates the users.

You will need to make the following changes to make this work:

Modify the application/database/ini.py to add an address field.

Run the command to create a migration: flask db migrate -m "added address field"

Run the command to apply the migration: flask db upgrade

Modify the tests/conftest.py Fixture to populate the address field with faker address.

Set the seed in tests/conftest.py Fixture to 4321

Modify the application/bp/homepage/templates/user.html file to add the jinja code to display the address field.

Install Commands

pip(3) install -r requirements.txt

flask db upgrade

flask --debug run or flask run (no debugging)

pytest

Fix Mac Permission Error after docker compose up --build command - Run these on the terminal

chmod +x ./development.sh

chmod +x ./production.sh

import pytest
from faker import Faker
from application import init_app as create_app
from application.database import db, User
@pytest.fixture(scope="function")
def create_300_users(app):
faker = Faker('en')
# Faker.seed()
user_list = []
number_of_users = 300
with app.app_context():
for i in range(number_of_users):
user = User()
user.name = faker.name()
user.password = faker.password()
user.email = faker.email()
user.phone = faker.phone_number()
user.address = faker.address()
user_list.append(user)
db.session.add_all(user_list)
db.session.commit()
@pytest.fixture(scope="function")
def app():
app = create_app()
app.config.update({
"TESTING": True,
})
# other setup can go here
with app.app_context():
db.session.remove()
db.drop_all()
db.create_all()
yield app
db.session.remove()
# Uncomment To Reset Database After Test
# db.drop_all()
# clean up / reset resources here
@pytest.fixture()
def client(app):
return app.test_client()
@pytest.fixture()
def runner(app):
return app.test_cli_runner()
@pytest.fixture(scope="function")
def app_clean_db():
app = create_app()
app.config.update({
"TESTING": True,
})
# other setup can go here
with app.app_context():
db.session.remove()
db.drop_all()
yield app
db.session.remove()

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Power Bi And Azure Integrating Cloud Analytics For Scalable Solutions

Authors: Kiet Huynh

1st Edition

B0CMHKB85L, 979-8868959943

More Books

Students also viewed these Databases questions

Question

How do parent-infant attachment bonds form?

Answered: 1 week ago

Question

What is topology? Explain with examples

Answered: 1 week ago