Esempio n. 1
0
    def test_login_raises(self, monkeypatch):
        """Tests that an error is raised if the _login method was
        unsuccessful."""
        dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL)

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

        with pytest.raises(RequestFailedError,
                           match="Failed to get access token"):
            dev._login()
Esempio n. 2
0
    def test_login(self, monkeypatch):
        """Tests that an access token and a refresh token are returned if the
        _login method was successful."""
        dev = HQSDevice(3, machine=DUMMY_MACHINE, user_email=DUMMY_EMAIL)

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

        access_token, refresh_token = dev._login()
        assert access_token == MOCK_ACCESS_TOKEN
        assert refresh_token == MOCK_REFRESH_TOKEN