Refactored some tets

remotes/origin/enhancement/email-actions
David Barragán Merino 2015-06-24 00:41:32 +02:00
parent 8efeb406fd
commit 9f253394a4
10 changed files with 65 additions and 65 deletions

View File

@ -47,7 +47,7 @@ def test_valid_project_export_with_celery_disabled(client, settings):
response = client.get(url, content_type="application/json")
assert response.status_code == 200
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert "url" in response_data
@ -63,7 +63,7 @@ def test_valid_project_export_with_celery_enabled(client, settings):
response = client.get(url, content_type="application/json")
assert response.status_code == 202
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert "export_id" in response_data

View File

@ -32,7 +32,7 @@ def test_bad_signature(client):
url = "{}?project={}&key={}".format(url, project.id, "badbadbad")
data = {}
response = client.post(url, urllib.parse.urlencode(data, True), content_type="application/x-www-form-urlencoded")
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert response.status_code == 400
assert "Bad signature" in response_content["_error_message"]
@ -232,7 +232,7 @@ def test_api_get_project_modules(client):
client.login(project.owner)
response = client.get(url)
assert response.status_code == 200
content = json.loads(response.content.decode("utf-8"))
content = response.data
assert "bitbucket" in content
assert content["bitbucket"]["secret"] != ""
assert content["bitbucket"]["webhooks_url"] != ""

View File

@ -30,7 +30,7 @@ def test_bad_signature(client):
response = client.post(url, json.dumps(data),
HTTP_X_HUB_SIGNATURE="sha1=badbadbad",
content_type="application/json")
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert response.status_code == 400
assert "Bad signature" in response_content["_error_message"]
@ -421,7 +421,7 @@ def test_api_get_project_modules(client):
client.login(project.owner)
response = client.get(url)
assert response.status_code == 200
content = json.loads(response.content.decode("utf-8"))
content = response.data
assert "github" in content
assert content["github"]["secret"] != ""
assert content["github"]["webhooks_url"] != ""

View File

@ -33,7 +33,7 @@ def test_bad_signature(client):
url = "{}?project={}&key={}".format(url, project.id, "badbadbad")
data = {}
response = client.post(url, json.dumps(data), content_type="application/json")
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert response.status_code == 400
assert "Bad signature" in response_content["_error_message"]
@ -349,7 +349,7 @@ def test_api_get_project_modules(client):
client.login(project.owner)
response = client.get(url)
assert response.status_code == 200
content = json.loads(response.content.decode("utf-8"))
content = response.data
assert "gitlab" in content
assert content["gitlab"]["secret"] != ""
assert content["gitlab"]["webhooks_url"] != ""

View File

