Best Python code snippet using autotest_python
bl.py
Source:bl.py  
1import da2from atlas_manager import execute_service3def get_things():4    return {5        'code': 200,6        'result': da.get_all_things()7    }8def get_all_services():9    return {10        'code': 200,11        'result': da.get_all_services()12    }13def get_services(thing_id):14    return {15        'code': 200,16        'result': da.get_services_of_thing(thing_id)17    }18def get_relationships():19    return{20        'code': 200,21        'result': da.get_all_relationships()22    }23def create_relationship(data):24    if 'name' not in data or 'desc' not in data or 'service1' not in data or 'service2' not in data:25        return {26            'code': 400,27            'msg': 'Name, Description, or Services not provided'28        }29    name = data['name']30    desc = data['desc']31    service_1 = data['service1']32    service_2 = data['service2']33    if 'icon' in data:34        icon = data['icon']35    else:36        icon = ''37    result = da.create_relationship(38        name=name, icon=icon, desc=desc, service_1=service_1, service_2=service_2)39    if result:40        return {41            'code': 201,42            'msg': 'Relationship created'43        }44    else:45        return {46            'code': 500,47            'msg': 'Server error. It is not you, it is us.'48        }49def create_thing(data):50    if 'id' not in data or 'name' not in data or 'desc' not in data or 'space' not in data or 'ip' not in data:51        return {52            'code': 400,53            'msg': 'ID, Name, Description, IP address or Space not provided'54        }55    id = data['id']56    name = data['name']57    desc = data['desc']58    space = data['space']59    ip = data['ip']60    if 'icon' in data:61        icon = data['icon']62    else:63        icon = ''64    result = da.create_thing(65        id=id, name=name, icon=icon, desc=desc, space=space, ip=ip)66    if result:67        return {68            'code': 201,69            'msg': 'Thing created'70        }71    else:72        return {73            'code': 500,74            'msg': 'Server error. It is not you, it is us.'75        }76def create_service(data):77    if 'thing' not in data or 'name' not in data or 'entity' not in data or 'space' not in data:78        return {79            'code': 400,80            'msg': 'Thing, Name, Entity or Space not provided'81        }82    thing = data['thing']83    name = data['name']84    entity = data['entity']85    space = data['space']86    if 'icon' in data:87        icon = data['icon']88    else:89        icon = ''90    result = da.create_service(91        thing=thing, name=name, icon=icon, entity=entity, space=space)92    if result:93        return {94            'code': 201,95            'msg': 'Service {} created'.format(name)96        }97    else:98        return {99            'code': 500,100            'msg': 'Server error. It is not you, it is us.'101        }102def create_recipe(data):103    if 'name' not in data or 'relationships' not in data or 'relationships' not in data:104        return {105            'code': 400,106            'msg': 'Name or relationships not provided'107        }108    name = data['name']109    id = name110    relationships = data['relationships']111    if 'icon' in data:112        icon = data['icon']113    else:114        icon = ''115    result = da.create_recipe(116        id=id, name=name, icon=icon, relationships=relationships)117    if result:118        return {119            'code': 201,120            'msg': 'Recipe {} created'.format(name)121        }122    else:123        return {124            'code': 500,125            'msg': 'Server error. It is not you, it is us.'126        }127def get_recipes():128    return{129        'code': 200,130        'result': da.get_recipes()131    }132def run_recipe(recipe_id):133    recipe = da.get_recipe(recipe_id)134    recipe_results = {135        'recipe': recipe,136        'result': []137    }138    for relationship in recipe['relationships']:139        relationship_results = {140            'relationship': relationship,141            'result': []142        }143        result_1 = execute_service(relationship['service1'], None)144        result_2 = execute_service(relationship['service2'], result_1)145        relationship_results['result'].append({146            'service': relationship['service1'],147            'result': result_1148        })149        relationship_results['result'].append({150            'service': relationship['service2'],151            'result': result_2152        })153        recipe_results['result'].append(relationship_results)154    return {155        'code': 200,156        'msg': 'Actions performed',157        'result': recipe_results158    }159def enable_disable_recipe(recipe_id):160    result = da.enable_disable_recipe(recipe_id)161    if result:162        return {163            'code': 200,164            'msg': 'Recipe enabled/disabled',165        }166    else:167        return {168            'code': 500,169            'msg': 'Server error. It is not you, it is us.'170        }171def delete_recipe(recipe_id):172    result = da.delete_recipe(recipe_id)173    if result:174        return {175            'code': 200,176            'msg': 'Recipe deleted'177        }178    else:179        return {180            'code': 500,181            'msg': 'Server error. It is not you, it is us.'182        }183def import_recipe(data):184    try:185        relationships = data['relationships']186        for relationship in relationships:187            service_1 = relationship['service1']188            service_2 = relationship['service2']189            da.create_relationship(name=relationship['name'], desc=relationship['desc'], service_1=service_1['name'], service_2=service_2['name'])190            da.create_service(thing=service_1['thing']['id'], name=service_1['name'], entity=service_1['entity'], space=service_1['space'], icon=service_1['icon'])191            da.create_service(thing=service_2['thing']['id'], name=service_2['name'], entity=service_2['entity'], space=service_2['space'], icon=service_2['icon'])192        193        da.create_recipe(id=data['id'], name=data['name'], relationships=[relationship['name'] for relationship in relationships], icon=data['icon'], enabled=False)194        return {195            'code': 200,196            'msg': 'Recipe imported'197        }198    except:199        return {200            'code': 500,201            'msg': 'Error importing'...test_services.py
Source:test_services.py  
1from mock import sentinel2import pytest3from hear_me.libs.services import ServiceRegistry4class TestServiceRegistry(object):5    @pytest.fixture6    def service_registry(self):7        return ServiceRegistry()8    def test_register(self, service_registry):9        service_registry.register('service_1', sentinel.service_1)10        service_registry.register('service_2', sentinel.service_2)11        assert service_registry.services == {12            'service_1': sentinel.service_1,13            'service_2': sentinel.service_2,14        }15        assert service_registry.services.service_1 == sentinel.service_116        assert service_registry.services.service_2 == sentinel.service_217    def test_register_on_already_registered_service(self, service_registry):18        service_registry.register('service_1', sentinel.service_1)19        with pytest.raises(RuntimeError):20            service_registry.register('service_1', sentinel.service_1)21    def test_query_service(self, service_registry):22        service_registry.register('service_1', sentinel.service_1)23        service_registry.register('service_2', sentinel.service_2)24        service_1 = service_registry.query_service('service_1')25        service_2 = service_registry.query_service('service_2')26        assert service_1 == sentinel.service_127        assert service_2 == sentinel.service_228    def test_service_decorator_registry(self, service_registry):29        @service_registry.service30        def random_service():31            return sentinel.service_1...main_5.19.py
Source:main_5.19.py  
1#Charlotte Carbaugh, Student ID 181553223services = {'Oil change': 35, 'Tire rotation': 19, 'Car wash': 7, 'Car wax': 12, '-': 'No service'}45print("Davy's auto shop services")6print("Oil change -- $35\nTire rotation -- $19\nCar wash -- $7\nCar wax -- $12\n")78service_1 = str(input("Select first service:\n"))9service_2 = str(input("Select second service:\n"))1011print("\nDavy's auto shop invoice\n")12if service_1 == '-':13    print("Service 1:", services[service_1])14else:15    print("Service 1:", service_1 + ", $" + str(services[service_1]))16if service_2 == '-':17    print("Service 2:", services[service_2] + '\n')18else:19    print("Service 2:", service_2 + ", $" + str(services[service_2]) + "\n")2021if (service_1 == '-') and (service_2 == '-' ):22    invoice  = 023elif service_2 == '-':24    invoice = services[service_1]25elif service_1 == '-':26    invoice = services[service_2]27else:28    invoice = services[service_1] + services[service_2]2930
...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!!
