How to use create_thing method in hypothesis

Best Python code snippet using hypothesis

test_api.py

Source:test_api.py Github

copy

Full Screen

...18 things = app.api.get_things()19 assert things == []20 def test_thing_creation(self, app, random_name):21 thing_name = random_name()22 thing_id = app.api.create_thing(thing_name)23 assert thing_id is not None24 assert isinstance(thing_id, str)25 def test_thing_bulk_creation(self, app, random_name):26 names = [random_name() for i in range(self.BULK_CREATION_NUMBER)]27 things = app.api.create_things_bulk(names)28 assert isinstance(things, list)29 created_names = [t['name'] for t in things]30 for name in names:31 assert name in created_names32 def test_delete_thing(self, app, random_name):33 thing_name = random_name()34 _id = app.api.create_thing(thing_name)35 status_code = app.api.delete_thing(_id)36 assert status_code == 20437 def test_get_things(self, app, random_name):38 names = [random_name() for i in range(self.BULK_CREATION_NUMBER)]39 app.api.create_things_bulk(names)40 things = app.api.get_things()41 assert isinstance(things, list)42 assert len(things) == self.BULK_CREATION_NUMBER43 assert set([t['name'] for t in things]) == set(names)44 def test_get_thing(self, app, random_name):45 name = random_name()46 _id = app.api.create_thing(name)47 thing = app.api.get_thing(_id)48 assert isinstance(thing, dict)49 assert thing['id'] == _id50 assert thing['name'] == name51@pytest.mark.usefixtures('clean_things')52@pytest.mark.usefixtures('clean_channels')53class TestChannelsApi:54 BULK_CREATION_NUMBER = 555 def test_create_channel(self, app, random_name):56 name = random_name()57 channel_id = app.api.create_channel(name)58 assert isinstance(channel_id, str)59 assert channel_id != ""60 channel_dict = app.api.get_channel(channel_id)61 assert channel_dict["id"] == channel_id62 assert channel_dict["name"] == name63 def test_delete_all_channels(self, app):64 channels_names = [str(i) for i in range(self.BULK_CREATION_NUMBER)]65 channels = app.api.create_channels_bulk(channels_names)66 assert len(channels) == len(channels_names)67 app.api.delete_all_channels()68 channels = app.api.get_channels()69 assert channels == []70 def test_delete_channel(self, app, random_name):71 name = random_name()72 channel_id = app.api.create_channel(name)73 status_code = app.api.delete_channel(channel_id)74 assert isinstance(status_code, int)75 assert status_code == 20476 channel_dict = app.api.get_channel(channel_id)77 assert channel_dict["error"] == "non-existent entity"78 def test_connect_thing_to_channel(self, app, random_name):79 channel_name = random_name()80 thing_name = random_name()81 channel_id = app.api.create_channel(channel_name)82 thing_id = app.api.create_thing(thing_name)83 status_code = app.api.connect_thing_to_channel(thing_id, channel_id)84 assert isinstance(status_code, int)85 assert status_code == 20086 def test_get_connected_things(self, app, random_name):87 things_number = 388 channel_name = random_name()89 channel_id = app.api.create_channel(channel_name)90 thing_ids = []91 thing_names = []92 for i in range(things_number):93 name = random_name()94 thing_id = app.api.create_thing(name)95 app.api.connect_thing_to_channel(thing_id, channel_id)96 thing_ids.append(thing_id)97 thing_names.append(name)98 things = app.api.get_connected_things(channel_id)99 assert isinstance(things, list)100 assert len(things) == things_number101 for th in things:102 assert isinstance(th, dict)103 assert th["id"] in thing_ids104 assert th["name"] in thing_names105 def test_disconnect_thing_from_channel(self, app, random_name):106 channel_name = random_name()107 thing_name = random_name()108 channel_id = app.api.create_channel(channel_name)109 thing_id = app.api.create_thing(thing_name)110 app.api.connect_thing_to_channel(thing_id, channel_id)111 status_code = app.api.disconnect_thing_from_channel(channel_id, thing_id)112 assert isinstance(status_code, int)113 assert status_code == 204114 channel_things = app.api.get_connected_things(channel_id)115 for th in channel_things:...

Full Screen

Full Screen

test.py

Source:test.py Github

copy

Full Screen

