Beispiel #1
0
    def test_raise_if_error(self) -> None:
        """
        Tests of the method which actually raises the exception when the
        API response is an error.
        """

        given = {
            "@type": "error",
            "error_type": "not_found",
            "error_message": "repository not found (or insufficient access)",
            "resource_type": "repository",
        }

        fake_response = requests.Response()
        fake_response.url = "https://example.org"

        self.assertRaises(
            TravisCIError,
            lambda: Requester.raise_if_error(fake_response, given))
Beispiel #2
0
    def test_raise_if_error_not_error(self) -> None:
        """
        Tests of the method which actually raises the exception when the
        API response is an error, but for the case that no error
        is given (in the api_response)
        """

        given = {
            "@type": "user",
            "@href": "/user/4549848944894848948949",
            "@representation": "standard",
            "@permissions": {
                "read": True,
                "sync": True
            },
            "id": 4549848944894848948949,
            "login": "******",
            "name": "Foo Bar",
            "github_id": 1148942198798789784897949849484523106,
            "vcs_id": "1148942198798789784897949849484523106",
            "vcs_type": "GithubUser",
            "avatar_url": None,
            "education": False,
            "allow_migration": False,
            "email": "*****@*****.**",
            "is_syncing": False,
            "synced_at": "2020-10-14T14:53:08Z",
            "recently_signed_up": False,
            "secure_user_hash": None,
        }
        expected = None

        fake_response = requests.Response()
        fake_response.url = "https://example.org"

        actual = Requester.raise_if_error(fake_response, given)

        self.assertEqual(expected, actual)