@ -58,7 +58,7 @@ def test_valid_project_import_without_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
must_empty_children = [
"issues", "user_stories", "us_statuses", "wiki_pages", "priorities",
"severities", "milestones", "points", "issue_types", "task_statuses",
@ -85,7 +85,7 @@ def test_valid_project_import_with_not_existing_memberships(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
# The new membership and the owner membership
assert len(response_data["memberships"]) == 2
@ -108,7 +108,7 @@ def test_valid_project_import_with_membership_uuid_rewrite(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert Membership.objects.filter(email="with-uuid@email.com", token="123").count() == 0
@ -149,7 +149,7 @@ def test_valid_project_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
must_empty_children = [
"issues", "user_stories", "wiki_pages", "milestones",
"wiki_links",
@ -178,7 +178,7 @@ def test_invalid_project_import_without_roles(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 2
assert Project.objects.filter(slug="imported-project").count() == 0
@ -205,7 +205,7 @@ def test_invalid_project_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 7
assert Project.objects.filter(slug="imported-project").count() == 0
@ -302,7 +302,7 @@ def test_valid_user_story_import(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["subject"] == "Imported issue"
assert response_data["finish_date"] == "2014-10-24T00:00:00+0000"
@ -349,7 +349,7 @@ def test_valid_issue_import_without_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -408,7 +408,7 @@ def test_valid_issue_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data["attachments"]) == 1
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -435,7 +435,7 @@ def test_invalid_issue_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
assert Issue.objects.filter(subject="Imported issue").count() == 0
@ -460,7 +460,7 @@ def test_invalid_issue_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
url = reverse("importer-issue", args=[project.pk])
@ -472,7 +472,7 @@ def test_invalid_issue_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
url = reverse("importer-issue", args=[project.pk])
@ -484,7 +484,7 @@ def test_invalid_issue_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
url = reverse("importer-issue", args=[project.pk])
@ -496,7 +496,7 @@ def test_invalid_issue_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
@ -528,7 +528,7 @@ def test_valid_us_import_without_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -556,7 +556,7 @@ def test_valid_us_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data["attachments"]) == 1
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -579,7 +579,7 @@ def test_invalid_us_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
assert UserStory.objects.filter(subject="Imported us").count() == 0
@ -601,7 +601,7 @@ def test_invalid_us_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
@ -633,7 +633,7 @@ def test_valid_task_import_without_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -685,7 +685,7 @@ def test_valid_task_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data["attachments"]) == 1
assert response_data["owner"] == user.email
assert response_data["ref"] is not None
@ -708,7 +708,7 @@ def test_invalid_task_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
assert Task.objects.filter(subject="Imported task").count() == 0
@ -730,7 +730,7 @@ def test_invalid_task_import_with_bad_choices(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
@ -781,7 +781,7 @@ def test_valid_wiki_page_import_without_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["owner"] == user.email
@ -806,7 +806,7 @@ def test_valid_wiki_page_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data["attachments"]) == 1
assert response_data["owner"] == user.email
@ -826,7 +826,7 @@ def test_invalid_wiki_page_import_with_extra_data(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert len(response_data) == 1
assert WikiPage.objects.filter(slug="imported-wiki-page").count() == 0
@ -858,7 +858,7 @@ def test_valid_wiki_link_import(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
json.loads(response.content.decode("utf-8"))
response.data
@ -890,7 +890,7 @@ def test_valid_milestone_import(client):
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 201
json.loads(response.content.decode("utf-8"))
response.data
@ -910,7 +910,7 @@ def test_milestone_import_duplicated_milestone(client):
response = client.post(url, json.dumps(data), content_type="application/json")
response = client.post(url, json.dumps(data), content_type="application/json")
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["milestones"][0]["name"][0] == "Name duplicated for the project"
@ -925,7 +925,7 @@ def test_invalid_dump_import(client):
response = client.post(url, {'dump': data})
assert response.status_code == 400
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["_error_message"] == "Invalid dump format"
@ -946,7 +946,7 @@ def test_valid_dump_import_with_celery_disabled(client, settings):
response = client.post(url, {'dump': data})
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert "id" in response_data
assert response_data["name"] == "Valid project"
@ -968,7 +968,7 @@ def test_valid_dump_import_with_celery_enabled(client, settings):
response = client.post(url, {'dump': data})
assert response.status_code == 202
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert "import_id" in response_data
@ -988,7 +988,7 @@ def test_dump_import_duplicated_project(client):
response = client.post(url, {'dump': data})
assert response.status_code == 201
response_data = json.loads(response.content.decode("utf-8"))
response_data = response.data
assert response_data["name"] == "Test import"
assert response_data["slug"] == "{}-test-import".format(user.username)

View File

@ -463,4 +463,4 @@ def test_retrieve_notify_policies_by_anonymous_user(client):
url = reverse("notifications-detail", args=[policy.pk])
response = client.get(url, content_type="application/json")
assert response.status_code == 404, response.status_code
assert json.loads(response.content.decode("utf-8"))["_error_message"] == "No NotifyPolicy matches the given query.", response.content
assert response.data["_error_message"] == "No NotifyPolicy matches the given query.", response.content

View File

@ -61,7 +61,7 @@ def test_invalid_concurrent_save_for_issue(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.content
issue_id = json.loads(response.content)["id"]
issue_id = response.data["id"]
url = reverse("issues-detail", args=(issue_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -90,7 +90,7 @@ def test_valid_concurrent_save_for_issue_different_versions(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.content
issue_id = json.loads(response.content)["id"]
issue_id = response.data["id"]
url = reverse("issues-detail", args=(issue_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -119,7 +119,7 @@ def test_valid_concurrent_save_for_issue_different_fields(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.content
issue_id = json.loads(response.content)["id"]
issue_id = response.data["id"]
url = reverse("issues-detail", args=(issue_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -143,7 +143,7 @@ def test_invalid_concurrent_save_for_wiki_page(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.content
wiki_id = json.loads(response.content)["id"]
wiki_id = response.data["id"]
url = reverse("wiki-detail", args=(wiki_id,))
data = {"version": 1, "content": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -167,7 +167,7 @@ def test_valid_concurrent_save_for_wiki_page_different_versions(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201, response.content
wiki_id = json.loads(response.content)["id"]
wiki_id = response.data["id"]
url = reverse("wiki-detail", args=(wiki_id,))
data = {"version": 1, "content": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -194,7 +194,7 @@ def test_invalid_concurrent_save_for_us(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
userstory_id = json.loads(response.content)["id"]
userstory_id = response.data["id"]
url = reverse("userstories-detail", args=(userstory_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -220,7 +220,7 @@ def test_valid_concurrent_save_for_us_different_versions(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
userstory_id = json.loads(response.content)["id"]
userstory_id = response.data["id"]
url = reverse("userstories-detail", args=(userstory_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -246,7 +246,7 @@ def test_valid_concurrent_save_for_us_different_fields(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
userstory_id = json.loads(response.content)["id"]
userstory_id = response.data["id"]
url = reverse("userstories-detail", args=(userstory_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -272,7 +272,7 @@ def test_invalid_concurrent_save_for_task(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
task_id = json.loads(response.content)["id"]
task_id = response.data["id"]
url = reverse("tasks-detail", args=(task_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -298,7 +298,7 @@ def test_valid_concurrent_save_for_task_different_versions(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
task_id = json.loads(response.content)["id"]
task_id = response.data["id"]
url = reverse("tasks-detail", args=(task_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -324,7 +324,7 @@ def test_valid_concurrent_save_for_task_different_fields(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
task_id = json.loads(response.content)["id"]
task_id = response.data["id"]
url = reverse("tasks-detail", args=(task_id,))
data = {"version": 1, "subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")
@ -351,7 +351,7 @@ def test_invalid_save_without_version_parameter(client):
response = client.json.post(url, json.dumps(data))
assert response.status_code == 201
task_id = json.loads(response.content)["id"]
task_id = response.data["id"]
url = reverse("tasks-detail", args=(task_id,))
data = {"subject": "test 1"}
response = client.patch(url, json.dumps(data), content_type="application/json")

View File

@ -200,7 +200,7 @@ def test_leave_project_valid_membership_only_owner(client):
url = reverse("projects-leave", args=(project.id,))
response = client.post(url)
assert response.status_code == 403
assert json.loads(response.content)["_error_message"] == "You can't leave the project if there are no more owners"
assert response.data["_error_message"] == "You can't leave the project if there are no more owners"
def test_leave_project_invalid_membership(client):
@ -221,7 +221,7 @@ def test_delete_membership_only_owner(client):
url = reverse("memberships-detail", args=(membership.id,))
response = client.delete(url)
assert response.status_code == 400
assert json.loads(response.content)["_error_message"] == "At least one of the user must be an active admin"
assert response.data["_error_message"] == "At least one of the user must be an active admin"
def test_edit_membership_only_owner(client):
@ -339,7 +339,7 @@ def test_projects_user_order(client):
url = reverse("projects-list")
url = "%s?member=%s" % (url, user.id)
response = client.json.get(url)
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert response.status_code == 200
assert(response_content[0]["id"] == project_1.id)
@ -347,6 +347,6 @@ def test_projects_user_order(client):
url = reverse("projects-list")
url = "%s?member=%s&order_by=memberships__user_order" % (url, user.id)
response = client.json.get(url)
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert response.status_code == 200
assert(response_content[0]["id"] == project_2.id)

View File

@ -202,13 +202,13 @@ def test_list_contacts_private_projects(client):
url = reverse('users-contacts', kwargs={"pk": user_1.pk})
response = client.get(url, content_type="application/json")
assert response.status_code == 200
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert len(response_content) == 0
client.login(user_1)
response = client.get(url, content_type="application/json")
assert response.status_code == 200
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert len(response_content) == 1
assert response_content[0]["id"] == user_2.id
@ -227,7 +227,7 @@ def test_list_contacts_no_projects(client):
response = client.get(url, content_type="application/json")
assert response.status_code == 200
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert len(response_content) == 0
@ -246,6 +246,6 @@ def test_list_contacts_public_projects(client):
response = client.get(url, content_type="application/json")
assert response.status_code == 200
response_content = json.loads(response.content.decode("utf-8"))
response_content = response.data
assert len(response_content) == 1
assert response_content[0]["id"] == user_2.id

View File

@ -203,15 +203,15 @@ def test_archived_filter(client):
data = {}
response = client.get(url, data)
assert len(json.loads(response.content)) == 2
assert len(response.data) == 2
data = {"status__is_archived": 0}
response = client.get(url, data)
assert len(json.loads(response.content)) == 1
assert len(response.data) == 1
data = {"status__is_archived": 1}
response = client.get(url, data)
assert len(json.loads(response.content)) == 1
assert len(response.data) == 1
def test_filter_by_multiple_status(client):
@ -230,7 +230,7 @@ def test_filter_by_multiple_status(client):
data = {}
response = client.get(url, data)
assert len(json.loads(response.content)) == 2
assert len(response.data) == 2
def test_get_total_points(client):