示例#1
0
文件: logic_test.py 项目: ackermann/h
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
示例#2
0
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
示例#3
0
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)
示例#4
0
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")
示例#5
0
文件: logic_test.py 项目: ackermann/h
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")
示例#6
0
文件: logic_test.py 项目: ackermann/h
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)
示例#7
0
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"}))
示例#8
0
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")
示例#9
0
文件: logic_test.py 项目: ackermann/h
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")
示例#10
0
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")
示例#11
0
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")
示例#12
0
文件: logic_test.py 项目: ackermann/h
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")