def test_add_nipsa_does_not_add_when_user_already_exists(NipsaUser): """ add_nipsa() should not call db.add() if the user already exists. """ request = mock.Mock() nipsa_user = mock.Mock() NipsaUser.get_by_userid.return_value = nipsa_user logic.add_nipsa(request=request, userid="test_id") assert not request.db.add.called
def test_add_nipsa_adds_user_if_user_does_not_exist(NipsaUser): request = mock.Mock() nipsa_user = mock.Mock() NipsaUser.return_value = nipsa_user NipsaUser.get_by_userid.return_value = None logic.add_nipsa(request=request, userid="test_id") NipsaUser.assert_called_once_with("test_id") request.db.add.assert_called_once_with(nipsa_user)
def test_add_nipsa_schedules_task_if_user_does_not_exist(NipsaUser, worker): request = mock.Mock() nipsa_user = mock.Mock() nipsa_user.userid = "test_id" NipsaUser.return_value = nipsa_user NipsaUser.get_by_userid.return_value = None logic.add_nipsa(request=request, userid="test_id") worker.add_nipsa.delay.assert_called_once_with("test_id")
def test_add_nipsa_publishes_if_user_does_not_exist(NipsaUser, _publish): request = mock.Mock() nipsa_user = mock.Mock() nipsa_user.userid = "test_id" NipsaUser.return_value = nipsa_user NipsaUser.get_by_userid.return_value = None logic.add_nipsa(request=request, userid="test_id") _publish.assert_called_once_with( request, json.dumps({"action": "add_nipsa", "userid": "test_id"}))
def test_add_nipsa_schedules_task_when_user_already_exists(NipsaUser, worker): """ Even if the user is already NIPSA'd, add_nipsa() should still schedule an "add_nipsa" task. """ nipsa_user = mock.Mock() NipsaUser.get_by_userid.return_value = nipsa_user request = mock.Mock() logic.add_nipsa(request=request, userid="test_id") worker.add_nipsa.delay.assert_called_once_with("test_id") NipsaUser.get_by_userid.assert_called_once_with("test_id")
def test_add_nipsa_publishes_when_user_already_exists( NipsaUser, _publish): """ Even if the user is already NIPSA'd, add_nipsa() should still publish an "add_nipsa" message to the queue. """ nipsa_user = mock.Mock() NipsaUser.get_by_userid.return_value = nipsa_user request = mock.Mock() logic.add_nipsa(request=request, userid="test_id") _publish.assert_called_once_with( request, json.dumps({"action": "add_nipsa", "userid": "test_id"})) NipsaUser.get_by_userid.assert_called_once_with("test_id")
def test_add_nipsa_gets_user_by_id(NipsaUser): logic.add_nipsa(request=mock.Mock(), userid="test_id") NipsaUser.get_by_userid.assert_called_once_with("test_id")