def test_add_trigger_type_with_params(self): MOCK_TRIGGER.type = 'system.test' # Trigger type with params should not create a trigger. PARAMETERS_SCHEMA = { "type": "object", "properties": { "url": { "type": "string" } }, "required": ['url'], "additionalProperties": False } trig_type = { 'name': 'myawesometriggertype2', 'pack': 'dummy_pack_1', 'description': 'Words cannot describe how awesome I am.', 'parameters_schema': PARAMETERS_SCHEMA, 'payload_schema': {} } trigtype_dbs = container_utils.add_trigger_models( pack='my_pack_1', trigger_types=[trig_type]) trigger_type, trigger = trigtype_dbs[0] trigtype_db = TriggerType.get_by_id(trigger_type.id) self.assertEqual(trigtype_db.pack, 'my_pack_1') self.assertEqual(trigtype_db.name, trig_type.get('name')) self.assertEqual(trigger, None)
def test_add_trigger_type_with_params(self): MOCK_TRIGGER.type = 'system.test' # Trigger type with params should not create a trigger. PARAMETERS_SCHEMA = { "type": "object", "properties": { "url": {"type": "string"} }, "required": ['url'], "additionalProperties": False } trig_type = { 'name': 'myawesometriggertype2', 'pack': 'dummy_pack_1', 'description': 'Words cannot describe how awesome I am.', 'parameters_schema': PARAMETERS_SCHEMA, 'payload_schema': {} } trigtype_dbs = container_utils.add_trigger_models(pack='my_pack_1', trigger_types=[trig_type]) trigger_type, trigger = trigtype_dbs[0] trigtype_db = TriggerType.get_by_id(trigger_type.id) self.assertEqual(trigtype_db.pack, 'my_pack_1') self.assertEqual(trigtype_db.name, trig_type.get('name')) self.assertEqual(trigger, None)
def test_triggertype_crud(self): saved = ReactorModelTest._create_save_triggertype() retrieved = TriggerType.get_by_id(saved.id) self.assertEqual(saved.name, retrieved.name, 'Same triggertype was not returned.') # test update self.assertEqual(retrieved.description, '') retrieved.description = DUMMY_DESCRIPTION saved = TriggerType.add_or_update(retrieved) retrieved = TriggerType.get_by_id(saved.id) self.assertEqual(retrieved.description, DUMMY_DESCRIPTION, 'Update to trigger failed.') # cleanup ReactorModelTest._delete([retrieved]) try: retrieved = TriggerType.get_by_id(saved.id) except ValueError: retrieved = None self.assertIsNone(retrieved, 'managed to retrieve after failure.')
def test_triggertype_crud(self): saved = ReactorModelTest._create_save_triggertype() retrieved = TriggerType.get_by_id(saved.id) self.assertEqual(saved.name, retrieved.name, 'Same triggertype was not returned.') # test update self.assertEqual(retrieved.description, '') retrieved.description = DUMMY_DESCRIPTION saved = TriggerType.add_or_update(retrieved) retrieved = TriggerType.get_by_id(saved.id) self.assertEqual(retrieved.description, DUMMY_DESCRIPTION, 'Update to trigger failed.') # cleanup ReactorModelTest._delete([retrieved]) try: retrieved = TriggerType.get_by_id(saved.id) except ValueError: retrieved = None self.assertIsNone(retrieved, 'managed to retrieve after failure.')
def test_add_trigger_type_no_params(self): # Trigger type with no params should create a trigger with same name as trigger type. trig_type = { 'name': 'myawesometriggertype', 'pack': 'dummy_pack_1', 'description': 'Words cannot describe how awesome I am.', 'parameters_schema': {}, 'payload_schema': {} } trigtype_dbs = container_utils.add_trigger_models( pack='my_pack_1', trigger_types=[trig_type]) trigger_type, trigger = trigtype_dbs[0] trigtype_db = TriggerType.get_by_id(trigger_type.id) self.assertEqual(trigtype_db.pack, 'my_pack_1') self.assertEqual(trigtype_db.name, trig_type.get('name')) self.assertTrue(trigger is not None) self.assertEqual(trigger.name, trigtype_db.name)
def test_add_trigger_type_no_params(self): # Trigger type with no params should create a trigger with same name as trigger type. trig_type = { 'name': 'myawesometriggertype', 'pack': 'dummy_pack_1', 'description': 'Words cannot describe how awesome I am.', 'parameters_schema': {}, 'payload_schema': {} } trigtype_dbs = container_utils.add_trigger_models(pack='my_pack_1', trigger_types=[trig_type]) trigger_type, trigger = trigtype_dbs[0] trigtype_db = TriggerType.get_by_id(trigger_type.id) self.assertEqual(trigtype_db.pack, 'my_pack_1') self.assertEqual(trigtype_db.name, trig_type.get('name')) self.assertTrue(trigger is not None) self.assertEqual(trigger.name, trigtype_db.name)