def create_label(label: LabelInputObject) -> Label: if has_label_with_label_text(label.label): return get_label_with_text(label.label) else: label.description = label.description if label.description else "" new_db_label = Label(unique_label=label.label.lower(), label=label.label, description=label.description) new_db_label.save() return new_db_label
def test_create_correct(self): client = Client(schema) name = 'Test-Scenario' description = 'boomerang' folder = self.folders[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() executed = client.execute(''' mutation { createScenario ( name: "%s", description: "%s", folderId: %s, labels: {label: "%s", description: "%s"} ) { name } } ''' % (name, description, folder.id, label.unique_label, label.description)) self.assertEquals(executed['data']['createScenario']['name'], name)
def test_query(self): client = Client(schema) scenario = self.scenarios[0] folder = self.folders[0] segment = self.segments[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() ScenarioToLabel(scenario=scenario, label=label).save() executed = client.execute( ''' query { scenarios ( name: "%s", desc: "boomerang", folderId: %s, roadSegmentId: %s, labelName: "%s" ) { name } } ''' % (scenario.name, folder.id, segment.id, label.unique_label)) self.assertEquals(executed['data']['scenarios'][0]['name'], scenario.name)
def test_update(self): client = Client(schema) scenario = self.scenarios[1] name = 'New-Name' description = 'Tori' folder = self.folders[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() executed = client.execute(''' mutation { updateScenario ( id: %s, name: "%s", description: "%s", folderId: %s, labels: [{label: "%s", description: "%s"}] ) { name } } ''' % (scenario.id, name, description, folder.id, label.unique_label, label.description)) self.assertEquals(executed['data']['updateScenario']['name'], name)
def test_query(self): client = Client(schema) instrument = self.instruments[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() InstrumentToLabel(instrument=instrument, label=label).save() instrument.description = "bt" instrument.save() executed = client.execute( ''' query { instruments ( name: "%s", instrumentTypeId: %s, instrumentSystemId: %s, desc: "%s", labelName: "%s" ) { name } } ''' % (instrument.name, instrument.instrument_type.id, instrument.instrument_system.id, instrument.description, label.unique_label)) self.assertEquals(executed['data']['instruments'][0]['name'], instrument.name)
def test_create_correct(self): client = Client(schema) new_name = 'Test-Name' instrument_system = self.instrument_systems[0] instrument_type = self.instrument_types[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() executed = client.execute( ''' mutation { createInstrument ( name: "%s", lat: 2.0, lng: 2.0, instrumentSystemId: %s, instrumentTypeId: %s, labels: {label: "%s", description: "%s"} ) { name } } ''' % (new_name, instrument_system.id, instrument_type.id, label.unique_label, label.description)) self.assertEquals(executed['data']['createInstrument']['name'], new_name)
def test_update(self): client = Client(schema) new_name = 'Test-Name' lat = 3.666 lng = 3.666 description = 'Test-Desc' instrument_system = self.instrument_systems[1] instrument_type = self.instrument_types[1] instrument = self.instruments[0] label = Label() label.label = "boomerang" label.unique_label = "boomerang" label.description = "tori" label.save() executed = client.execute( ''' mutation { updateInstrument ( id: %s, name: "%s", lat: %s, lng: %s, description: "%s", instrumentSystemId: %s, instrumentTypeId: %s, labels: {label: "%s", description: "%s"} ) { description } } ''' % (instrument.id, new_name, lat, lng, description, instrument_system.id, instrument_type.id, label.unique_label, label.description)) self.assertEquals(executed['data']['updateInstrument']['description'], description)