Best Python code snippet using mailosaur-python_python
base_test.py
Source:base_test.py
1from crud.base import CRUDBase2from time import sleep3class TestGetData:4 def test_get_models(self, db_with_add, test_model):5 obj_data = test_model(id=1, name="Test", test_int=112)6 db_with_add.add(obj_data)7 db_with_add.flush()8 retrieved_data = CRUDBase(test_model).get_by_id(db_with_add, 1)9 assert retrieved_data == obj_data10 def test_get_using_filters(self, db_with_add, test_model):11 obj_data = test_model(id=1, name="Test", test_int=112)12 db_with_add.add(obj_data)13 db_with_add.flush()14 filters = {'name': 'Test', 'test_int': 112}15 retrieved_data = CRUDBase(test_model).get(db_with_add, filters)16 assert retrieved_data == obj_data17 def test_get_multi(self, db_with_add, test_model):18 obj_data1 = test_model(id=1, name='Test1', test_int=112)19 obj_data2 = test_model(id=2, name='Test2', test_int=113)20 db_with_add.add(obj_data1)21 db_with_add.add(obj_data2)22 db_with_add.flush()23 filters1 = {'id': 1, 'name': 'Test1'}24 retrieved_data = CRUDBase(test_model).get(db_with_add, filters1)25 assert retrieved_data == obj_data126 filters2 = {'id': 2, 'name': 'Test2'}27 retrieved_data = CRUDBase(test_model).get(db_with_add, filters2)28 assert retrieved_data == obj_data229class TestCreateData:30 def test_create(self, db_with_add, test_crud, test_schema):31 obj_in = test_schema(name="test", test_int=999)32 obj_created = test_crud.create(db_with_add, obj_in)33 assert obj_created.name == obj_in.name34 assert obj_created.test_int == obj_in.test_int35 obj_retrieved = test_crud.get(db_with_add, filters={'name': 'test', 'test_int': 999})36 assert obj_retrieved == obj_created37 def test_create_multi(self, db_with_add, test_crud, test_schema):38 obj1 = {'name': 'test1', 'test_int': 999}39 obj2 = {'name': 'test1', 'test_int': 888}40 objs_in = [test_schema(**obj1), test_schema(**obj2)]41 test_crud.create_multi(db_with_add, objs_in)42 obj_retrieved = test_crud.get(db_with_add, obj1)43 assert obj_retrieved.name == obj1['name']44 assert obj_retrieved.test_int == obj1['test_int']45 obj_retrieved = test_crud.get(db_with_add, obj2)46 assert obj_retrieved.name == obj2['name']47 assert obj_retrieved.test_int == obj2['test_int']48class TestUpdateData:49 def test_update_with_dict(self, db_with_add, test_crud, test_schema):50 obj_data = {'name': 'update1', 'test_int': 12}51 updated_obj_data = {'test_int': 21}52 obj_in = test_schema(**obj_data)53 obj_created = test_crud.create(db_with_add, obj_in)54 updated_obj = test_crud.update(db_with_add, obj_created, updated_obj_data)55 assert updated_obj.id == obj_created.id56 assert updated_obj.name == obj_created.name57 assert updated_obj.test_int == updated_obj_data['test_int']58 assert updated_obj.created_at == obj_created.created_at59 def test_update_and_check_if_updated_at_is_changed(60 self, db_with_add, test_crud, test_schema):61 obj_data = {'name': 'update1', 'test_int': 112}62 updated_obj_data = {'test_int': 21}63 obj_in = test_schema(**obj_data)64 obj_created = test_crud.create(db_with_add, obj_in)65 updated_time = obj_created.updated_at66 sleep(1)67 updated_obj = test_crud.update(db_with_add, obj_created, updated_obj_data)68 assert updated_obj.created_at == obj_created.created_at69 assert updated_obj.updated_at != updated_time70 def test_update_with_schema(self, db_with_add, test_crud, test_schema):71 obj_data = {'name': 'update1', 'test_int': 12}72 updated_obj_data = {'name': 'updated1', 'test_int': 21}73 obj_in = test_schema(**obj_data)74 obj_created = test_crud.create(db_with_add, obj_in)75 _id = obj_created.id76 updated_obj_schema = test_schema(**updated_obj_data)77 updated_obj = test_crud.update(db_with_add, obj_created, updated_obj_schema)78 assert updated_obj.id == _id79 assert updated_obj.test_int == updated_obj_schema.test_int80 def test_update_multi(self, db_with_add, test_crud, test_schema):81 obj_data1 = {'name': 'multi1', 'test_int': 1}82 obj_data2 = {'name': 'multi2', 'test_int': 2}83 updated_obj_data1 = {'test_int': 12}84 updated_obj_data2 = {'test_int': 23}85 db_obj1 = test_crud.create(db_with_add, test_schema(**obj_data1))86 db_obj2 = test_crud.create(db_with_add, test_schema(**obj_data2))87 id1 = db_obj1.id88 id2 = db_obj2.id89 obj1 = {'db_obj': db_obj1, 'obj_in': updated_obj_data1}90 obj2 = {'db_obj': db_obj2, 'obj_in': updated_obj_data2}91 objs_in = [obj1, obj2]92 test_crud.update_multi(db_with_add, objs_in)93 retrieved_obj1 = test_crud.get(db_with_add, {'name': 'multi1'})94 assert retrieved_obj1.id == id195 assert retrieved_obj1.name == obj_data1['name']96 assert retrieved_obj1.test_int == updated_obj_data1['test_int']97 retrieved_obj2 = test_crud.get(db_with_add, {'name': 'multi2'})98 assert retrieved_obj2.id == id299 assert retrieved_obj2.name == obj_data2['name']100 assert retrieved_obj2.test_int == updated_obj_data2['test_int']101 def test_update_multi_with_schema(self, db_with_add, test_crud, test_schema):102 obj_data1 = {'name': 'multi1', 'test_int': 1}103 obj_data2 = {'name': 'multi2', 'test_int': 2}104 db_obj1 = test_crud.create(db_with_add, test_schema(**obj_data1))105 db_obj2 = test_crud.create(db_with_add, test_schema(**obj_data2))106 id1 = db_obj1.id107 id2 = db_obj2.id108 updated_obj_schema1 = test_schema(**{'name': 'multi1', 'test_int': 12})109 updated_obj_schema2 = test_schema(**{'name': 'multi2', 'test_int': 23})110 obj1 = {'db_obj': db_obj1, 'obj_in': updated_obj_schema1}111 obj2 = {'db_obj': db_obj2, 'obj_in': updated_obj_schema2}112 objs_in = [obj1, obj2]113 test_crud.update_multi(db_with_add, objs_in)114 retrieved_obj1 = test_crud.get_by_id(db_with_add, id1)115 assert retrieved_obj1.id == id1116 assert retrieved_obj1.name == updated_obj_schema1.name117 assert retrieved_obj1.test_int == updated_obj_schema1.test_int118 retrieved_obj2 = test_crud.get_by_id(db_with_add, id2)119 assert retrieved_obj2.id == id2120 assert retrieved_obj2.name == updated_obj_schema2.name121 assert retrieved_obj2.test_int == updated_obj_schema2.test_int122class TestRemoveData:123 def test_remove_single_data_with_id(self, db_with_add, test_crud, test_schema):124 obj_in = test_schema(name="test", test_int=999)125 obj_created = test_crud.create(db_with_add, obj_in)126 _id = obj_created.id127 removed_obj = test_crud.remove_with_id(db_with_add, _id)128 assert removed_obj.id == obj_created.id129 assert test_crud.get_by_id(db_with_add, _id) is None130 def test_remove_multiple_data_with_id(self, db_with_add, test_crud, test_schema):131 obj1 = test_schema(name="test1", test_int=999)132 obj2 = test_schema(name="test2", test_int=888)133 obj_created1 = test_crud.create(db_with_add, obj1)134 obj_created2 = test_crud.create(db_with_add, obj2)135 id1, id2 = (obj_created1.id, obj_created2.id)136 test_crud.remove_multi_with_id(db_with_add, [id1, id2])137 assert test_crud.get_by_id(db_with_add, id1) is None138 assert test_crud.get_by_id(db_with_add, id2) is None139 def test_remove_single_data(self, db_with_add, test_crud, test_schema):140 obj_in = test_schema(name="test", test_int=999)141 obj_created = test_crud.create(db_with_add, obj_in)142 test_crud.remove(db_with_add, obj_created)143 assert test_crud.get_by_id(db_with_add, obj_created.id) is None144 def test_remove_multiple_data(self, db_with_add, test_crud, test_schema):145 obj1 = test_schema(name="test1", test_int=999)146 obj2 = test_schema(name="test2", test_int=888)147 obj_created1 = test_crud.create(db_with_add, obj1)148 obj_created2 = test_crud.create(db_with_add, obj2)149 test_crud.remove_multi(db_with_add, [obj_created1, obj_created2])150 assert test_crud.get_by_id(db_with_add, obj_created1.id) is None...
tests.py
Source:tests.py
1from django.test import TestCase2from .repositories import *3from users.models import CustomUser4class test_CRUD(TestCase):5 client_user = CustomUser(role=CustomUser.SUPERUSER)6 fixtures = ['prices.json']7 @staticmethod8 def test_Customer():9 user = CustomUser(10 email = "1234@mail.ru",11 password = "secure_password",12 role = 0,13 club = 1,14 login = "1234qwerty"15 )16 customer = Customers(17 customer_id = 1,18 sex = "man",19 name = "ÐÑигоÑий",20 surname = "ÐладимиÑÑкий",21 patronymic = "ÐнÑоновиÑ",22 day_of_birth = "1989-05-23",23 tariff_end_date = "2021-08-14",24 tariff_id = 1,25 user = user26 )27 CustomersRepository.create(test_CRUD.client_user, customer)28 db_customer = CustomersRepository.read_by_pk(29 test_CRUD.client_user, 1)30 assert(db_customer.customer_id == 1)31 assert(db_customer.sex == "man")32 assert(db_customer.name == "ÐÑигоÑий")33 assert(db_customer.surname == "ÐладимиÑÑкий")34 assert(db_customer.patronymic == "ÐнÑоновиÑ")35 assert(str(db_customer.day_of_birth) == "1989-05-23")36 assert(str(db_customer.tariff_end_date) == "2021-08-14")37 CustomersRepository.update_by_pk(test_CRUD.client_user, 1, {'name': "ÐаленÑин", 'surname' : "Ðжов"})38 db_customer = CustomersRepository.read_by_pk(test_CRUD.client_user, 1)39 assert(db_customer.name == "ÐаленÑин")40 assert(db_customer.surname == "Ðжов")41 CustomersRepository.delete_by_pk(test_CRUD.client_user, 1)42 delete_flag = 043 try:44 CustomersRepository.read_by_pk(test_CRUD.client_user, 1)45 except:46 delete_flag = 147 assert(delete_flag == 1)48 @staticmethod49 def test_Instructors():50 user = CustomUser(51 email="12345@mail.ru",52 password="secure_password",53 role=1,54 club=1,55 login="12345qwerty"56 )57 instructor = Instructors(58 instructor_id = 1,59 user = user,60 sex = "woman",61 name = "ÐлизавеÑа",62 surname = "ÐоÑапова",63 patronymic = "Ðиколаевна",64 education = ["ÐемÐУ"],65 experience = 20,66 achievements = ["ÐС по ÑинÑ
ÑÐ¾Ð½Ð½Ð¾Ð¼Ñ Ð¿Ð»Ð°Ð²Ð°Ð½Ð¸Ñ","ÐÑезенÑÐµÑ ÑоÑÑийÑкиÑ
конвенÑий по напÑавлениÑм step и aero","ÐаÑÑÐµÑ ÑпоÑÑа по дзÑдо"],67 specialization = ["ÐодгоÑовка к ÑоÑевнованиÑм","ÐоÑÑÑановление поÑле ÑÑавм и опеÑаÑий","ФÑнкÑионалÑнÑй ÑÑенинг"]68 )69 InstructorsRepository.create(test_CRUD.client_user, instructor)70 db_instructor = InstructorsRepository.read_by_pk(71 test_CRUD.client_user, 1)72 assert(db_instructor.user == user)73 assert(db_instructor.sex == "woman")74 assert(db_instructor.name == "ÐлизавеÑа")75 assert(db_instructor.surname == "ÐоÑапова")76 assert(db_instructor.patronymic == "Ðиколаевна")77 assert(db_instructor.education == ["ÐемÐУ"])78 assert(db_instructor.experience == 20)79 assert(str(db_instructor.achievements) == str(["ÐС по ÑинÑ
ÑÐ¾Ð½Ð½Ð¾Ð¼Ñ Ð¿Ð»Ð°Ð²Ð°Ð½Ð¸Ñ","ÐÑезенÑÐµÑ ÑоÑÑийÑкиÑ
конвенÑий по напÑавлениÑм step и aero", "ÐаÑÑÐµÑ ÑпоÑÑа по дзÑдо"]))80 assert(str(db_instructor.specialization) == str(["ÐодгоÑовка к ÑоÑевнованиÑм", "ÐоÑÑÑановление поÑле ÑÑавм и опеÑаÑий", "ФÑнкÑионалÑнÑй ÑÑенинг"]))81 InstructorsRepository.update_by_pk(test_CRUD.client_user, 1, {'name': "ÐаленÑина", 'surname': "Ðжова"})82 db_instructor = InstructorsRepository.read_by_pk(test_CRUD.client_user, 1)83 assert (db_instructor.name == "ÐаленÑина")84 assert (db_instructor.surname == "Ðжова")85 InstructorsRepository.delete_by_pk(test_CRUD.client_user, 1)86 delete_flag = 087 try:88 InstructorsRepository.read_by_pk(test_CRUD.client_user, 1)89 except:90 delete_flag = 1...
test_crud.py
Source:test_crud.py
1"""Deprecated import support. Auto-generated by import_shims/generate_shims.sh."""2# pylint: disable=redefined-builtin,wrong-import-position,wildcard-import,useless-suppression,line-too-long3from import_shims.warn import warn_deprecated_import4warn_deprecated_import('contentstore.tests.test_crud', 'cms.djangoapps.contentstore.tests.test_crud')...
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!!