How to use test_clean_db method in pytest-django

Best Python code snippet using pytest-django_python

test_integration_navbar.py

Source:test_integration_navbar.py Github

copy

Full Screen

1import pytest2from selenium import webdriver3from flask import current_app4import sqlite35from time import sleep6from static.classes.User import User, encryptPassword, decryptPassword7#globals8t_username = 'testUsername29475'9t_password = 'kjdfvi4kjvsd4'10t_firstname = 'john'11t_lastname = 'doe'12DB_NAME = 'database.db'13def test_clean_DB():14 connection = sqlite3.connect(DB_NAME)15 cur = connection.execute("DELETE FROM Users WHERE UserName = (?) ",(t_username,))16 connection.commit()17 connection.close()18class TestNavbar:19 20 # ---------------------------------21 # navbar gui tests22 # ---------------------------------23 # guest gui testing 24 def test_navbar_home_link(self, application: str, ff_browser: webdriver.Firefox):25 ff_browser.get(application)26 elem = ff_browser.find_element_by_name("home_link")27 assert elem.text == "Home"28 29 def test_navbar_login_link(self, application: str, ff_browser: webdriver.Firefox):30 ff_browser.get(application + "/logout")31 ff_browser.get(application)32 elem = ff_browser.find_element_by_name("login_link")33 assert elem.text == "Login"34 def test_navbar_register_link(self, application: str, ff_browser: webdriver.Firefox):35 ff_browser.get(application + "/logout")36 ff_browser.get(application)37 elem = ff_browser.find_element_by_name("register_link")38 assert elem.text == "Register"39 40 def test_navbar_about_link(self, application: str, ff_browser: webdriver.Firefox):41 ff_browser.get(application)42 elem = ff_browser.find_element_by_name("about_link")43 assert elem.text == "About"44 45 # ---------------------------------46 # navbar unitests47 # ---------------------------------48 def test_home_route(self, application: str, ff_browser: webdriver.Firefox):49 ff_browser.get(application)50 elem = ff_browser.find_element_by_name("home_link")51 elem.click()52 assert ff_browser.current_url == application + "/"53 def test_login_route(self, application: str, ff_browser: webdriver.Firefox):54 ff_browser.get(application + "/logout")55 ff_browser.get(application)56 elem = ff_browser.find_element_by_name("login_link")57 elem.click()58 assert ff_browser.current_url == application + "/login"59 60 def test_register_route(self, application: str, ff_browser: webdriver.Firefox):61 ff_browser.get(application + "/logout")62 ff_browser.get(application)63 elem = ff_browser.find_element_by_name("register_link")64 elem.click()65 assert ff_browser.current_url == application + "/register"66 '''67 # uncomment next sprint68 def test_about_route(self, application: str, ff_browser: webdriver.Firefox):69 ff_browser.get(application)70 elem = ff_browser.find_element_by_name("about_link")71 elem.click()72 assert ff_browser.current_url == application + "/about"73 '''74 75 def test_user_navbar(self, application: str, ff_browser: webdriver.Firefox):76 ''' check that there is user profile button '''77 test_clean_DB() # remove previous inserts in case there are any78 ff_browser.get(application + "/logout") # logout 79 connection = sqlite3.connect(DB_NAME)80 #insert normal user81 cur = connection.execute("INSERT INTO Users VALUES (?,?,?,?,?,?,?,?,?,?)",82 (t_username,t_firstname,t_lastname,encryptPassword(t_password),1,1,1,0,0,"")83 )84 connection.commit()85 connection.close()86 #connect to user87 ff_browser.get(application + "/login")88 elem = ff_browser.find_element_by_name("username")89 elem.send_keys(t_username)90 elem = ff_browser.find_element_by_name("password")91 elem.send_keys(t_password)92 elem = ff_browser.find_element_by_name("submit")93 elem.click()94 elem = ff_browser.find_element_by_name("user_link")95 assert elem.text == "My Profile"96 def test_user_navbar_route(self, application: str, ff_browser: webdriver.Firefox):97 ''' check if My Profile moves the user to the right route '''98 elem = ff_browser.find_element_by_name("user_link")99 elem.click()100 assert ff_browser.current_url == application + "/user/" + t_username101 def test_admin_navbar(self, application: str, ff_browser: webdriver.Firefox):102 ''' check there is an admin navbar button '''103 test_clean_DB() # remove previous inserts in case there are any104 ff_browser.get(application + "/logout") # logout 105 connection = sqlite3.connect(DB_NAME)106 #insert admin user107 cur = connection.execute("INSERT INTO Users VALUES (?,?,?,?,?,?,?,?,?,?)",108 (t_username,t_firstname,t_lastname,encryptPassword(t_password),1,1,1,1,0,"")109 )110 connection.commit()111 connection.close()112 #connect to admin user113 ff_browser.get(application + "/login")114 elem = ff_browser.find_element_by_name("username")115 elem.send_keys(t_username)116 elem = ff_browser.find_element_by_name("password")117 elem.send_keys(t_password)118 elem = ff_browser.find_element_by_name("submit")119 elem.click()120 elem = ff_browser.find_element_by_name("control_panel_link")121 assert elem.text == "Control Panel"122 def test_admin_navbar(self, application: str, ff_browser: webdriver.Firefox):123 ''' check if Control Panel moves the admin to the right route '''124 test_clean_DB() # remove previous inserts in case there are any125 ff_browser.get(application + "/logout") # logout 126 connection = sqlite3.connect(DB_NAME)127 #insert admin user128 cur = connection.execute("INSERT INTO Users VALUES (?,?,?,?,?,?,?,?,?,?)",129 (t_username,t_firstname,t_lastname,encryptPassword(t_password),1,1,1,1,0,"")130 )131 connection.commit()132 connection.close()133 #connect to admin user134 ff_browser.get(application + "/login")135 elem = ff_browser.find_element_by_name("username")136 elem.send_keys(t_username)137 elem = ff_browser.find_element_by_name("password")138 elem.send_keys(t_password)139 elem = ff_browser.find_element_by_name("submit")140 elem.click()141 elem = ff_browser.find_element_by_name("control_panel_link")142 elem.click()143 assert ff_browser.current_url == application + "/controlpanel"144 def test_house_cleaning(self):...

