Exemplo n.º 1
0
    def test_compare_commits_no_start(self):
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/xyz' % self.gitlab_id,
            json={'created_at': '2018-09-19T13:14:15Z'}
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits?until=2018-09-19T13:14:15Z' % self.gitlab_id,
            json=json.loads(COMMIT_LIST_RESPONSE)
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/ed899a2f4b50b4370feeea94676502b42383c746/diff' % self.gitlab_id,
            json=json.loads(COMMIT_DIFF_RESPONSE)
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff' % self.gitlab_id,
            json=json.loads(COMMIT_DIFF_RESPONSE)
        )

        response = self.create_repository(self.default_repository_config,
                                          self.integration.id)
        repo = Repository.objects.get(pk=response.data['id'])
        commits = self.provider.compare_commits(repo, None, 'xyz')
        for commit in commits:
            assert_commit_shape(commit)
Exemplo n.º 2
0
 def test_compare_commits_start_and_end(self):
     responses.add(
         responses.GET,
         "https://example.gitlab.com/api/v4/projects/%s/repository/compare?from=abc&to=xyz"
         % self.gitlab_id,
         json=json.loads(COMPARE_RESPONSE),
     )
     responses.add(
         responses.GET,
         "https://example.gitlab.com/api/v4/projects/%s/repository/commits/12d65c8dd2b2676fa3ac47d955accc085a37a9c1/diff"
         % self.gitlab_id,
         json=json.loads(COMMIT_DIFF_RESPONSE),
     )
     responses.add(
         responses.GET,
         "https://example.gitlab.com/api/v4/projects/%s/repository/commits/8b090c1b79a14f2bd9e8a738f717824ff53aebad/diff"
         % self.gitlab_id,
         json=json.loads(COMMIT_DIFF_RESPONSE),
     )
     response = self.create_repository(self.default_repository_config,
                                       self.integration.id)
     repo = Repository.objects.get(pk=response.data["id"])
     commits = self.provider.compare_commits(repo, "abc", "xyz")
     assert 2 == len(commits)
     for commit in commits:
         assert_commit_shape(commit)
Exemplo n.º 3
0
    def test_compare_commits_no_start(self):
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/xyz' % self.gitlab_id,
            json={'created_at': '2018-09-19T13:14:15Z'}
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits?until=2018-09-19T13:14:15Z' % self.gitlab_id,
            json=json.loads(COMMIT_LIST_RESPONSE)
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/ed899a2f4b50b4370feeea94676502b42383c746/diff' % self.gitlab_id,
            json=json.loads(COMMIT_DIFF_RESPONSE)
        )
        responses.add(
            responses.GET,
            'https://example.gitlab.com/api/v4/projects/%s/repository/commits/6104942438c14ec7bd21c6cd5bd995272b3faff6/diff' % self.gitlab_id,
            json=json.loads(COMMIT_DIFF_RESPONSE)
        )

        response = self.create_repository(self.default_repository_config,
                                          self.integration.id)
        repo = Repository.objects.get(pk=response.data['id'])
        commits = self.provider.compare_commits(repo, None, 'xyz')
        for commit in commits:
            assert_commit_shape(commit)
Exemplo n.º 4
0
 def test_compare_commits_no_start(self, get_jwt):
     stub_installation_token()
     responses.add(
         responses.GET,
         'https://api.github.com/repos/getsentry/example-repo/commits?sha=abcdef',
         json=json.loads(GET_LAST_COMMITS_EXAMPLE))
     responses.add(
         responses.GET,
         'https://api.github.com/repos/getsentry/example-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e',
         json=json.loads(GET_COMMIT_EXAMPLE))
     result = self.provider.compare_commits(self.repository, None, 'abcdef')
     for commit in result:
         assert_commit_shape(commit)
