Exemple #1
0
    def test_fetch_from_empty_cache(self):
        """Test if there are not any issue returned when the cache is empty"""

        cache = Cache(self.tmp_path)
        redmine = Redmine(REDMINE_URL, api_token='AAAA', cache=cache)
        cached_issues = [issue for issue in redmine.fetch_from_cache()]
        self.assertEqual(len(cached_issues), 0)
Exemple #2
0
    def test_fetch_from_non_set_cache(self):
        """Test if a error is raised when the cache was not set"""

        redmine = Redmine(REDMINE_URL, api_token='AAAA')

        with self.assertRaises(CacheError):
            _ = [issue for issue in redmine.fetch_from_cache()]
Exemple #3
0
    def test_fetch_from_date(self):
        """Test wether if fetches a set of issues from the given date"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 7, 27)

        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3)
        issues = [issue for issue in redmine.fetch(from_date=from_date)]

        self.assertEqual(len(issues), 1)

        issue = issues[0]
        self.assertEqual(issue['data']['id'], 7311)
        self.assertEqual(issue['uuid'], '4ab289ab60aee93a66e5490529799cf4a2b4d94c')
        self.assertEqual(issue['origin'], REDMINE_URL)
        self.assertEqual(issue['updated_on'], 1469607427.0)
        self.assertEqual(issue['category'], 'issue')
        self.assertEqual(issue['tag'], REDMINE_URL)
        self.assertEqual(issue['data']['author_data']['id'], 24)
        self.assertEqual(issue['data']['journals'][0]['user_data']['id'], 4)

        expected = [{
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=2016-07-27T00:00:00Z'],
                     'offset' : ['0'],
                     'limit' : ['3']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=2016-07-27T00:00:00Z'],
                     'offset' : ['3'],
                     'limit' : ['3']
                    }]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
Exemple #4
0
    def test_not_found_user(self):
        """Test if it works when a user is not found"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2016, 7, 27)

        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3)
        issues = [issue for issue in redmine.fetch(from_date=from_date)]

        self.assertEqual(len(issues), 1)

        # The user 99 does not have information
        self.assertEqual(issues[0]['data']['journals'][1]['user']['id'], 99)
        self.assertDictEqual(issues[0]['data']['journals'][1]['user_data'], {})
Exemple #5
0
    def test_fetch_from_cache(self):
        """Test whether the cache works"""

        http_requests = setup_http_server()

        # First, we fetch the issues from the server,
        # storing them in a cache
        cache = Cache(self.tmp_path)
        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3, cache=cache)

        issues = [issue for issue in redmine.fetch()]
        self.assertEqual(len(http_requests), 12)

        # Now, we get the issues from the cache.
        # The issues should be the same and there won't be
        # any new request to the server
        cached_issues = [issue for issue in redmine.fetch_from_cache()]
        self.assertEqual(len(cached_issues), len(issues))

        expected = [(9, '91a8349c2f6ebffcccc49409529c61cfd3825563', 1323367020.0, 3, 3),
                    (5, 'c4aeb9e77fec8e4679caa23d4012e7cc36ae8b98', 1323367075.0, 3, 3),
                    (2, '3c3d67925b108a37f88cc6663f7f7dd493fa818c', 1323367117.0, 3, 3),
                    (7311, '4ab289ab60aee93a66e5490529799cf4a2b4d94c', 1469607427.0, 24, 4)]

        self.assertEqual(len(cached_issues), len(expected))

        for x in range(len(cached_issues)):
            issue = cached_issues[x]
            expc = expected[x]
            self.assertEqual(issue['data']['id'], expc[0])
            self.assertEqual(issue['uuid'], expc[1])
            self.assertEqual(issue['origin'], REDMINE_URL)
            self.assertEqual(issue['updated_on'], expc[2])
            self.assertEqual(issue['category'], 'issue')
            self.assertEqual(issue['tag'], REDMINE_URL)
            self.assertEqual(issue['data']['author_data']['id'], expc[3])
            self.assertEqual(issue['data']['journals'][0]['user_data']['id'], expc[4])
            self.assertDictEqual(issue['data'], issues[x]['data'])

        # The user 99 does not have information
        self.assertEqual(issues[3]['data']['journals'][1]['user']['id'], 99)
        self.assertDictEqual(issues[3]['data']['journals'][1]['user_data'], {})

        # No more requests were sent
        self.assertEqual(len(http_requests), 12)
Exemple #6
0
    def test_parse_user_data(self):
        """"Test if it parses a user stream"""

        raw_json = read_file('data/redmine/redmine_user_3.json')

        user = Redmine.parse_user_data(raw_json)

        self.assertEqual(user['id'], 3)
        self.assertEqual(user['lastname'], 'User')
        self.assertEqual(user['login'], 'generic')
Exemple #7
0
    def test_parse_issue_data(self):
        """Test if it parses a issue stream"""

        raw_json = read_file('data/redmine/redmine_issue_7311.json')

        issue = Redmine.parse_issue_data(raw_json)

        self.assertEqual(issue['id'], 7311)
        self.assertEqual(len(issue['journals']), 22)
        self.assertEqual(len(issue['changesets']), 0)
