Guest User

Untitled

a guest
Aug 13th, 2023
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. import pytest, bcrypt, os  
  2.  
  3. from wsgi import app
  4.  
  5. @pytest.fixture
  6. def client():
  7.     return app.test_client()
  8.  
  9. @pytest.fixture
  10. def runner():
  11.     return app.test_cli_runner()
  12.  
  13.  
  14. @pytest.fixture
  15. def username_form():
  16.     '''This username_form_form is for pytest'''
  17.    
  18.     username = 'fkpr[kfkuh'
  19.     return username
  20.  
  21. @pytest.fixture
  22. def plaintext_password_form():  
  23.    '''This plaintext_password_form_form is for pytest'''  
  24.    
  25.    plaintext_password = 'pojkp[kjpj[pj'
  26.    return plaintext_password
  27.  
  28. @pytest.fixture
  29. def hashed_password_form():    
  30.     '''This hashed_password_form is for pytest'''
  31.    
  32.     plaintext_password = 'pojkp[kjpj[pj'
  33.     # converting password to array of bytes
  34.     bytes = plaintext_password.encode('utf-8')
  35.     # generating the salt
  36.     salt = bcrypt.gensalt()
  37.     # Hashing the password
  38.     hashed_password_form = bcrypt.hashpw(bytes, salt)
  39.     return hashed_password_form
  40.  
  41.  
  42.  
  43. @pytest.fixture
  44. def email_form():
  45.     '''This email_form is for pytest'''
  46.     '''For both UserTest and Payments'''
  47.     email_form = os.environ['TESTING_EMAIL_USERNAME']
  48.     return email_form
  49.  
  50.  
  51. @pytest.fixture
  52. def item_name_form():
  53.     '''This item_name_form is for pytest'''
  54.     item_name_form = 'donation'  
  55.     return item_name_form
  56.  
  57.  
  58.  
  59. @pytest.fixture
  60. def price_of_donation_form():    
  61.     '''This price_of_donation_form is for pytest'''
  62.     # equal to 66 cents
  63.     price_of_donation_form = 66
  64.     return price_of_donation_form
  65.  
  66.  
  67. from app.tests.models import UserTest
  68. from app import db
  69.  
  70. @pytest.fixture
  71. def yield_username_db():  
  72.    
  73.     '''
  74.    Create the db column then yield the selected/queried usertest and finally delete the db.
  75.    yield does not stop the code when yielded.
  76.    '''
  77.    
  78.     # = with app.app_context() except won't work for pytest
  79.     with app.test_request_context():
  80.  
  81.         bind_key="testing_app_db"
  82.        
  83.         def _subfunction(username_form, hashed_password_form, email_form):
  84.                        
  85.             db.create_all(bind_key)
  86.             usertest_db = UserTest(username=username_form, hashed_password=hashed_password_form, email=email_form)
  87.             db.session.add(usertest_db)
  88.             db.session.commit()
  89.             # returns the username
  90.             username = ''fkpr[kfkuh''
  91.             return username
  92.  
  93.         # yield unlike return doesn't stop when called.
  94.         yield _subfunction
  95.         db.drop_all(bind_key)
  96.  
Advertisement
Add Comment
Please, Sign In to add comment