Beispiel #1
0
    def test_http_wrong_status(self):
        """Test if an error is raised when the http status was not 200"""

        issue = ""

        httpretty.register_uri(httpretty.GET,
                               PAGURE_ISSUES_URL,
                               body=issue,
                               status=501,
                               )

        client = PagureClient(namespace=None, repository="Project-example", token="aaa", sleep_time=1, max_retries=1)

        with self.assertRaises(requests.exceptions.HTTPError):
            _ = [issues for issues in client.issues()]

        # Check requests
        expected = {
            'status': ['all'],
            'per_page': ['100'],
            'order': ['asc']
        }

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"], "token aaa")
Beispiel #2
0
    def test_get_from_date_issues(self):
        """Test issues from date API call"""

        issues = read_file('data/pagure/pagure_repo_issue_from_2020_03_07')

        httpretty.register_uri(httpretty.GET,
                               PAGURE_ISSUES_URL,
                               body=issues,
                               status=200,
                               )

        from_date = datetime.datetime(2020, 3, 7)
        client = PagureClient(namespace=None, repository='Project-example', token='aaa')

        raw_issues = [issues for issues in client.issues(from_date=from_date)]
        self.assertEqual(raw_issues[0], issues)

        # Check requests
        expected = {
            'status': ['all'],
            'per_page': ['100'],
            'order': ['asc'],
            'since': ['2020-03-07 00:00:00']
        }
        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"], "token aaa")
    def test_get_empty_issues(self):
        """Test when issue is empty API call"""

        issue = read_file('data/pagure/pagure_empty_request')

        httpretty.register_uri(
            httpretty.GET,
            PAGURE_ISSUES_URL,
            body=issue,
            status=200,
        )

        client = PagureClient(namespace=None,
                              repository="Project-example",
                              token="aaa")

        raw_issues = [issues for issues in client.issues()]
        self.assertEqual(raw_issues[0], issue)

        # Check requests
        expected = {'status': ['all'], 'per_page': ['100'], 'order': ['asc']}

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"],
                         "token aaa")
    def test_get_page_issues(self):
        """Test issues pagination API call"""

        issue_1 = read_file('data/pagure/pagure_repo_issue_1')
        issue_2 = read_file('data/pagure/pagure_repo_only_issue_2')

        httpretty.register_uri(
            httpretty.GET,
            PAGURE_ISSUES_URL,
            body=issue_1,
            status=200,
            forcing_headers={
                'Link':
                '<' + PAGURE_ISSUES_URL + '/?&page=2>; rel="next", <' +
                PAGURE_ISSUES_URL + '/?&page=3>; rel="last"'
            })
        httpretty.register_uri(
            httpretty.GET,
            PAGURE_ISSUES_URL + '/?&page=2',
            body=issue_2,
            status=200,
        )

        client = PagureClient(namespace=None,
                              repository="Project-example",
                              token="aaa")

        issues = [issues for issues in client.issues()]

        self.assertEqual(len(issues), 2)
        self.assertEqual(issues[0], issue_1)
        self.assertEqual(issues[1], issue_2)

        # Check requests
        expected = {
            'status': ['all'],
            'page': ['2'],
            'per_page': ['100'],
            'order': ['asc']
        }

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertEqual(httpretty.last_request().headers["Authorization"],
                         "token aaa")
    def test_namespace_issues(self):
        """Test fetching issues from a repository within a namespace"""

        issue = read_file('data/pagure/pagure_namespace_issue_2')

        httpretty.register_uri(httpretty.GET,
                               PAGURE_NAMESPACE_ISSUES_URL,
                               body=issue,
                               status=200)

        client = PagureClient(namespace='Test-group',
                              repository='Project-namespace-example',
                              token=None)

        raw_issues = [issues for issues in client.issues()]
        self.assertEqual(raw_issues[0], issue)

        # Check requests
        expected = {'status': ['all'], 'per_page': ['100'], 'order': ['asc']}

        self.assertDictEqual(httpretty.last_request().querystring, expected)
        self.assertIsNone(httpretty.last_request().headers["Authorization"])