示例#1
0
def test_request_all_my_posts(db_session, client):
    user, pwd = users.sketch()
    add_fixture(db_session, user)
    post_instances = posts.create_posts(user, 10)
    add_fixtures(db_session, *post_instances)

    res = client.get('/api/v1/posts', user=user, password=pwd)
    assert res.status_code == 200
示例#2
0
def test_post_model(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    post = create_post(user)
    add_fixture(db_session, post)

    expected_result = frozenset([('title', post.title), ('sub', post.sub),
                                 ('user', user), ('content', post.content)])
    check_db_object(expected_result, Post)
示例#3
0
def test_user_model(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    expected_result = frozenset([
        ('username', 'sketch'),
        ('email', '*****@*****.**')
    ])

    check_db_object(expected_result, User)
示例#4
0
def test_group_membership(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)

    group = create_group()
    user.groups.append(group)
    add_fixture(db_session, group)

    assert group in User.query.get(1).groups
示例#5
0
def test_group_model(db_session):
    group = create_group()
    add_fixture(db_session, group)

    expected_result = frozenset([
        ('name', 'test')
    ])

    check_db_object(expected_result, Group)
示例#6
0
def test_passes_change_instance_public(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    post = create_post(user)
    add_fixture(db_session, post)

    post.grant_permission(permission='read')
    assert post.is_public
    post.revoke_permission(permission='read')
    assert not post.is_public
def test_passes_for_dump_tag_instance(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    post = create_post(user)

    tag = post.Tag(user=user, tag="CMDB")
    data = TagSchema().dump(tag).data

    assert data['author'] == 'sketch'
    assert data['tag'] == 'CMDB'
    assert 'id' in data
    assert 'created_at' in data
    assert 'updated_at' in data
示例#8
0
def test_passes_for_dump_status_instance(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    post = create_post(user)

    status = post.Status(user=user, status="delete")
    data = StatusSchema().dump(status).data

    assert data['author'] == 'sketch'
    assert data['status'] == 'delete'
    assert 'id' in data
    assert 'created_at' in data
    assert 'updated_at' in data
示例#9
0
def test_passed_deserialization_post_instance(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)

    post = create_post(user)
    add_fixture(db_session, post)

    data = PostSchema().dump(post).data

    assert data['id'] == post.id
    assert data['author'] == user.username
    assert data['title'] == post.title
    assert data['sub'] == post.sub
    assert data['content'] == post.content
    assert data['statuses'] == []
    assert data['comments'] == []
    assert data['tags'] == []
示例#10
0
def test_passes_change_permission(db_session):
    user, _ = sketch()
    add_fixture(db_session, user)
    post = create_post(user)
    add_fixture(db_session, post)
    group = create_group()
    # update user data
    user.groups.append(group)
    add_fixture(db_session, group)

    for permission in ('read', 'write', 'delete'):
        assert not post.has_permission(permission=permission, user=user)

        post.grant_permission(permission=permission, group=group)
        # user in group
        assert post.has_permission(permission=permission, user=user)
        post.revoke_permission(permission=permission, group=group)
        assert not post.has_permission(permission=permission, user=user)
示例#11
0
def test_check_password(db_session):
    user, password = sketch()
    add_fixture(db_session, user)

    assert user.check_password(password)
    assert not user.check_password('invalid password')