def test_project_sync_url_base_schema(self): """ Check nothing bad happens if a Project can't be found or if some needed fields are missing in the schema """ self.set_sg_mock_schema(os.path.join( os.path.dirname(__file__), "fixtures", "schemas", "base", )) shotgun = mockgun.Shotgun( "http://unit_test_mock_sg", "mock_user", "mock_key" ) # Check nothing bad happens if a Project can't be found or if some # needed fields are missing in the schema routing = {} sg_jira_event_trigger.process_event( shotgun, logger, EVENT, routing ) # Add missing project self.add_to_sg_mock_db(shotgun, PROJECT) sg_jira_event_trigger.process_event( shotgun, logger, EVENT, routing ) self.assertTrue(PROJECT["id"] in routing)
def setUp(self): # Switch to a schema with needed fields self.set_sg_mock_schema( os.path.join(os.path.dirname(__file__), "fixtures", "schemas", "sg-jira")) self._shotgun = mockgun.Shotgun("http://unit_test_mock_sg", "mock_user", "mock_key") self.mock_jira_session_bases() self.add_to_sg_mock_db( self._shotgun, [ { "type": "HumanUser", "id": 1, "login": "******", "email": "*****@*****.**", "sg_jira_account_id": None, }, { "type": "HumanUser", "id": 2, "login": "******", "email": "*****@*****.**", "sg_jira_account_id": None, }, { "type": "HumanUser", "id": 3, "login": "******", "email": "*****@*****.**", "sg_jira_account_id": None, }, { "type": "HumanUser", "id": 4, "login": "******", "email": "*****@*****.**", "sg_jira_account_id": None, }, ], ) self._jira = JiraSession("https://somesite") self._jira._is_jira_cloud = True self._jira.set_projects([JIRA_PROJECT])
def test_project_sync_url(self, mocked): """ Test retrieving the dispatch url for a Project. """ routing = {} # Switch to a schema with needed fields self.set_sg_mock_schema(os.path.join( os.path.dirname(__file__), "fixtures", "schemas", "sg-jira", )) shotgun = mockgun.Shotgun( "http://unit_test_mock_sg", "mock_user", "mock_key" ) self.add_to_sg_mock_db(shotgun, PROJECT) sg_jira_event_trigger.process_event( shotgun, logger, EVENT, routing ) self.assertTrue(PROJECT["id"] in routing) self.assertIsNone(routing[PROJECT["id"]]) routing = {} url = "http://localhost/default/sg2jira" shotgun.update( PROJECT["type"], PROJECT["id"], data={ "sg_jira_sync_url": { "content_type": "string", "link_type": "web", "name": "test", "url": "http://localhost/default/sg2jira" } } ) sg_jira_event_trigger.process_event( shotgun, logger, EVENT, routing ) self.assertTrue(PROJECT["id"] in routing) self.assertTrue(routing[PROJECT["id"]].startswith(url)) mocked.assert_called_once() self.assertTrue(mocked.call_args[0][0].startswith(url)) # Check the trigger clears its routing cache if the sync url is changed project_event = { "event_type": "Shotgun_Project_Change", "entity": PROJECT, "project": None, "attribute_name": "sg_jira_sync_url", "meta": { "type": "attribute_change", "attribute_name": "sg_jira_sync_url", "entity_type": PROJECT["type"], "entity_id": PROJECT["id"], "field_data_type": "url", "old_value": None, "new_value": { "attachment_id": 1416, "attachment_type": "http_url", "display_name": "Jira Sync", "icon_url": "/images/filetypes/filetype_icon_misc.png", "icon_class": "icon_web", "url": "http://localhost/default/sg2jira", "attachment_uuid": "abcdefg" } } } sg_jira_event_trigger.process_event( shotgun, logger, project_event, routing ) self.assertFalse(PROJECT["id"] in routing) # Processing the Task event should cache the routing again sg_jira_event_trigger.process_event( shotgun, logger, EVENT, routing ) self.assertTrue(PROJECT["id"] in routing) self.assertTrue(routing[PROJECT["id"]].startswith(url)) mocked.assert_called() self.assertTrue(mocked.call_args[0][0].startswith(url))