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
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)
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)
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
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)
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
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
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'] == []
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)
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')