← Back to team overview

launchpad-reviewers team mailing list archive

Re: [Merge] ~ilasc/launchpad:revision-status-submission-api into launchpad:master

 


Diff comments:

> diff --git a/lib/lp/code/model/tests/test_gitrepository.py b/lib/lp/code/model/tests/test_gitrepository.py
> index a832554..3c99c17 100644
> --- a/lib/lp/code/model/tests/test_gitrepository.py
> +++ b/lib/lp/code/model/tests/test_gitrepository.py
> @@ -4200,6 +4208,44 @@ class TestGitRepositoryWebservice(TestCaseWithFactory):
>              self.assertEqual(
>                  InformationType.PUBLIC, repository_db.information_type)
>  
> +    def test_newRevisionStatusReport(self):
> +        repository = self.factory.makeGitRepository()
> +        requester = repository.owner
> +        with person_logged_in(requester):
> +            repository_url = api_url(repository)
> +        webservice = webservice_for_person(
> +            requester, permission=OAuthPermission.WRITE_PUBLIC,
> +            default_api_version="devel")
> +        response = webservice.named_post(
> +            repository_url, "issueAccessToken", description="Test token",
> +            scopes=["repository:build_status"])
> +        self.assertEqual(200, response.status)
> +        secret = response.jsonBody()
> +        with person_logged_in(requester):
> +            token = getUtility(IAccessTokenSet).getBySecret(secret)
> +            self.assertThat(token, MatchesStructure(
> +                owner=Equals(requester),
> +                description=Equals("Test token"),
> +                target=Equals(repository),
> +                scopes=Equals([AccessTokenScope.REPOSITORY_BUILD_STATUS]),
> +                date_expires=Is(None)))

This test can probably assume that `issueAccessToken` works rather than needing to specifically make assertions about the resulting token structure.

For the same reason, I'd also be inclined to use `secret, _ = self.factory.makeAccessToken(owner=requester, target=repository, scopes=[AccessTokenScope.REPOSITORY_BUILD_STATUS])` rather than creating the token using the API.  It'll be faster that way, and it's more consistent with the fact that we normally do test setup using factory methods and only call the actual thing we're testing at the moment via the webservice.

> +        # Use the token to create a new Status Report
> +        with person_logged_in(requester):
> +            repository_url = api_url(repository)
> +        webservice = webservice_for_person(
> +            requester, permission=OAuthPermission.WRITE_PRIVATE,
> +            default_api_version="devel")
> +
> +        # header = "Authorization: Token %s" % token
> +        header = {'Authorization-type': 'Token %s' % token}
> +        response = webservice.named_post(
> +            repository_url, "newRevisionStatusReport",
> +            headers=header, name="CI", status="Queued",
> +            description="120/120 tests passed",
> +            commit_sha1='823748ur9804376', result='Success')
> +
> +        self.assertEqual(200, response.status)
> +
>      def test_set_target(self):
>          # The repository owner can move the repository to another target;
>          # this redirects to the new location.


-- 
https://code.launchpad.net/~ilasc/launchpad/+git/launchpad/+merge/410373
Your team Launchpad code reviewers is requested to review the proposed merge of ~ilasc/launchpad:revision-status-submission-api into launchpad:master.



References