How to use load_fixtures method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

migrate.py

Source:migrate.py Github

copy

Full Screen

2import json3from app import db, models4from datetime import datetime56def load_fixtures(file_path):7 # функция чтения файла8 content = []9 if os.path.isfile(file_path):10 with open(file_path, 'r', encoding='utf-8') as file:11 content = json.load(file)1213 return content1415def migrate_user_roles(fixture_path):16 # функция загрузки роли пользователя17 fixture_content = load_fixtures(fixture_path)18 for role in fixture_content:19 if db.session.query(models.UserRole).filter(models.UserRole.id == role['id']).first() is None:20 new_role = models.UserRole(**role)21 db.session.add(new_role)22 db.session.commit()232425def migrate_users(fixture_path):26 # функция загрузки данных пользователя27 fixture_content = load_fixtures(fixture_path)28 for user in fixture_content:29 if db.session.query(models.User).filter(models.User.id == user['id']).first() is None:30 new_user = models.User(**user)31 db.session.add(new_user)32 db.session.commit()333435def migrate_orders(fixture_path):36 # функция загрузки заказов37 fixture_content = load_fixtures(fixture_path)38 for order in fixture_content:39 # перевод даты в нужный формат40 for field_name, field_value in order.items():41 if isinstance(field_value, str) and field_value.count('/') == 2:42 order[field_name] = datetime.strptime(field_value, '%m/%d/%Y')4344 if db.session.query(models.Order).filter(models.Order.id == order['id']).first() is None:45 new_order = models.Order(**order)46 db.session.add(new_order)47 db.session.commit()484950def migrate_offers(fixture_path):51 # функция загрузки откликов на заказы52 fixture_content = load_fixtures(fixture_path)53 for offer in fixture_content:54 if db.session.query(models.Offer).filter(models.Offer.id == offer['id']).first() is None:55 new_offer = models.Offer(**offer)56 db.session.add(new_offer) ...

Full Screen

Full Screen

test_dcl_lookup.py

Source:test_dcl_lookup.py Github

copy

Full Screen

...28 raise Exception("idx {} out of expected range".format(idx))29 e = load_fixtures[idx]30 assert e['found'] == e['expected']31@given('I know a DCL with expected lookup values')32def load_fixtures():33 return fixtures.VALUES34#35# these are unrolled to avoid nasty exec-style code36#37@when('I query the DCL for the first lookup fixture')38def first_lookup_fixture(load_fixtures):39 query_dcl_fixture_idx(load_fixtures, 0)40@when('I query the DCL for the second lookup fixture')41def second_lookup_fixture(load_fixtures):42 query_dcl_fixture_idx(load_fixtures, 1)43@when('I query the DCL for the third lookup fixture')44def third_lookup_fixture(load_fixtures):45 query_dcl_fixture_idx(load_fixtures, 2)46@when('I query the DCL for the fourth lookup fixture')...

Full Screen

Full Screen

0021_load_intial_data.py

Source:0021_load_intial_data.py Github

copy

Full Screen

1# Generated by Django 2.1.5 on 2019-02-13 14:112from django.db import migrations3def load_fixtures(apps, schema_editor):4 from django.core.management import call_command5 call_command("loaddata", "scopes")6def unload_fixtures(apps, schema_editor):7 Scope = apps.get_model("scopes", "Scope")8 Scope.objects.all().delete()9class Migration(migrations.Migration):10 dependencies = [11 ('badge', '0020_auto_20190213_1507'),12 ]13 operations = [14 migrations.RunPython(load_fixtures, reverse_code=load_fixtures),...

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 Lemoncheesecake 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