Best Python code snippet using autotest_python
test_models.py
Source:test_models.py
...8from users.models import CustomUser9pytestmark = [pytest.mark.django_db]10class TestManufactoryModel:11 @pytest.fixture12 def init_db(self, db):13 Manufactor.objects.create(name='ASUS creator', summary='ASUS summary to be continue')14 def test_name_label(self, db, init_db):15 manufactor = Manufactor.objects.get(manufactor_id=1)16 field_label = manufactor._meta.get_field('name').verbose_name17 assert(field_label == _('Ðазвание'))18 def test_name_max_length(self, db, init_db):19 manufactor = Manufactor.objects.get(manufactor_id=1)20 max_length = manufactor._meta.get_field('name').max_length21 assert(max_length == 200)22 def test_summary_label(self, db, init_db):23 manufactor = Manufactor.objects.get(manufactor_id=1)24 field_label = manufactor._meta.get_field('summary').verbose_name25 assert(field_label == _('ÐпиÑание'))26 def test_summary_max_length(self, db, init_db):27 manufactor = Manufactor.objects.get(manufactor_id=1)28 max_length = manufactor._meta.get_field('summary').max_length29 assert(max_length == 500)30 def test_get_absolute_url(self, db, init_db):31 manufactor = Manufactor.objects.get(manufactor_id=1)32 assert(manufactor.get_absolute_url() == '/manufactor/manufactor/1')33class TestCategoryModel:34 @pytest.fixture35 def init_db(self, db):36 Category.objects.create(name='VR Ð´Ð»Ñ Ð´Ð¾Ð¼Ð¾Ñ
озÑек', summary='Ðогда-нибÑÐ´Ñ Ð¿ÑидÑмаÑÑ... навеÑное...')37 def test_name_label(self, db, init_db):38 category = Category.objects.get(category_id=1)39 field_label = category._meta.get_field('name').verbose_name40 assert(field_label == _('Ðазвание'))41 def test_name_max_length(self, db, init_db):42 category = Category.objects.get(category_id=1)43 max_length = category._meta.get_field('name').max_length44 assert(max_length == 200)45 def test_summary_label(self, db, init_db):46 category = Category.objects.get(category_id=1)47 field_label = category._meta.get_field('summary').verbose_name48 assert(field_label == _('ÐпиÑание'))49 def test_summary_max_length(self, db, init_db):50 category = Category.objects.get(category_id=1)51 max_length = category._meta.get_field('summary').max_length52 assert(max_length == 500)53 def test_get_absolute_url(self, db, init_db):54 category = Category.objects.get(category_id=1)55 assert(category.get_absolute_url() == '/category/category/1')56class TestItemModel:57 @pytest.fixture58 def init_db(self, db):59 item_uuid = uuid.uuid4()60 manufactor = Manufactor.objects.create(name='ASUS creator', summary='ASUS summary to be continue')61 category = Category.objects.create(name='VR Ð´Ð»Ñ Ð´Ð¾Ð¼Ð¾Ñ
озÑек', summary='Ðогда-нибÑÐ´Ñ Ð¿ÑидÑмаÑÑ... навеÑное...')62 Item.objects.create(item_id=item_uuid, manufactor=manufactor, category=category,63 name='Ðогда ÑкÑÑно', summary='Ðожно вклÑÑиÑÑ', price=999.90, quantity=14,64 availability=False)65 return item_uuid66 def test_name_label(self, db, init_db):67 item = Item.objects.get(item_id=init_db)68 field_label = item._meta.get_field('name').verbose_name69 assert(field_label == _('Ðаименование'))70 def test_name_max_length(self, db, init_db):71 item = Item.objects.get(item_id=init_db)72 max_length = item._meta.get_field('name').max_length73 assert(max_length == 200)74 def test_summary_label(self, db, init_db):75 item = Item.objects.get(item_id=init_db)76 field_label = item._meta.get_field('summary').verbose_name77 assert(field_label == _('ÐпиÑание'))78 def test_summary_max_length(self, db, init_db):79 item = Item.objects.get(item_id=init_db)80 max_length = item._meta.get_field('summary').max_length81 assert(max_length == 500)82 def test_price_decimal_places(self, db, init_db):83 item = Item.objects.get(item_id=init_db)84 decimal_places = item._meta.get_field('price').decimal_places85 assert(decimal_places == 2)86 def test_get_absolute_url(self, db, init_db):87 item = Item.objects.get(item_id=init_db)88 assert(item.get_absolute_url() == '/item/item/counter/' + str(init_db))89class TestItemIssueModel:90 @pytest.fixture91 def init_db(self, db):92 item_uuid = uuid.uuid4()93 manufactor = Manufactor.objects.create(name='ASUS creator', summary='ASUS summary to be continue')94 category = Category.objects.create(name='VR Ð´Ð»Ñ Ð´Ð¾Ð¼Ð¾Ñ
озÑек', summary='Ðогда-нибÑÐ´Ñ Ð¿ÑидÑмаÑÑ... навеÑное...')95 item = Item.objects.create(item_id=item_uuid, manufactor=manufactor, category=category,96 name='Ðогда ÑкÑÑно', summary='Ðожно вклÑÑиÑÑ', price=999.90, quantity=14,97 availability=False)98 user = CustomUser.objects.create_user(email='test@test.ru', password='test-pwd')99 ItemIssue.objects.create(item=item, created_by=user)100 def test_item_issue_label(self, db, init_db):101 item_issue = ItemIssue.objects.get(item_issue_id=1)102 field_label = item_issue._meta.get_field('item').verbose_name...
conftest.py
Source:conftest.py
1import logging2import os3import psycopg24import pytest5from pytest_docker import docker_ip, docker_services # pylint:disable=W06116from sqlalchemy import create_engine7from sqlalchemy.orm import sessionmaker8import server.utils.init_db as init_db9_LOGGER = logging.getLogger(__name__)10#@pytest.fixture(scope='session')11#def docker_compose_file(pytestconfig):12# """13# Path to docker-compose configuration files used for testing14# """15# return os.path.join(16# str(pytestconfig.rootdir),17# '..'18# 'docker-compose.yml'19# )20def is_responsive2(database, user, password, host, port, **kargs):21 """Check if there is a db"""22 try:23 conn = psycopg2.connect(24 dbname=database, user=user, password=password, host=host, port=port)25 conn.close()26 except psycopg2.OperationalError as _ex:27 logging.exception("Connection to db failed")28 return False29 return True30def is_responsive(**kargs):31 try:32 conn = init_db.admin_engine.connect()33 conn.close()34 except:35 logging.exception("Connection to db failed")36 return False37 return True38@pytest.fixture(scope="session")39def postgres_service(docker_ip, docker_services):40 """41 starts postgress service with sample data42 """43 config = init_db.TEST_CONFIG['postgres']44 engine = init_db.test_engine45 docker_services.wait_until_responsive(46 check=lambda: is_responsive(**config),47 timeout=30.0,48 pause=1.0,49 )50 init_db.setup_db(config)51 init_db.create_tables(engine)52 init_db.sample_data(engine)53 yield config54 init_db.drop_tables()...
init_db.py
Source:init_db.py
1from testlogin import init_db2init_db ()3from highestgrossing import init_db4init_db ()5from animated import init_db6init_db ()7from movies2000 import init_db8init_db ()9from movies2001 import init_db10init_db ()11from movies2002 import init_db12init_db ()13from movies2003 import init_db14init_db ()15from movies2004 import init_db16init_db ()17from movies2005 import init_db18init_db ()19from movies2006 import init_db20init_db ()21from movies2007 import init_db22init_db ()23from movies2008 import init_db24init_db ()25from movies2009 import init_db26init_db ()27from movies2010 import init_db28init_db ()29from movies2011 import init_db30init_db ()31from movies2012 import init_db32init_db ()33from movies2013 import init_db34init_db ()35from movies2014 import init_db36init_db ()37from movies2015 import init_db38init_db ()39from movies2016 import init_db40init_db ()41from movies2017 import init_db42init_db ()43from movies2018 import init_db...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!