Esempio n. 1
0
    def test_fetch_empty(self):
        """Test whether it works when no issues are fetched"""

        bodies_json = read_file('data/jira/jira_issues_page_empty.json')

        body = read_file('data/jira/jira_fields.json')

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               body=bodies_json, status=200)

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body, status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch()]

        expected_req = {
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 0 order by updated asc'],
                            'startAt': ['0']
                        }

        self.assertEqual(len(issues), 0)

        request = httpretty.last_request()
        self.assertEqual(request.method, 'GET')
        self.assertRegex(request.path, '/rest/api/2/search')
        self.assertDictEqual(request.querystring, expected_req)
Esempio n. 2
0
    def test_fetch_empty(self):
        """Test whether it works when no issues are fetched"""

        bodies_json = read_file('data/jira/jira_issues_page_empty.json')

        body = read_file('data/jira/jira_fields.json')

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               body=bodies_json,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body,
                               status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch()]

        expected_req = {
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 0'],
            'startAt': ['0']
        }

        self.assertEqual(len(issues), 0)

        request = httpretty.last_request()
        self.assertEqual(request.method, 'GET')
        self.assertRegex(request.path, '/rest/api/2/search')
        self.assertDictEqual(request.querystring, expected_req)
Esempio n. 3
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        jira = Jira(JIRA_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = cache_issues = [cache_issue for cache_issue in jira.fetch_from_cache()]
Esempio n. 4
0
    def test_fetch_from_cache_empty(self):
        """Test if there are not any issues returned when the cache is empty"""

        cache = Cache(self.tmp_path)

        jira = Jira(JIRA_SERVER_URL, cache=cache)
        cache_issues = [cache_issue for cache_issue in jira.fetch_from_cache()]

        self.assertEqual(len(cache_issues), 0)
Esempio n. 5
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        jira = Jira(JIRA_SERVER_URL)

        with self.assertRaises(CacheError):
            _ = cache_issues = [
                cache_issue for cache_issue in jira.fetch_from_cache()
            ]
Esempio n. 6
0
    def test_fetch_from_cache_empty(self):
        """Test if there are not any issues returned when the cache is empty"""

        cache = Cache(self.tmp_path)

        jira = Jira(JIRA_SERVER_URL, cache=cache)
        cache_issues = [cache_issue for cache_issue in jira.fetch_from_cache()]

        self.assertEqual(len(cache_issues), 0)
Esempio n. 7
0
    def test_parse_issues(self):
        """Test issues parsing"""

        raw_parse_json = read_file('data/jira/jira_issues_page_1.json')
        parse_json = read_file('data/jira/jira_issues_parse_expected.json')

        issues = Jira.parse_issues(raw_parse_json)

        result = [issue for issue in issues]

        parse = json.loads(parse_json)

        self.assertTrue(len(result), 2)

        self.assertEqual(result[0]["id"], "35851")
        self.assertEqual(result[0]["key"], "HELP-6043")
        self.assertEqual(result[0]["self"],
                         "https://jira.fiware.org/rest/api/2/issue/35851")
        self.assertEqual(
            result[0]["expand"],
            "operations,editmeta,changelog,transitions,renderedFields")
        self.assertEqual(len(result[0]["fields"]), 27)
        self.assertDictEqual(result[0]["fields"], parse[0]["fields"])

        self.assertEqual(result[1]["id"], "35850")
        self.assertEqual(result[1]["key"], "HELP-6042")
        self.assertEqual(result[1]["self"],
                         "https://jira.fiware.org/rest/api/2/issue/35850")
        self.assertEqual(
            result[1]["expand"],
            "operations,editmeta,changelog,transitions,renderedFields")
        self.assertEqual(len(result[1]["fields"]), 27)
        self.assertDictEqual(result[1]["fields"], parse[1]["fields"])
Esempio n. 8
0
    def test_parse_issues(self):
        """Test issues parsing"""

        raw_parse_json = read_file('data/jira/jira_issues_page_1.json')
        parse_json = read_file('data/jira/jira_issues_parse_expected.json')

        issues = Jira.parse_issues(raw_parse_json)

        result = [issue for issue in issues]

        parse = json.loads(parse_json)

        self.assertTrue(len(result), 2)

        self.assertEqual(result[0]["id"], "35851")
        self.assertEqual(result[0]["key"], "HELP-6043")
        self.assertEqual(result[0]["self"], "https://jira.fiware.org/rest/api/2/issue/35851")
        self.assertEqual(result[0]["expand"],
                         "operations,editmeta,changelog,transitions,renderedFields")
        self.assertEqual(len(result[0]["fields"]), 27)
        self.assertDictEqual(result[0]["fields"], parse[0]["fields"])

        self.assertEqual(result[1]["id"], "35850")
        self.assertEqual(result[1]["key"], "HELP-6042")
        self.assertEqual(result[1]["self"], "https://jira.fiware.org/rest/api/2/issue/35850")
        self.assertEqual(result[1]["expand"],
                         "operations,editmeta,changelog,transitions,renderedFields")
        self.assertEqual(len(result[1]["fields"]), 27)
        self.assertDictEqual(result[1]["fields"], parse[1]["fields"])
Esempio n. 9
0
    def test_initialization(self):
        """Test whether attributes are initializated"""

        jira = Jira(JIRA_SERVER_URL, origin='test', max_issues=5)

        self.assertEqual(jira.url, JIRA_SERVER_URL)
        self.assertEqual(jira.origin, 'test')
        self.assertEqual(jira.max_issues, 5)
        self.assertIsInstance(jira.client, JiraClient)

        # When origin is empty or None it will be set to
        # the value in url
        jira = Jira(JIRA_SERVER_URL)
        self.assertEqual(jira.url, JIRA_SERVER_URL)
        self.assertEqual(jira.origin, JIRA_SERVER_URL)

        jira = Jira(JIRA_SERVER_URL, origin='')
        self.assertEqual(jira.url, JIRA_SERVER_URL)
        self.assertEqual(jira.origin, JIRA_SERVER_URL)
Esempio n. 10
0
    def test_fetch_from_date(self):
        """Test whether a list of issues is returned from a given date"""

        from_date = str_to_datetime('2015-01-01')

        bodies_json = read_file('data/jira/jira_issues_page_2.json')

        body = read_file('data/jira/jira_fields.json')

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               body=bodies_json,
                               status=200)

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body,
                               status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch(from_date)]

        expected_req = {
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 1420070400000'],
            'startAt': ['0']
        }

        self.assertEqual(len(issues), 1)

        self.assertEqual(issues[0]['origin'], 'http://example.com')
        self.assertEqual(issues[0]['uuid'],
                         '2e988d555915991228d81144b018c8321d628265')
        self.assertEqual(issues[0]['updated_on'], 1457006245)
        self.assertEqual(issues[0]['category'], 'issue')
        self.assertEqual(issues[0]['tag'], 'http://example.com')

        request = httpretty.last_request()
        self.assertEqual(request.method, 'GET')
        self.assertRegex(request.path, '/rest/api/2/search')
        self.assertDictEqual(request.querystring, expected_req)