Exemplo n.º 5
0
    def test_compare_commits_force_refresh(self, get_jwt):
        stub_installation_token()
        ten_hours = datetime.datetime.utcnow() + datetime.timedelta(hours=10)
        self.integration.metadata = {
            "access_token": "old-access-token",
            "expires_at": ten_hours.replace(microsecond=0).isoformat(),
        }
        self.integration.save()
        responses.add(
            responses.GET,
            "https://api.github.com/repos/getsentry/example-repo/compare/xyz123...abcdef",
            status=404,
            body="GitHub returned a 404 Not Found error.",
        )
        responses.add(
            responses.GET,
            "https://api.github.com/repos/getsentry/example-repo/compare/xyz123...abcdef",
            json=json.loads(COMPARE_COMMITS_EXAMPLE),
        )
        responses.add(
            responses.GET,
            "https://api.github.com/repos/getsentry/example-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
            json=json.loads(GET_COMMIT_EXAMPLE),
        )

        result = self.provider.compare_commits(self.repository, "xyz123", "abcdef")
        for commit in result:
            assert_commit_shape(commit)

        # assert token was refreshed
        assert (
            Integration.objects.get(id=self.integration.id).metadata["access_token"]
            == "v1.install-token"
        )

        # compare_commits gives 400, token was refreshed, and compare_commits gives 200
        assert (
            responses.calls[0].response.url
            == "https://api.github.com/repos/getsentry/example-repo/compare/xyz123...abcdef"
        )
        assert responses.calls[0].response.status_code == 404
        assert (
            responses.calls[1].response.url
            == "https://api.github.com/app/installations/654321/access_tokens"
        )
        assert responses.calls[1].response.status_code == 200
        assert (
            responses.calls[2].response.url
            == "https://api.github.com/repos/getsentry/example-repo/compare/xyz123...abcdef"
        )
        assert responses.calls[2].response.status_code == 200
Exemplo n.º 6
0
 def test_compare_commits(self, get_jwt):
     stub_installation_token()
     responses.add(
         responses.GET,
         "https://api.github.com/repos/getsentry/example-repo/compare/xyz123...abcdef",
         json=json.loads(COMPARE_COMMITS_EXAMPLE),
     )
     responses.add(
         responses.GET,
         "https://api.github.com/repos/getsentry/example-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e",
         json=json.loads(GET_COMMIT_EXAMPLE),
     )
     result = self.provider.compare_commits(self.repository, "xyz123", "abcdef")
     for commit in result:
         assert_commit_shape(commit)
Exemplo n.º 7
0
 def test_compare_commits_no_start(self):
     stub_installation_token()
     responses.add(
         responses.GET,
         'https://api.github.com/repos/getsentry/example-repo/commits?sha=abcdef',
         json=json.loads(GET_LAST_COMMITS_EXAMPLE)
     )
     responses.add(
         responses.GET,
         'https://api.github.com/repos/getsentry/example-repo/commits/6dcb09b5b57875f334f61aebed695e2e4193db5e',
         json=json.loads(GET_COMMIT_EXAMPLE)
     )
     result = self.provider.compare_commits(self.repository, None, 'abcdef')
     for commit in result:
         assert_commit_shape(commit)
Exemplo n.º 8
0
 def test_compare_commits_start_and_end(self):
     responses.add(
         responses.GET,
         'https://example.gitlab.com/api/v4/projects/%s/repository/compare?from=abc&to=xyz' % self.gitlab_id,
         json=json.loads(COMPARE_RESPONSE)
     )
     responses.add(
         responses.GET,
         'https://example.gitlab.com/api/v4/projects/%s/repository/commits/12d65c8dd2b2676fa3ac47d955accc085a37a9c1/diff' % self.gitlab_id,
         json=json.loads(COMMIT_DIFF_RESPONSE)
     )
     responses.add(
         responses.GET,
         'https://example.gitlab.com/api/v4/projects/%s/repository/commits/8b090c1b79a14f2bd9e8a738f717824ff53aebad/diff' % self.gitlab_id,
         json=json.loads(COMMIT_DIFF_RESPONSE)
     )
     response = self.create_repository(self.default_repository_config,
                                       self.integration.id)
     repo = Repository.objects.get(pk=response.data['id'])
     commits = self.provider.compare_commits(repo, 'abc', 'xyz')
     assert 2 == len(commits)
     for commit in commits:
         assert_commit_shape(commit)