def test_login_token(self, mock_save): old_refresh_token = "123" refresh_token = "456" access_token = "abc" expires_at = 1000.0 self.requests_mock.add(responses.POST, '%s/api/token' % command.get_registry_url(None), json=dict(status=200, refresh_token=refresh_token, access_token=access_token, expires_at=expires_at)) command.login_with_token(None, old_refresh_token) assert self.requests_mock.calls[ 0].request.body == "refresh_token=%s" % old_refresh_token mock_save.assert_called_with({ command.get_registry_url(None): dict(team=None, refresh_token=refresh_token, access_token=access_token, expires_at=expires_at) })
def test_login_token_server_error(self, mock_save): self.requests_mock.add(responses.POST, '%s/api/token' % command.get_registry_url(), status=500) with self.assertRaises(command.CommandException): command.login_with_token("123") mock_save.assert_not_called()
def test_login_token_auth_fail(self, mock_save): self.requests_mock.add(responses.POST, '%s/api/token' % command.get_registry_url(), json=dict(status=200, error="Bad token!")) with self.assertRaises(command.CommandException): command.login_with_token("123") mock_save.assert_not_called()
def test_login_token(self, mock_save): old_refresh_token = "123" refresh_token = "456" access_token = "abc" expires_at = 1000.0 self.requests_mock.add(responses.POST, '%s/api/token' % command.QUILT_PKG_URL, json=dict(status=200, refresh_token=refresh_token, access_token=access_token, expires_at=expires_at)) command.login_with_token(old_refresh_token) assert self.requests_mock.calls[ 0].request.body == "refresh_token=%s" % old_refresh_token mock_save.assert_called_with( dict(refresh_token=refresh_token, access_token=access_token, expires_at=expires_at))
def test_login_with_token_invalid_team(self): with pytest.raises(command.CommandException, match='Invalid team name'): command.login_with_token('fo!o', '123')