Esempio n. 11
0
    def test_fetch_from_date(self):
        """Test whether a list of issues is returned from a given date"""

        from_date = str_to_datetime('2015-01-01')

        bodies_json = read_file('data/jira/jira_issues_page_2.json')

        body = read_file('data/jira/jira_fields.json')

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               body=bodies_json, status=200)

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body, status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch(from_date)]

        expected_req = {
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 1420070400000 order by updated asc'],
                            'startAt': ['0']
                        }

        self.assertEqual(len(issues), 1)

        self.assertEqual(issues[0]['origin'], 'http://example.com')
        self.assertEqual(issues[0]['uuid'], '2e988d555915991228d81144b018c8321d628265')
        self.assertEqual(issues[0]['updated_on'], 1457006245)
        self.assertEqual(issues[0]['category'], 'issue')
        self.assertEqual(issues[0]['tag'], 'http://example.com')

        request = httpretty.last_request()
        self.assertEqual(request.method, 'GET')
        self.assertRegex(request.path, '/rest/api/2/search')
        self.assertDictEqual(request.querystring, expected_req)
Esempio n. 12
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Jira.has_resuming(), True)
Esempio n. 13
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Jira.has_resuming(), True)
Esempio n. 14
0
    def test_fetch(self):
        """Test whether a list of issues is returned"""

        requests = []

        bodies_json = [read_file('data/jira/jira_issues_page_1.json'),
                       read_file('data/jira/jira_issues_page_2.json')]

        body = read_file('data/jira/jira_fields.json')

        def request_callback(method, uri, headers):
            body = bodies_json.pop(0)
            requests.append(httpretty.last_request())
            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               responses=[httpretty.Response(body=request_callback) \
                                          for _ in range(2)])

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body, status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch()]

        body_json = json.loads(body)

        custom_fields = filter_custom_fields(body_json)

        expected_req = [{
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 0 order by updated asc'],
                            'startAt': ['0']
                        },
                        {
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 0 order by updated asc'],
                            'startAt': ['2']
                        }]

        for i in range(len(expected_req)):
            self.assertEqual(requests[i].method, 'GET')
            self.assertRegex(requests[i].path, '/rest/api/2/search')
            self.assertDictEqual(requests[i].querystring, expected_req[i])

        self.assertEqual(len(issues), 3)

        self.assertEqual(issues[0]['origin'], 'http://example.com')
        self.assertEqual(issues[0]['uuid'], 'dfe008e19e2b720d1d377607680e90c250134164')
        self.assertEqual(issues[0]['updated_on'], 1457015567)
        self.assertEqual(issues[0]['category'], 'issue')
        self.assertEqual(issues[0]['tag'], 'http://example.com')
        self.assertEqual(issues[0]['data']['key'], 'HELP-6043')
        self.assertEqual(issues[0]['data']['fields']['issuetype']['name'],  'extRequest')
        self.assertEqual(issues[0]['data']['fields']['creator']['name'], 'user2')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'], 'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'], 'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'], 'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'], 'user1')
        self.assertEqual(issues[0]['data']['fields']['customfield_10301']['id'],
                         custom_fields['customfield_10301']['id'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10301']['name'],
                         custom_fields['customfield_10301']['name'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10400']['id'],
                         custom_fields['customfield_10400']['id'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10400']['name'],
                         custom_fields['customfield_10400']['name'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10600']['id'],
                         custom_fields['customfield_10600']['id'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10600']['name'],
                         custom_fields['customfield_10600']['name'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10603']['id'],
                         custom_fields['customfield_10603']['id'])
        self.assertEqual(issues[0]['data']['fields']['customfield_10603']['name'],
                         custom_fields['customfield_10603']['name'])

        self.assertEqual(issues[1]['origin'], 'http://example.com')
        self.assertEqual(issues[1]['uuid'], '830747ed8cc9af800fcd6284e9dccfdb11daf15b')
        self.assertEqual(issues[1]['updated_on'], 1457015417)
        self.assertEqual(issues[1]['category'], 'issue')
        self.assertEqual(issues[1]['tag'], 'http://example.com')
        self.assertEqual(issues[1]['data']['key'], 'HELP-6042')
        self.assertEqual(issues[1]['data']['fields']['issuetype']['name'],  'extRequest')
        self.assertEqual(issues[1]['data']['fields']['creator']['name'], 'user2')
        self.assertEqual(issues[1]['data']['fields']['assignee']['name'], 'user1')
        self.assertEqual(issues[1]['data']['fields']['customfield_10301']['id'],
                         custom_fields['customfield_10301']['id'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10301']['name'],
                         custom_fields['customfield_10301']['name'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10400']['id'],
                         custom_fields['customfield_10400']['id'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10400']['name'],
                         custom_fields['customfield_10400']['name'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10600']['id'],
                         custom_fields['customfield_10600']['id'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10600']['name'],
                         custom_fields['customfield_10600']['name'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10603']['id'],
                         custom_fields['customfield_10603']['id'])
        self.assertEqual(issues[1]['data']['fields']['customfield_10603']['name'],
                         custom_fields['customfield_10603']['name'])

        self.assertEqual(issues[2]['origin'], 'http://example.com')
        self.assertEqual(issues[2]['uuid'], '2e988d555915991228d81144b018c8321d628265')
        self.assertEqual(issues[2]['updated_on'], 1457006245)
        self.assertEqual(issues[2]['category'], 'issue')
        self.assertEqual(issues[2]['tag'], 'http://example.com')
        self.assertEqual(issues[2]['data']['key'], 'HELP-6041')
        self.assertEqual(issues[2]['data']['fields']['issuetype']['name'],  'extRequest')
        self.assertEqual(issues[2]['data']['fields']['creator']['name'], 'user2')
        self.assertEqual(issues[2]['data']['fields']['assignee']['name'], 'user3')
        self.assertEqual(issues[2]['data']['fields']['customfield_10301']['id'],
                         custom_fields['customfield_10301']['id'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10301']['name'],
                         custom_fields['customfield_10301']['name'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10400']['id'],
                         custom_fields['customfield_10400']['id'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10400']['name'],
                         custom_fields['customfield_10400']['name'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10600']['id'],
                         custom_fields['customfield_10600']['id'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10600']['name'],
                         custom_fields['customfield_10600']['name'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10603']['id'],
                         custom_fields['customfield_10603']['id'])
        self.assertEqual(issues[2]['data']['fields']['customfield_10603']['name'],
                         custom_fields['customfield_10603']['name'])
Esempio n. 15
0
    def test_fetch_from_cache(self):
        """Test whether a list of issues is returned from cache"""

        requests = []

        bodies_json = [
            read_file('data/jira/jira_issues_page_1.json'),
            read_file('data/jira/jira_issues_page_2.json')
        ]

        body = read_file('data/jira/jira_fields.json')

        def request_callback(method, uri, headers):
            body = bodies_json.pop(0)
            requests.append(httpretty.last_request())
            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               responses=[httpretty.Response(body=request_callback) \
                                          for _ in range(2)])
        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body,
                               status=200)

        # First, we fetch the issues from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        jira = Jira(JIRA_SERVER_URL, cache=cache)

        issues = [issue for issue in jira.fetch()]
        del issues[0]['timestamp']

        # Now, we get the issues from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cache_issues = [cache_issue for cache_issue in jira.fetch_from_cache()]

        expected_req = [{
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 0'],
            'startAt': ['0']
        }, {
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 0'],
            'startAt': ['2']
        }]

        for i in range(len(expected_req)):
            self.assertEqual(requests[i].method, 'GET')
            self.assertRegex(requests[i].path, '/rest/api/2/search')
            self.assertDictEqual(requests[i].querystring, expected_req[i])

        self.assertEqual(len(issues), len(cache_issues))

        for i in range(len(cache_issues)):
            self.assertEqual(issues[i]['origin'], cache_issues[i]['origin'])
            self.assertEqual(issues[i]['uuid'], cache_issues[i]['uuid'])
            self.assertEqual(issues[i]['updated_on'],
                             cache_issues[i]['updated_on'])
            self.assertEqual(issues[i]['data']['key'],
                             cache_issues[i]['data']['key'])
            self.assertEqual(
                issues[i]['data']['fields']['issuetype']['name'],
                cache_issues[i]['data']['fields']['issuetype']['name'])
            self.assertEqual(
                issues[i]['data']['fields']['creator']['name'],
                cache_issues[i]['data']['fields']['creator']['name'])
            self.assertEqual(
                issues[i]['data']['fields']['assignee']['name'],
                cache_issues[i]['data']['fields']['assignee']['name'])
Esempio n. 16
0
    def test_fetch(self):
        """Test whether a list of issues is returned"""

        requests = []

        bodies_json = [
            read_file('data/jira/jira_issues_page_1.json'),
            read_file('data/jira/jira_issues_page_2.json')
        ]

        body = read_file('data/jira/jira_fields.json')

        def request_callback(method, uri, headers):
            body = bodies_json.pop(0)
            requests.append(httpretty.last_request())
            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               responses=[httpretty.Response(body=request_callback) \
                                          for _ in range(2)])

        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body,
                               status=200)

        jira = Jira(JIRA_SERVER_URL)

        issues = [issue for issue in jira.fetch()]

        body_json = json.loads(body)

        custom_fields = filter_custom_fields(body_json)

        expected_req = [{
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 0'],
            'startAt': ['0']
        }, {
            'expand': ['renderedFields,transitions,operations,changelog'],
            'jql': [' updated > 0'],
            'startAt': ['2']
        }]

        for i in range(len(expected_req)):
            self.assertEqual(requests[i].method, 'GET')
            self.assertRegex(requests[i].path, '/rest/api/2/search')
            self.assertDictEqual(requests[i].querystring, expected_req[i])

        self.assertEqual(len(issues), 3)

        self.assertEqual(issues[0]['origin'], 'http://example.com')
        self.assertEqual(issues[0]['uuid'],
                         'dfe008e19e2b720d1d377607680e90c250134164')
        self.assertEqual(issues[0]['updated_on'], 1457015567)
        self.assertEqual(issues[0]['data']['key'], 'HELP-6043')
        self.assertEqual(issues[0]['data']['fields']['issuetype']['name'],
                         'extRequest')
        self.assertEqual(issues[0]['data']['fields']['creator']['name'],
                         'user2')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'],
                         'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'],
                         'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'],
                         'user1')
        self.assertEqual(issues[0]['data']['fields']['assignee']['name'],
                         'user1')
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10301']['id'],
            custom_fields['customfield_10301']['id'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10301']['name'],
            custom_fields['customfield_10301']['name'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10400']['id'],
            custom_fields['customfield_10400']['id'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10400']['name'],
            custom_fields['customfield_10400']['name'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10600']['id'],
            custom_fields['customfield_10600']['id'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10600']['name'],
            custom_fields['customfield_10600']['name'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10603']['id'],
            custom_fields['customfield_10603']['id'])
        self.assertEqual(
            issues[0]['data']['fields']['customfield_10603']['name'],
            custom_fields['customfield_10603']['name'])

        self.assertEqual(issues[1]['origin'], 'http://example.com')
        self.assertEqual(issues[1]['uuid'],
                         '830747ed8cc9af800fcd6284e9dccfdb11daf15b')
        self.assertEqual(issues[1]['updated_on'], 1457015417)
        self.assertEqual(issues[1]['data']['key'], 'HELP-6042')
        self.assertEqual(issues[1]['data']['fields']['issuetype']['name'],
                         'extRequest')
        self.assertEqual(issues[1]['data']['fields']['creator']['name'],
                         'user2')
        self.assertEqual(issues[1]['data']['fields']['assignee']['name'],
                         'user1')
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10301']['id'],
            custom_fields['customfield_10301']['id'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10301']['name'],
            custom_fields['customfield_10301']['name'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10400']['id'],
            custom_fields['customfield_10400']['id'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10400']['name'],
            custom_fields['customfield_10400']['name'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10600']['id'],
            custom_fields['customfield_10600']['id'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10600']['name'],
            custom_fields['customfield_10600']['name'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10603']['id'],
            custom_fields['customfield_10603']['id'])
        self.assertEqual(
            issues[1]['data']['fields']['customfield_10603']['name'],
            custom_fields['customfield_10603']['name'])

        self.assertEqual(issues[2]['origin'], 'http://example.com')
        self.assertEqual(issues[2]['uuid'],
                         '2e988d555915991228d81144b018c8321d628265')
        self.assertEqual(issues[2]['updated_on'], 1457006245)
        self.assertEqual(issues[2]['data']['key'], 'HELP-6041')
        self.assertEqual(issues[2]['data']['fields']['issuetype']['name'],
                         'extRequest')
        self.assertEqual(issues[2]['data']['fields']['creator']['name'],
                         'user2')
        self.assertEqual(issues[2]['data']['fields']['assignee']['name'],
                         'user3')
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10301']['id'],
            custom_fields['customfield_10301']['id'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10301']['name'],
            custom_fields['customfield_10301']['name'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10400']['id'],
            custom_fields['customfield_10400']['id'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10400']['name'],
            custom_fields['customfield_10400']['name'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10600']['id'],
            custom_fields['customfield_10600']['id'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10600']['name'],
            custom_fields['customfield_10600']['name'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10603']['id'],
            custom_fields['customfield_10603']['id'])
        self.assertEqual(
            issues[2]['data']['fields']['customfield_10603']['name'],
            custom_fields['customfield_10603']['name'])
Esempio n. 17
0
    def test_fetch_from_cache(self):
        """Test whether a list of issues is returned from cache"""

        requests = []

        bodies_json = [read_file('data/jira/jira_issues_page_1.json'),
                       read_file('data/jira/jira_issues_page_2.json')]

        body = read_file('data/jira/jira_fields.json')

        def request_callback(method, uri, headers):
            body = bodies_json.pop(0)
            requests.append(httpretty.last_request())
            return (200, headers, body)

        httpretty.register_uri(httpretty.GET,
                               JIRA_SEARCH_URL,
                               responses=[httpretty.Response(body=request_callback) \
                                          for _ in range(2)])
        httpretty.register_uri(httpretty.GET,
                               JIRA_FIELDS_URL,
                               body=body, status=200)

        # First, we fetch the issues from the server, storing them
        # in a cache
        cache = Cache(self.tmp_path)
        jira = Jira(JIRA_SERVER_URL, cache=cache)

        issues = [issue for issue in jira.fetch()]
        del issues[0]['timestamp']

        # Now, we get the issues from the cache.
        # The contents should be the same and there won't be
        # any new request to the server
        cache_issues = [cache_issue for cache_issue in jira.fetch_from_cache()]

        expected_req = [{
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 0 order by updated asc'],
                            'startAt': ['0']
                        },
                        {
                            'expand': ['renderedFields,transitions,operations,changelog'],
                            'jql': ['updated > 0 order by updated asc'],
                            'startAt': ['2']
                        }]

        for i in range(len(expected_req)):
            self.assertEqual(requests[i].method, 'GET')
            self.assertRegex(requests[i].path, '/rest/api/2/search')
            self.assertDictEqual(requests[i].querystring, expected_req[i])

        self.assertEqual(len(issues), len(cache_issues))

        for i in range(len(cache_issues)):
            self.assertEqual(issues[i]['origin'], cache_issues[i]['origin'])
            self.assertEqual(issues[i]['uuid'], cache_issues[i]['uuid'])
            self.assertEqual(issues[i]['updated_on'], cache_issues[i]['updated_on'])
            self.assertEqual(issues[i]['category'], cache_issues[i]['category'])
            self.assertEqual(issues[1]['tag'], cache_issues[i]['tag'])
            self.assertEqual(issues[i]['data']['key'], cache_issues[i]['data']['key'])
            self.assertEqual(issues[i]['data']['fields']['issuetype']['name'],
                             cache_issues[i]['data']['fields']['issuetype']['name'])
            self.assertEqual(issues[i]['data']['fields']['creator']['name'],
                             cache_issues[i]['data']['fields']['creator']['name'])
            self.assertEqual(issues[i]['data']['fields']['assignee']['name'],
                             cache_issues[i]['data']['fields']['assignee']['name'])