Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pytest, bcrypt, os
- from wsgi import app
- @pytest.fixture
- def client():
- return app.test_client()
- @pytest.fixture
- def runner():
- return app.test_cli_runner()
- @pytest.fixture
- def username_form():
- '''This username_form_form is for pytest'''
- username = 'fkpr[kfkuh'
- return username
- @pytest.fixture
- def plaintext_password_form():
- '''This plaintext_password_form_form is for pytest'''
- plaintext_password = 'pojkp[kjpj[pj'
- return plaintext_password
- @pytest.fixture
- def hashed_password_form():
- '''This hashed_password_form is for pytest'''
- plaintext_password = 'pojkp[kjpj[pj'
- # converting password to array of bytes
- bytes = plaintext_password.encode('utf-8')
- # generating the salt
- salt = bcrypt.gensalt()
- # Hashing the password
- hashed_password_form = bcrypt.hashpw(bytes, salt)
- return hashed_password_form
- @pytest.fixture
- def email_form():
- '''This email_form is for pytest'''
- '''For both UserTest and Payments'''
- email_form = os.environ['TESTING_EMAIL_USERNAME']
- return email_form
- @pytest.fixture
- def item_name_form():
- '''This item_name_form is for pytest'''
- item_name_form = 'donation'
- return item_name_form
- @pytest.fixture
- def price_of_donation_form():
- '''This price_of_donation_form is for pytest'''
- # equal to 66 cents
- price_of_donation_form = 66
- return price_of_donation_form
- from app.tests.models import UserTest
- from app import db
- @pytest.fixture
- def yield_username_db():
- '''
- Create the db column then yield the selected/queried usertest and finally delete the db.
- yield does not stop the code when yielded.
- '''
- # = with app.app_context() except won't work for pytest
- with app.test_request_context():
- bind_key="testing_app_db"
- def _subfunction(username_form, hashed_password_form, email_form):
- db.create_all(bind_key)
- usertest_db = UserTest(username=username_form, hashed_password=hashed_password_form, email=email_form)
- db.session.add(usertest_db)
- db.session.commit()
- # returns the username
- username = ''fkpr[kfkuh''
- return username
- # yield unlike return doesn't stop when called.
- yield _subfunction
- db.drop_all(bind_key)
Advertisement
Add Comment
Please, Sign In to add comment