def test_serialize_very_detailed(app, authed_client): add_permissions(app, 'forums_threads_modify', 'forums_threads_modify_advanced') thread = ForumThread.from_pk(3) data = NewJSONEncoder().default(thread) check_dictionary( data, { 'id': 3, 'topic': 'Using PHP', 'locked': True, 'sticky': True, 'deleted': False, 'post_count': 1, 'subscribed': True, }, ) assert 'forum' in data and data['forum']['id'] == 2 assert 'creator' in data and data['creator']['id'] == 2 assert 'last_post' in data and data['last_post']['id'] == 2 assert 'last_viewed_post' in data and data['last_viewed_post']['id'] == 2 assert ('posts' in data and len(data['posts']) == 1 and data['posts'][0]['id'] == 2) assert 'created_time' in data and isinstance(data['created_time'], int) assert 'poll' in data and data['poll']['id'] == 3 assert 'thread_notes' in data assert ('thread_notes' in data and len(data['thread_notes']) == 1 and data['thread_notes'][0]['id'] == 3)
def test_serialize_very_detailed(app, authed_client): add_permissions(app, 'users_moderate', 'users_moderate_advanced') user = User.from_pk(1) data = NewJSONEncoder().default(user) check_dictionary( data, { 'id': 1, 'username': '******', 'email': '*****@*****.**', 'enabled': True, 'locked': False, 'user_class': 'User', 'secondary_classes': ['FLS'], 'uploaded': 5368709120, 'downloaded': 0, 'invites': 1, 'inviter': None, 'basic_permissions': [], }, ) assert 'api_keys' in data and len(data['api_keys']) == 2 assert 'permissions' in data and set(data['permissions']) == { 'users_moderate', 'users_moderate_advanced', }
def test_serialize_user_class_detailed(app, authed_client): user_class = UserClass.from_pk(1) data = NewJSONEncoder().default(user_class) check_dictionary( data, { 'id': 1, 'name': 'User', 'permissions': ['permissions_modify', 'users_edit_settings'], }, strict=True, )
def test_serialize_no_perms(app, authed_client): category = ForumCategory.from_pk(1) data = NewJSONEncoder().default(category) check_dictionary( data, { 'id': 1, 'name': 'Site', 'description': 'General site discussion', 'position': 1, }, ) assert 'forums' in data and len(data['forums']) == 2
def test_serialize_no_perms(app, authed_client): forum = Forum.from_pk(1) data = NewJSONEncoder().default(forum) check_dictionary( data, { 'id': 1, 'name': 'Pulsar', 'description': 'Stuff about pulsar', 'position': 1, 'thread_count': 1, }, ) assert 'category' in data and data['category']['id'] == 1 assert 'threads' in data and len(data['threads']) == 1
def test_serialize_very_detailed(app, authed_client): add_permissions(app, 'forums_forums_modify') category = ForumCategory.from_pk(1) data = NewJSONEncoder().default(category) check_dictionary( data, { 'id': 1, 'name': 'Site', 'description': 'General site discussion', 'position': 1, 'deleted': False, }, ) assert 'forums' in data and len(data['forums']) == 2
def test_serialize_nested(app, authed_client): add_permissions(app, 'forums_forums_modify') category = ForumCategory.from_pk(1) data = category.serialize(nested=True) check_dictionary( data, { 'id': 1, 'name': 'Site', 'description': 'General site discussion', 'forums': None, 'position': 1, 'deleted': False, }, strict=True, )
def test_serialize_no_perms(app, client): user = User.from_pk(1) data = NewJSONEncoder().default(user) check_dictionary( data, { 'id': 1, 'username': '******', 'enabled': True, 'user_class': 'User', 'secondary_classes': ['FLS'], 'uploaded': 5368709120, 'downloaded': 0, 'permissions': None, }, )
def test_serialize_very_detailed(app, authed_client): add_permissions(app, 'forums_forums_modify') forum = Forum.from_pk(1) data = NewJSONEncoder().default(forum) check_dictionary( data, { 'id': 1, 'name': 'Pulsar', 'description': 'Stuff about pulsar', 'position': 1, 'thread_count': 1, 'deleted': False, }, ) assert 'category' in data and data['category']['id'] == 1 assert 'threads' in data and len(data['threads']) == 1
def test_serialize_nested(app, authed_client): add_permissions(app, 'forums_forums_modify') forum = Forum.from_pk(1) data = forum.serialize(nested=True) check_dictionary( data, { 'id': 1, 'name': 'Pulsar', 'description': 'Stuff about pulsar', 'position': 1, 'thread_count': 1, 'deleted': False, }, ) assert ('last_updated_thread' in data and 'id' in data['last_updated_thread'])
def test_serialize_detailed(app, authed_client): add_permissions(app, 'api_keys_view_others') api_key = APIKey.from_pk('1234567890', include_dead=True) data = NewJSONEncoder().default(api_key) check_dictionary( data, { 'hash': '1234567890', 'user_id': 2, 'ip': '0.0.0.0', 'user_agent': None, 'revoked': True, 'permanent': False, 'timeout': 3600, 'permissions': [], }, ) assert 'last_used' in data and isinstance(data['last_used'], int)
def test_serialize_nested(app, authed_client): add_permissions(app, 'forums_threads_modify_advanced') thread = ForumThread.from_pk(3) data = NewJSONEncoder()._objects_to_dict(thread.serialize(nested=True)) check_dictionary( data, { 'id': 3, 'topic': 'Using PHP', 'locked': True, 'sticky': True, 'deleted': False, 'post_count': 1, 'subscribed': True, }, ) assert 'creator' in data and data['creator']['id'] == 2 assert 'last_post' in data and data['last_post']['id'] == 2 assert 'last_viewed_post' in data and data['last_viewed_post']['id'] == 2 assert 'created_time' in data and isinstance(data['created_time'], int)
def test_serialize_no_perms(app, authed_client): post = ForumPost.from_pk(2) data = NewJSONEncoder().default(post) check_dictionary( data, { 'id': 2, 'contents': 'Why the f**k is Gazelle in PHP?!', 'sticky': True, 'editor': None, }, ) assert ( 'thread' in data and data['thread']['id'] == 3 and len([k for k, v in data['thread'].items() if v]) == 2 ) assert 'user' in data and data['user']['id'] == 1 assert 'time' in data and isinstance(data['time'], int) assert 'edited_time' in data
def test_serialize_no_perms(app, authed_client): thread = ForumThread.from_pk(3) data = NewJSONEncoder().default(thread) check_dictionary( data, { 'id': 3, 'topic': 'Using PHP', 'locked': True, 'sticky': True, 'post_count': 1, 'subscribed': True, }, ) assert 'forum' in data and data['forum']['id'] == 2 assert 'creator' in data and data['creator']['id'] == 2 assert 'last_post' in data and data['last_post']['id'] == 2 assert 'last_viewed_post' in data and data['last_viewed_post']['id'] == 2 assert ('posts' in data and len(data['posts']) == 1 and data['posts'][0]['id'] == 2) assert 'created_time' in data and isinstance(data['created_time'], int) assert 'poll' in data and data['poll']['id'] == 3
def test_serialize_nested(app, authed_client): add_permissions(app, 'forums_posts_modify_advanced') post = ForumPost.from_pk(1) data = NewJSONEncoder()._objects_to_dict(post.serialize(nested=True)) check_dictionary( data, { 'id': 1, 'contents': '!site New yeah', 'sticky': True, 'editor': None, 'deleted': False, }, ) assert 'user' in data and data['user']['id'] == 1 assert 'time' in data and isinstance(data['time'], int) assert 'edited_time' in data assert ( 'edit_history' in data and data['edit_history'][0]['id'] == 1 and len(data['edit_history']) == 1 )
def test_serialize_nested(app, authed_client): add_permissions(app, 'users_moderate') user = User.from_pk(1) data = NewJSONEncoder()._objects_to_dict(user.serialize(nested=True)) check_dictionary( data, { 'id': 1, 'username': '******', 'email': '*****@*****.**', 'enabled': True, 'locked': False, 'user_class': 'User', 'secondary_classes': ['FLS'], 'uploaded': 5368709120, 'downloaded': 0, 'invites': 1, 'api_keys': None, 'basic_permissions': None, 'inviter': None, 'permissions': None, }, strict=True, )
def test_serialize_self(app, authed_client): api_key = APIKey.from_pk('abcdefghij') data = NewJSONEncoder().default(api_key) check_dictionary( data, { 'hash': 'abcdefghij', 'user_id': 1, 'ip': '0.0.0.0', 'user_agent': None, 'revoked': False, 'permissions': [ 'sample_permission', 'sample_2_permission', 'sample_3_permission', ], }, ) assert 'last_used' in data and isinstance(data['last_used'], int)
def test_serialize_user_class_permless(app, client): user_class = UserClass.from_pk(1) data = NewJSONEncoder().default(user_class) check_dictionary(data, {'id': 1, 'name': 'User'})
def test_serialize_basic_perms(authed_client): pm = PrivateConversation.from_pk(1) pm.set_state(1) data = NewJSONEncoder().default(pm) check_dictionary(data, {'id': 1, 'topic': 'New Private Message!'})
def test_serialize_view_others(app, authed_client): add_permissions(app, MessagePermissions.VIEW_OTHERS) pm = PrivateConversation.from_pk(4) pm.set_state(2) data = NewJSONEncoder().default(pm) check_dictionary(data, {'id': 4, 'topic': 'detingstings'})
def test_serialize(authed_client): article = WikiArticle.from_pk(1) data = NewJSONEncoder().default(article) check_dictionary(data, {'id': 1, 'title': 'Wiki1'})