Full Screen

Full Screen

tests.py

Source:tests.py Github

copy

Full Screen

...31 for i in range(20):32 B = small_factory.getRandomMatrix(dim, bit_count)33 t = small_factory.getZeros(dim, 1)34 dao.write(B, t, f"Small matrix sample {i}")35 def test_clean_db(self):36 dao = MatrixStorage("resources/matrix_storage.csv")37 dao.clean()38 def test_simulated_stat(self):39 B, t = self.get_matricies(18)40 sampler = SimulatedAnnealingSampler()41 interactor = TestInteractor(B, t, SympyMatrixFactory(), sampler)42 interactor.compute_probabilities((2, 10), num_reads=1000)43 interactor.show_plot(show=False, image_name="resources/energy_levels_simulated.png")44 def test_quantum_stat(self):45 B, t = self.get_matricies(18)46 sampler = EmbeddingComposite(DWaveSampler(token=self.token, 47 solver={'topology__type': 'chimera'}))48 interactor = TestInteractor(B, t, SympyMatrixFactory(), sampler)49 interactor.compute_probabilities((2, 8), num_reads=1000, k=2)...

Full Screen

Full Screen

test_basic.py

Source:test_basic.py Github

copy

Full Screen

...16 username=username,17 password=password18 ), follow_redirects=True)19# Start out tests20def test_clean_db(client):21 db.drop_all()22 db.create_all()23def test_index(client):24 """Start with a blank database."""25 rv = client.get('/')26 assert rv.status_code == 20027def test_sign_up(client):28 rv = client.get('/sign_up', query_string=dict(29 username='test',30 password='pass'31 ), follow_redirects=True)32 print rv.data33 assert rv.status_code == 20034 rv = client.get('/sign_up', data=dict(...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run pytest-django automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful