def test_search(self): api = Api() api._make_get = MagicMock( return_value={ 'issues': [{ 'id': 'id1', 'key': 'key1', 'fields': { 'duedate': '2019-01-01', 'summary': 'summary1', 'key': 'key1', 'assignee': None, 'project': { 'id': 'id1', 'name': 'name1' }, 'status': { 'id': 'id1', 'name': 'name1' }, 'issuetype': { 'name': 'name1' } } }] }) self.assertEqual(1, api.search('project=key').get_length())
def _get_data(self): collection = Api().search(self.jql) unique_index = {} for item in collection.get_list(): if item.assignee.ident is None: continue index = '_'.join([item.assignee.ident, item.status.ident]) if unique_index.get(index) is None: unique_index[index] = [item] else: unique_index[index].append(item) return [val for val in unique_index.values() if len(val) > 1]
def _get_data(self): collection = Api().search(self.jql) error_empty_date = {} for issue in collection.get_list(): if issue.assignee is None or issue.due_date is not None: continue user_id = issue.assignee.ident if not error_empty_date.get(user_id): error_empty_date[user_id] = [] error_empty_date[user_id].append(issue) return error_empty_date.values()
def _get_data(self): collection = Api().search(self.jql) error_date_outdated = {} for issue in collection.get_list(): if issue.assignee is None or issue.due_date is None: continue if issue.due_date.date() >= datetime.now().date(): continue user_id = issue.assignee.ident if not error_date_outdated.get(user_id): error_date_outdated[user_id] = [] error_date_outdated[user_id].append(issue) return error_date_outdated.values()
def test__make_get_error(self): Config.JIRA_HOST = 'http://jira.host' httpretty.register_uri(httpretty.GET, 'http://jira.host/error', body="Bad json string", status=500) self.assertEqual({}, Api()._make_get('/error', {}))
def test__create_user(self): item = Api()._create_user({ 'key': 'id1', 'displayName': 'name1', 'emailAddress': 'email1' }) self.assertEqual('id1', item.ident) self.assertEqual('name1', item.display_name) self.assertEqual('email1', item.email)
def _get_data(self): return Api().search(self.jql).get_list()
def test_search_false_data(self): api = Api() api._make_get = MagicMock(return_value="false-data") self.assertEqual({}, api.search('project=key'))
def test__make_get(self): Config.JIRA_HOST = 'http://jira.host' httpretty.register_uri(httpretty.GET, 'http://jira.host/data', body="[1, 2, {\"a\": 1}]") self.assertEqual([1, 2, {'a': 1}], Api()._make_get('/data', {}))
def test__make_get_bad_json(self): Config.JIRA_HOST = 'http://jira.host' httpretty.register_uri(httpretty.GET, 'http://jira.host/bad-json', body="Bad json string") self.assertEqual({}, Api()._make_get('/bad-json', {}))
def test__create_user_with_none_data(self): item = Api()._create_user(None) self.assertEqual(None, item.ident) self.assertEqual(None, item.display_name) self.assertEqual(None, item.email)
def test__create_status(self): item = Api()._create_status({'id': 'id1', 'name': 'name1'}) self.assertEqual('id1', item.ident) self.assertEqual('name1', item.name)
def test__create_datetime(self): self.assertEqual(datetime(2019, 1, 1, 1, 1, 1), Api()._create_datetime('2019-01-01 01:01:01')) self.assertEqual(datetime(2019, 1, 1, 0, 0, 0), Api()._create_datetime('2019-01-01')) self.assertEqual(None, Api()._create_datetime(1))