Best Python code snippet using lemoncheesecake
migrate.py
Source:migrate.py
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)
...
test_dcl_lookup.py
Source:test_dcl_lookup.py
...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')...
0021_load_intial_data.py
Source:0021_load_intial_data.py
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),...
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!!