...27batch.add_thing({"name": "Plato"}, "Person")28print("Load batch")29w.create_things_in_batch(batch)30print("Load a single things")31w.create_thing({"name": "Andrew S. Tanenbaum"}, "Person", "28954261-0449-57a2-ade5-e9e08d11f51a")32w.create_thing({"name": "Alan Turing"}, "Person", "1c9cd584-88fe-5010-83d0-017cb3fcb446")33w.create_thing({"name": "John von Neumann"}, "Person", "b36268d4-a6b5-5274-985f-45f13ce0c642")34w.create_thing({"name": "Tim Berners-Lee"}, "Person", "d1e90d26-d82e-5ef8-84f6-ca67119c7998")35w.create_thing({"name": "Legends"}, "Group", "2db436b5-0557-5016-9c5f-531412adf9c6")36w.create_thing({"name": "Chemists"}, "Group", "577887c1-4c6b-5594-aa62-f0c17883d9bf")37chemists = [None]*338chemists[0] = w.create_thing({"name": "Marie Curie"}, "Person")39chemists[1] = w.create_thing({"name": "Fritz Haber"}, "Person")40chemists[2] = w.create_thing({"name": "Walter White"}, "Person")41time.sleep(1.1) # Let weaviate refresh its index with the newly loaded things42print("Add reference to thing")43w.add_reference_to_thing("2db436b5-0557-5016-9c5f-531412adf9c6", "members", "b36268d4-a6b5-5274-985f-45f13ce0c642")44w.add_reference_to_thing("2db436b5-0557-5016-9c5f-531412adf9c6", "members", "1c9cd584-88fe-5010-83d0-017cb3fcb446")45print("Add reference to thing in batch")46reference_batch = weaviate.batch.ReferenceBatchRequest()47for chemist in chemists:48 reference_batch.add_reference("Group", "577887c1-4c6b-5594-aa62-f0c17883d9bf", "members", chemist)49w.add_references_in_batch(reference_batch)50time.sleep(1.1) # Let weaviate refresh its index with the newly updated things51print("Validate if loading was successful")52legends = query_data(gql_get_group_legends)53for member in legends["Group"][0]["Members"]:54 if not member["name"] in ["John von Neumann", "Alan Turing"]:55 print("Adding references to things failed")56 exit(5)57group_chemists = query_data(gql_get_group_chemists)58for member in group_chemists["Group"][0]["Members"]:59 if not member["name"] in ["Marie Curie", "Fritz Haber", "Walter White"]:60 print("Adding references to things failed")61 exit(6)62if len(group_chemists["Group"][0]["Members"]) != 3:63 exit(7)64print("Test Delete")65w.delete_thing(chemists[2]) # Delete Walter White not a real chemist just a legend66time.sleep(1.1)67if w.get_thing(chemists[2]) is not None:68 print("Thing was not correctly deleted")69 exit(8)70# Test delete reference71prime_ministers_group = w.create_thing({"name": "Prime Ministers"}, "Group")72prime_ministers = []73prime_minister_names = ["Wim Kok", "Dries van Agt", "Piet de Jong"]74for name in prime_minister_names:75 prime_ministers.append(w.create_thing({"name": name}, "Person"))76time.sleep(1.2)77for prime_minister in prime_ministers:78 w.add_reference_to_thing(prime_ministers_group, "members", prime_minister)79time.sleep(1.2)80w.delete_reference_from_thing(prime_ministers_group, "members", prime_ministers[0])81# TODO test some how query seems to fail raiscondition or result set not big enough82# len(group_prime_ministers["Group"][0]["Members"][0]) != 3:83# print("Reference not deleted correctly")84# exit(9)85print("Test query")86expected_name = "Sophie Scholl"87w.create_thing({"name": expected_name}, "Person", "594b7827-f795-40d0-aabb-5e0553953dad")88time.sleep(2.0)89result = w.query(gql_get_sophie_scholl)90if result["data"]["Get"]["Things"]["Person"][0]["name"] != expected_name:91 print("Query result is wrong")92 exit(10)93print("Integration test successfully completed")...

Full Screen

Full Screen

lambda_function.py

Source:lambda_function.py Github

copy

Full Screen

...20# configure logging21logging.basicConfig(format='%(asctime)s %(levelname)s: %(message)s')22logger = logging.getLogger()23logger.setLevel(logging.INFO)24def create_thing(c_iot, thing_name):25 try:26 response = c_iot.create_thing(thingName='jitr-' + thing_name)27 logger.info("create_thing: response: {}".format(response))28 except Exception as e:29 logger.error("create_thing: {}".format(e))30def create_iot_policy(c_iot, policy_name):31 try:32 response = c_iot.create_policy(33 policyName=policy_name,34 policyDocument='{"Version":"2012-10-17","Statement":[{"Effect":"Allow","Action": "iot:*","Resource":"*"}]}'35 )36 logger.info("create_iot_policy: response: {}".format(response))37 except Exception as e:38 logger.error("create_iot_policy: {}".format(e))39def activate_certificate(c_iot, certificate_id):40 try:41 response = c_iot.update_certificate(42 certificateId=certificate_id,43 newStatus='ACTIVE'44 )45 logger.info("activate_cert: response: {}".format(response))46 except Exception as e:47 logger.error("activate_certificate: {}".format(e))48def attach_policy(c_iot, certificate_id):49 try:50 response = c_iot.describe_certificate(51 certificateId=certificate_id52 )53 #logger.info("describe_certificate: response: {}".format(response))54 certificate_arn = response['certificateDescription']['certificateArn']55 logger.info("certificate_arn: {}".format(certificate_arn))56 response = c_iot.attach_thing_principal(57 thingName='jitr-' + certificate_id,58 principal=certificate_arn59 )60 logger.info("attach_thing_principal: response: {}".format(response))61 response = c_iot.attach_policy(62 policyName=certificate_id,63 target=certificate_arn64 )65 logger.info("attach_policy: response: {}".format(response))66 except Exception as e:67 logger.error("attach_policy: {}".format(e))68def lambda_handler(event, context):69 logger.info("event:\n" + str(event))70 region = os.environ["AWS_REGION"]71 logger.info("region: {}".format(region))72 ca_certificate_id = event['caCertificateId']73 certificate_id = event['certificateId']74 certificate_status = event['certificateStatus']75 logger.info("ca_certificate_id: " + ca_certificate_id)76 logger.info("certificate_id: " + certificate_id)77 logger.info("certificate_status: " + certificate_status)78 c_iot = boto3.client('iot')79 create_thing(c_iot, certificate_id)80 create_iot_policy(c_iot, certificate_id)81 activate_certificate(c_iot, certificate_id)82 attach_policy(c_iot, certificate_id)83 #for k in os.environ.keys():84 # logger.info("{}: {}".format(k, os.environ[k]))...

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