From c7149e99cad4540239b62eb3e33603e6d1816a19 Mon Sep 17 00:00:00 2001 From: Marvin Reimer Date: Wed, 18 Jan 2017 20:23:34 +0800 Subject: [PATCH] pep8 and clean up --- test/test_cache/test_cache_users.py | 48 ++++------------------------- 1 file changed, 6 insertions(+), 42 deletions(-) diff --git a/test/test_cache/test_cache_users.py b/test/test_cache/test_cache_users.py index 0ccca1aa0c..b676e0ea34 100644 --- a/test/test_cache/test_cache_users.py +++ b/test/test_cache/test_cache_users.py @@ -21,12 +21,10 @@ from pybossa.model.user import User from factories import ProjectFactory, TaskFactory, TaskRunFactory, UserFactory -from factories import reset_all_pk_sequences class TestUsersCache(Test): - def test_get_user_summary_nousers(self): """Test CACHE USERS get_user_summary returns None if no user exists with the name requested""" @@ -34,7 +32,6 @@ def test_get_user_summary_nousers(self): assert user is None, user - def test_public_get_user_summary_nousers(self): """Test public CACHE USERS get_user_summary returns None if no user exists with the name requested""" @@ -42,7 +39,6 @@ def test_public_get_user_summary_nousers(self): assert user is None, user - def test_get_user_summary_user_exists(self): """Test CACHE USERS get_user_summary returns a dict with the user data if the user exists""" @@ -65,7 +61,6 @@ def test_public_get_user_summary_user_exists(self): assert type(zizou) is dict, type(zizou) assert zizou != None, zizou - def test_get_user_summary_returns_fields(self): """Test CACHE USERS get_user_summary all the fields in the dict""" UserFactory.create(name='user') @@ -99,7 +94,7 @@ def test_rank_and_score(self): users = UserFactory.create_batch(4) for user in users: i += 1 - taskruns = TaskRunFactory.create_batch(i, user=user, task=tasks[i-1]) + taskruns = TaskRunFactory.create_batch(i, user=user, task=tasks[i - 1]) first_in_rank = cached_users.rank_and_score(users[3].id) last_in_rank = cached_users.rank_and_score(users[0].id) @@ -109,7 +104,6 @@ def test_rank_and_score(self): assert last_in_rank['rank'] == 4, last_in_rank['rank'] assert last_in_rank['score'] == 1, last_in_rank['score'] - def test_projects_contributed_no_contributions(self): """Test CACHE USERS projects_contributed returns empty list if the user has not contributed to any project""" @@ -119,7 +113,6 @@ def test_projects_contributed_no_contributions(self): assert projects_contributed == [], projects_contributed - def test_projects_contributed_no_contributions_cached(self): """Test CACHE USERS projects_contributed_cached returns empty list if the user has not contributed to any project""" @@ -129,7 +122,6 @@ def test_projects_contributed_no_contributions_cached(self): assert projects_contributed == [], projects_contributed - def test_public_projects_contributed_no_contributions(self): """Test public CACHE USERS projects_contributed returns empty list if the user has not contributed to any project""" @@ -139,7 +131,6 @@ def test_public_projects_contributed_no_contributions(self): assert projects_contributed == [], projects_contributed - def test_public_projects_contributed_no_contributions_cached(self): """Test public CACHE USERS projects_contributed_cached returns empty list if the user has not contributed to any project""" @@ -149,7 +140,6 @@ def test_public_projects_contributed_no_contributions_cached(self): assert projects_contributed == [], projects_contributed - def test_projects_contributed_contributions(self): """Test CACHE USERS projects_contributed returns a list of projects that has contributed to""" @@ -164,7 +154,6 @@ def test_projects_contributed_contributions(self): assert len(projects_contributed) == 1 assert projects_contributed[0]['short_name'] == project_contributed.short_name, projects_contributed - def test_projects_contributed_contributions_cached(self): """Test CACHE USERS projects_contributed_cached returns a list of projects that has contributed to""" @@ -199,7 +188,6 @@ def test_public_projects_contributed_contributions(self): assert 'owner_id' not in projects_contributed[0], err_msg assert 'task_presenter' not in projects_contributed[0]['info'] - def test_public_projects_contributed_contributions_cached(self): """Test CACHE USERS public cached projects_contributed returns a list of projects that has contributed to""" @@ -220,7 +208,6 @@ def test_public_projects_contributed_contributions_cached(self): assert 'owner_id' not in projects_contributed[0], err_msg assert 'task_presenter' not in projects_contributed[0]['info'] - def test_projects_contributed_returns_fields(self): """Test CACHE USERS projects_contributed returns the info of the projects with the required fields""" @@ -229,14 +216,13 @@ def test_projects_contributed_returns_fields(self): task = TaskFactory.create(project=project_contributed) TaskRunFactory.create(task=task, user=user) fields = ('id', 'name', 'short_name', 'owner_id', 'description', - 'overall_progress', 'n_tasks', 'n_volunteers', 'info') + 'overall_progress', 'n_tasks', 'n_volunteers', 'info') projects_contributed = cached_users.projects_contributed(user.id) for field in fields: assert field in projects_contributed[0].keys(), field - def test_published_projects_no_projects(self): """Test CACHE USERS published_projects returns empty list if the user has not created any project""" @@ -246,7 +232,6 @@ def test_published_projects_no_projects(self): assert projects_published == [], projects_published - def test_published_projects_no_projects_cached(self): """Test CACHE USERS published_projects_cached returns empty list if the user has not created any project""" @@ -256,7 +241,6 @@ def test_published_projects_no_projects_cached(self): assert projects_published == [], projects_published - def test_public_published_projects_no_projects(self): """Test public CACHE USERS published_projects returns empty list if the user has not created any project""" @@ -266,7 +250,6 @@ def test_public_published_projects_no_projects(self): assert projects_published == [], projects_published - def test_public_published_projects_no_projects_cached(self): """Test public CACHE USERS published_projects_cached returns empty list if the user has not created any project""" @@ -276,7 +259,6 @@ def test_public_published_projects_no_projects_cached(self): assert projects_published == [], projects_published - def test_published_projects_returns_published(self): """Test CACHE USERS published_projects returns a list with the projects that are published by the user""" @@ -288,7 +270,6 @@ def test_published_projects_returns_published(self): assert len(projects_published) == 1, projects_published assert projects_published[0]['short_name'] == published_project.short_name, projects_published - def test_public_published_projects_returns_published(self): """Test public CACHE USERS published_projects returns a list with the projects that are published by the user""" @@ -300,7 +281,6 @@ def test_public_published_projects_returns_published(self): assert len(projects_published) == 1, projects_published assert projects_published[0]['short_name'] == published_project.short_name, projects_published - def test_published_projects_only_returns_published(self): """Test CACHE USERS published_projects does not return draft or another user's projects""" @@ -312,21 +292,19 @@ def test_published_projects_only_returns_published(self): assert len(projects_published) == 0, projects_published - def test_published_projects_returns_fields(self): """Test CACHE USERS published_projects returns the info of the projects with the required fields""" user = UserFactory.create() published_project = ProjectFactory.create(owner=user, published=True) fields = ('id', 'name', 'short_name', 'owner_id', 'description', - 'overall_progress', 'n_tasks', 'n_volunteers', 'info') + 'overall_progress', 'n_tasks', 'n_volunteers', 'info') projects_published = cached_users.published_projects(user.id) for field in fields: assert field in projects_published[0].keys(), field - def test_public_published_projects_returns_fields(self): """Test CACHE USERS published_projects returns the info of the projects with the required fields""" @@ -344,7 +322,6 @@ def test_public_published_projects_returns_fields(self): for field in private_fields: assert field not in projects_published[0].keys(), field - def test_public_published_projects_cached_returns_fields(self): """Test CACHE USERS published_projects_cached returns the info of the projects with the required fields""" @@ -362,7 +339,6 @@ def test_public_published_projects_cached_returns_fields(self): for field in private_fields: assert field not in projects_published[0].keys(), field - def test_draft_projects_no_projects(self): """Test CACHE USERS draft_projects returns an empty list if the user has no draft projects""" @@ -373,7 +349,6 @@ def test_draft_projects_no_projects(self): assert len(draft_projects) == 0, draft_projects - def test_draft_projects_return_drafts(self): """Test CACHE USERS draft_projects returns draft belonging to the user""" user = UserFactory.create() @@ -384,7 +359,6 @@ def test_draft_projects_return_drafts(self): assert len(draft_projects) == 1, draft_projects assert draft_projects[0]['short_name'] == draft_project.short_name, draft_projects - def test_draft_projects_only_returns_drafts(self): """Test CACHE USERS draft_projects does not return any pubished projects or drafts that belong to another user""" @@ -396,21 +370,19 @@ def test_draft_projects_only_returns_drafts(self): assert len(draft_projects) == 0, draft_projects - def test_draft_projects_returns_fields(self): """Test CACHE USERS draft_projects returns the info of the projects with the required fields""" user = UserFactory.create() draft_project = ProjectFactory.create(owner=user, published=False) fields = ('id', 'name', 'short_name', 'owner_id', 'description', - 'overall_progress', 'n_tasks', 'n_volunteers', 'info') + 'overall_progress', 'n_tasks', 'n_volunteers', 'info') draft_project = cached_users.draft_projects(user.id) for field in fields: assert field in draft_project[0].keys(), field - def test_get_leaderboard_no_users_returns_empty_list(self): """Test CACHE USERS get_leaderboard returns an empty list if there are no users""" @@ -419,7 +391,6 @@ def test_get_leaderboard_no_users_returns_empty_list(self): assert users == [], users - def test_get_leaderboard_returns_users_ordered_by_rank(self): leader = UserFactory.create() second = UserFactory.create() @@ -428,7 +399,7 @@ def test_get_leaderboard_returns_users_ordered_by_rank(self): tasks = TaskFactory.create_batch(3, project=project) i = 3 for user in [leader, second, third]: - TaskRunFactory.create_batch(i, user=user, task=tasks[i-1]) + TaskRunFactory.create_batch(i, user=user, task=tasks[i - 1]) i -= 1 leaderboard = cached_users.get_leaderboard(3) @@ -437,7 +408,6 @@ def test_get_leaderboard_returns_users_ordered_by_rank(self): assert leaderboard[1]['name'] == second.name assert leaderboard[2]['name'] == third.name - def test_get_leaderboard_includes_specific_user_even_is_not_in_top(self): leader = UserFactory.create() second = UserFactory.create() @@ -446,7 +416,7 @@ def test_get_leaderboard_includes_specific_user_even_is_not_in_top(self): tasks = TaskFactory.create_batch(3, project=project) i = 3 for user in [leader, second, third]: - TaskRunFactory.create_batch(i, user=user, task=tasks[i-1]) + TaskRunFactory.create_batch(i, user=user, task=tasks[i - 1]) i -= 1 user_out_of_top = UserFactory.create() @@ -455,7 +425,6 @@ def test_get_leaderboard_includes_specific_user_even_is_not_in_top(self): assert len(leaderboard) is 4 assert leaderboard[-1]['name'] == user_out_of_top.name - def test_get_leaderboard_returns_fields(self): """Test CACHE USERS get_leaderboard returns user fields""" user = UserFactory.create() @@ -468,13 +437,11 @@ def test_get_leaderboard_returns_fields(self): assert field in leaderboard[0].keys(), field assert len(leaderboard[0].keys()) == len(fields) - def test_get_total_users_returns_0_if_no_users(self): total_users = cached_users.get_total_users() assert total_users == 0, total_users - def test_get_total_users_returns_number_of_users(self): expected_number_of_users = 3 UserFactory.create_batch(expected_number_of_users) @@ -483,7 +450,6 @@ def test_get_total_users_returns_number_of_users(self): assert total_users == expected_number_of_users, total_users - def test_get_users_page_only_returns_users_with_contributions(self): users = UserFactory.create_batch(2) TaskRunFactory.create(user=users[0]) @@ -492,7 +458,6 @@ def test_get_users_page_only_returns_users_with_contributions(self): assert len(users_with_contrib) == 1, users_with_contrib - def test_get_users_page_supports_pagination(self): users = UserFactory.create_batch(3) for user in users: @@ -503,7 +468,6 @@ def test_get_users_page_supports_pagination(self): assert len(paginated_users) == 1, paginated_users assert paginated_users[0]['name'] == users[1].name - def test_get_users_page_returns_fields(self): user = UserFactory.create() TaskRunFactory.create(user=user)