Ejemplo n.º 1
0
def test_register(mocker):
    mocker.patch('accounts.cqrs.make_password', lambda p: 'encoded_s3cr3t')
    mocker.patch.object(app, 'genuuid', lambda: 'ACTIVATION_TOKEN')
    app.register(email='*****@*****.**', password='******')

    assert Event.objects.count() == 1
    event = Event.objects.all().get()

    assert event.revision == 2
Ejemplo n.º 2
0
def test_iter_all_events():
    events = [
        app.register(email='*****@*****.**', password='******'),
        app.register(email='*****@*****.**', password='******'),
        app.register(email='*****@*****.**', password='******'),
    ]

    assert inspect.isgenerator(app.storage.iter_all_events()) is True
    assert list(app.storage.iter_all_events()) == events
Ejemplo n.º 3
0
def test_obtain_auth_token(mocker):
    event = app.register(email='*****@*****.**', password='******')
    app.activate(event.aggregate_id)

    mocker.patch.object(app, 'genuuid', lambda: 'AUTH_TOKEN')
    event = app.obtain_auth_token(event.aggregate_id)
    assert event.data['auth_token'] == 'AUTH_TOKEN'
Ejemplo n.º 4
0
def test_register(mocker):
    mocker.patch('accounts.cqrs.make_password', lambda p: 'encoded_s3cr3t')
    mocker.patch.object(app, 'genuuid', lambda: 'ACTIVATION_TOKEN')
    event = app.register(email='*****@*****.**', password='******')
    assert event.data == {
        'email': '*****@*****.**',
        'encoded_password': '******',
        'activation_token': 'ACTIVATION_TOKEN',
        'role': 'user',
    }
Ejemplo n.º 5
0
def test_auth_required_user_inactive(arf):
    user_id = app.register('*****@*****.**', 'secret').aggregate_id
    app.activate(user_id)
    event = app.obtain_auth_token(user_id)
    app.inactivate(user_id)

    request = arf.get('/api/auth/ping', token=event.data['auth_token'])

    @api_view(['GET'])
    @permission_classes([IsAuthenticated])
    def ping(request):
        assert request.user is None
        return Response({'msg': 'Pong!'})

    response = ping(request)
    assert response.status_code == 401
Ejemplo n.º 6
0
def test_obtain_auth_token__inactive_user():
    event = app.register(email='*****@*****.**', password='******')

    with pytest.raises(AssertionError):
        app.obtain_auth_token(event.aggregate_id)
Ejemplo n.º 7
0
def test_activate_with_token__fails_for_already_active_members(mocker):
    event = app.register(email='*****@*****.**', password='******')
    app.activate(event.aggregate_id)
    user = app.users.get_aggregate(event.aggregate_id)
    with pytest.raises(AssertionError):
        app.activate_with_token(user.id, user.activation_token)
Ejemplo n.º 8
0
def test_activate_with_token(mocker):
    event = app.register(email='*****@*****.**', password='******')
    user = app.users.get_aggregate(event.aggregate_id)
    event = app.activate_with_token(user.id, user.activation_token)
    user.mutate(event)
    assert user.is_active