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_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)