Exemple #8
0
    def test_parse_issues(self):
        """Test if it parses a issues stream"""

        raw_json = read_file('data/redmine/redmine_issues.json')

        issues = Redmine.parse_issues(raw_json)
        results = [issue for issue in issues]

        self.assertEqual(len(results), 3)
        self.assertEqual(results[0]['id'], 9)
        self.assertEqual(results[1]['id'], 5)
        self.assertEqual(results[2]['id'], 2)

        # Parse a file without results
        raw_json = read_file('data/redmine/redmine_issues_empty.json')

        issues = Redmine.parse_issues(raw_json)
        results = [issue for issue in issues]

        self.assertEqual(len(results), 0)
Exemple #9
0
    def test_fetch_empty(self):
        """Test if nothing is returnerd when there are no issues"""

        http_requests = setup_http_server()

        from_date = datetime.datetime(2017, 1, 1)

        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3)
        issues = [issue for issue in redmine.fetch(from_date=from_date)]

        self.assertEqual(len(issues), 0)

        expected = {
                    'key' : ['AAAA'],
                    'status_id' : ['*'],
                    'sort' : ['updated_on'],
                    'updated_on' : ['>=2017-01-01T00:00:00Z'],
                    'offset' : ['0'],
                    'limit' : ['3']
                   }

        self.assertEqual(len(http_requests), 1)
        self.assertDictEqual(http_requests[0].querystring, expected)
Exemple #10
0
    def test_fetch(self):
        """Test whether it fetches a set of issues"""

        http_requests = setup_http_server()

        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3)
        issues = [issue for issue in redmine.fetch()]

        expected = [(9, '91a8349c2f6ebffcccc49409529c61cfd3825563', 1323367020.0, 3, 3),
                    (5, 'c4aeb9e77fec8e4679caa23d4012e7cc36ae8b98', 1323367075.0, 3, 3),
                    (2, '3c3d67925b108a37f88cc6663f7f7dd493fa818c', 1323367117.0, 3, 3),
                    (7311, '4ab289ab60aee93a66e5490529799cf4a2b4d94c', 1469607427.0, 24, 4)]

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

        for x in range(len(issues)):
            issue = issues[x]
            expc = expected[x]
            self.assertEqual(issue['data']['id'], expc[0])
            self.assertEqual(issue['uuid'], expc[1])
            self.assertEqual(issue['origin'], REDMINE_URL)
            self.assertEqual(issue['updated_on'], expc[2])
            self.assertEqual(issue['category'], 'issue')
            self.assertEqual(issue['tag'], REDMINE_URL)
            self.assertEqual(issue['data']['author_data']['id'], expc[3])
            self.assertEqual(issue['data']['journals'][0]['user_data']['id'], expc[4])

        # Check requests
        expected = [{
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['0'],
                     'limit' : ['3']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['3'],
                     'limit' : ['3']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA']
                    },
                    {
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['6'],
                     'limit' : ['3']
                    }]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])
Exemple #11
0
    def test_has_resuming(self):
        """Test if it returns True when has_resuming is called"""

        self.assertEqual(Redmine.has_resuming(), True)
Exemple #12
0
    def test_has_caching(self):
        """Test if it returns True when has_caching is called"""

        self.assertEqual(Redmine.has_caching(), True)
    def test_fetch(self):
        """Test whether it fetches a set of issues"""

        http_requests = setup_http_server()

        redmine = Redmine(REDMINE_URL, api_token='AAAA',
                          max_issues=3)
        issues = [issue for issue in redmine.fetch()]

        expected = [(9, '91a8349c2f6ebffcccc49409529c61cfd3825563', 1323367020.0),
                    (5, 'c4aeb9e77fec8e4679caa23d4012e7cc36ae8b98', 1323367075.0),
                    (2, '3c3d67925b108a37f88cc6663f7f7dd493fa818c', 1323367117.0),
                    (7311, '4ab289ab60aee93a66e5490529799cf4a2b4d94c', 1469607427.0)]

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

        for x in range(len(issues)):
            issue = issues[x]
            expc = expected[x]
            self.assertEqual(issue['data']['id'], expc[0])
            self.assertEqual(issue['uuid'], expc[1])
            self.assertEqual(issue['updated_on'], expc[2])

        # Check requests
        expected = [{
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['0'],
                     'limit' : ['3']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['3'],
                     'limit' : ['3']
                    },
                    {
                     'key' : ['AAAA'],
                     'include' : ['attachments,changesets,children,journals,relations,watchers']
                    },
                    {
                     'key' : ['AAAA'],
                     'status_id' : ['*'],
                     'sort' : ['updated_on'],
                     'updated_on' : ['>=1970-01-01T00:00:00Z'],
                     'offset' : ['6'],
                     'limit' : ['3']
                    }]

        self.assertEqual(len(http_requests), len(expected))

        for i in range(len(expected)):
            self.assertDictEqual(http_requests[i].querystring, expected[i])