def test_login(self, mock_save, mock_input, mock_open): old_refresh_token = "123" refresh_token = "456" access_token = "abc" expires_at = 1000.0 mock_input.return_value = old_refresh_token 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() mock_open.assert_called_with('%s/login' % command.QUILT_PKG_URL) 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(self, mock_login_with_token, mock_input, mock_open): old_refresh_token = "123" mock_input.return_value = old_refresh_token command.login() mock_open.assert_called_with('%s/login' % command.get_registry_url()) mock_login_with_token.assert_called_with(old_refresh_token)
def test_login(self, mock_login_with_token, mock_input, mock_open): old_refresh_token = "123" mock_input.return_value = old_refresh_token command.login() mock_open.assert_called_with('%s/login' % command.QUILT_PKG_URL) mock_login_with_token.assert_called_with(old_refresh_token)
def test_login_auth_fail(self, mock_save, mock_input, mock_open): mock_input.return_value = "123" self.requests_mock.add(responses.POST, '%s/api/token' % command.QUILT_PKG_URL, json=dict(status=200, error="Bad token!")) with self.assertRaises(command.CommandException): command.login() mock_save.assert_not_called()
def test_login_server_error(self, mock_save, mock_input, mock_open): mock_input.return_value = "123" self.requests_mock.add(responses.POST, '%s/api/token' % command.QUILT_PKG_URL, status=500) with self.assertRaises(command.CommandException): command.login() mock_save.assert_not_called()
def test_login_invalid_team(self, mock_login_with_token, mock_input, mock_open): old_refresh_token = "123" mock_input.return_value = old_refresh_token with pytest.raises(command.CommandException, match='Invalid team name'): command.login('fo!o') assert not mock_open.called assert not mock_login_with_token.called
def test_login(self, mock_save, mock_input, mock_open): mock_input.return_value = "123" responses.add(responses.POST, '%s/api/token' % command.QUILT_PKG_URL, json=dict(statuc=200, refresh_token="456", access_token="abc", expires_at=1000.0)) command.login(Namespace()) mock_open.assert_called_with('%s/login' % command.QUILT_PKG_URL) assert responses.calls[0].request.body == "refresh_token=123" mock_save.assert_called_with( dict(refresh_token="456", access_token="abc", expires_at=1000.0))
def test_login_not_allowed(self, mock_open, mock_load, mock_save): # Already logged is as a public user. mock_load.return_value = { command.get_registry_url(None): dict(team=None) } # Normal login is ok. command.login(None) mock_open.reset_mock() mock_save.reset_mock() # Team login is not allowed. with self.assertRaises(command.CommandException): command.login('foo') mock_open.assert_not_called() mock_save.assert_not_called() # Already logged is as a team user. mock_load.return_value = { command.get_registry_url('foo'): dict(team='foo') } # Normal login is not allowed. with self.assertRaises(command.CommandException): command.login(None) # Login as 'foo' is ok. command.login('foo') mock_open.reset_mock() mock_save.reset_mock() # Login as a different team is not allowed. with self.assertRaises(command.CommandException): command.login('bar') mock_open.assert_not_called() mock_save.assert_not_called()