Beispiel #1
0
    def test_refresh_access_token_raises_for_expired(self, monkeypatch, code):
        """Tests that _refresh_access_token raises an error for an
        expired refresh token."""
        dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL)

        class MockResponseForExpired:
            def __init__(self):

                self.status_code = code
                self.mock_post_response = {
                    "status_code": str(code),
                    "code": "Not 200",
                    "detail": "Mock error for refresh.",
                    "meta": "Something went wrong.",
                }

            def json(self):
                return self.mock_post_response

        mock_response = MockResponseForExpired()
        monkeypatch.setattr(requests, "post",
                            lambda *args, **kwargs: mock_response)

        with pytest.raises(ExpiredRefreshTokenError,
                           match="Invalid refresh token was used."):
            dev._refresh_access_token()
Beispiel #2
0
    def test_refresh_access_token_raises(self, monkeypatch):
        """Tests that _refresh_access_token raises an error for a
        unsuccessful request."""
        dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL)

        mock_response = MockResponseUnsuccessfulRequest()
        monkeypatch.setattr(requests, "post",
                            lambda *args, **kwargs: mock_response)

        with pytest.raises(RequestFailedError,
                           match="Failed to get access token"):
            dev._refresh_access_token()
Beispiel #3
0
    def test_refresh_access_token(self, monkeypatch):
        """Tests that _refresh_access_token returns an access token for a
        successful request."""
        dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL)

        mock_response = MockResponseWithTokens()
        monkeypatch.setattr(requests, "post",
                            lambda *args, **kwargs: mock_response)

        access_token = dev._refresh_access_token()
        assert access_token == MOCK_ACCESS_TOKEN