Пример #1
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
Пример #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_id.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_id.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_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)
Пример #5
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_id.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"}))
Пример #6
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_id.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_id.assert_called_once_with("test_id")
Пример #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_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")
Пример #9
0
def test_add_nipsa_gets_user_by_id(NipsaUser):
    logic.add_nipsa(request=mock.Mock(), userid="test_id")

    NipsaUser.get_by_id.assert_called_once_with("test_id")
Пример #10
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")