Skip to content

Commit

Permalink
Merge pull request #1654 from ResearchHub/tests-cleanup
Browse files Browse the repository at this point in the history
Cleanup | Use non-deprecated assertion method
  • Loading branch information
gzurowski authored Jul 5, 2024
2 parents 68c4b48 + 4b4f952 commit 6192106
Show file tree
Hide file tree
Showing 8 changed files with 51 additions and 59 deletions.
4 changes: 2 additions & 2 deletions src/institution/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def test_create_institution(self):
Institution.upsert_from_openalex(institution)

created_inst = Institution.objects.filter(openalex_id=institution["id"]).first()
self.assertEquals(created_inst.openalex_id, institution["id"])
self.assertEqual(created_inst.openalex_id, institution["id"])

def test_update_institution(self):
old_institution = self.institutions[0]
Expand All @@ -38,4 +38,4 @@ def test_update_institution(self):
created_inst = Institution.objects.filter(
openalex_id=new_institution["id"]
).first()
self.assertEquals(created_inst.display_name, "new topic")
self.assertEqual(created_inst.display_name, "new topic")
40 changes: 20 additions & 20 deletions src/paper/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,18 +155,18 @@ def test_api_token_can_upload_paper(self):
self.base_url,
{"title": "Paper Uploaded via API Token", "paper_type": "REGULAR"},
)
self.assertEquals(res.status_code, 201)
self.assertEqual(res.status_code, 201)

@skip
def test_search_by_url_arxiv(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://arxiv.org/abs/1407.3561v1", "search": True}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertEquals(result["url"], data["url"])
self.assertEqual(result["url"], data["url"])
self.assertFalse(result["url_is_pdf"])
self.assertEquals(
self.assertEqual(
result["csl_item"]["title"],
"IPFS - Content Addressed, Versioned, P2P File System",
)
Expand All @@ -181,12 +181,12 @@ def test_search_by_url_arxiv_pdf(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://arxiv.org/pdf/1407.3561.pdf"}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertEquals(result["url"], data["url"])
self.assertEqual(result["url"], data["url"])
self.assertTrue(result["url_is_pdf"])
self.assertFalse(result["url_is_unsupported_pdf"])
self.assertEquals(
self.assertEqual(
result["csl_item"]["title"],
"IPFS - Content Addressed, Versioned, P2P File System",
)
Expand All @@ -205,33 +205,33 @@ def test_search_by_url_publisher(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://www.nature.com/articles/s41586-019-1099-1"}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertEquals(result["url"], data["url"])
self.assertEqual(result["url"], data["url"])
self.assertFalse(result["url_is_pdf"])
self.assertFalse(result["url_is_unsupported_pdf"])
self.assertEquals(
self.assertEqual(
result["csl_item"]["title"],
"Restoration of brain circulation and cellular functions hours post-mortem",
) # noqa E501
self.assertEquals(result["csl_item"]["DOI"], "10.1038/s41586-019-1099-1")
self.assertEqual(result["csl_item"]["DOI"], "10.1038/s41586-019-1099-1")

@skip
def test_search_by_url_doi(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://doi.org/10.1038/ng.3259"}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertEquals(result["url"], data["url"])
self.assertEqual(result["url"], data["url"])
self.assertFalse(result["url_is_pdf"])
self.assertFalse(result["url_is_unsupported_pdf"])
self.assertEquals(
self.assertEqual(
result["csl_item"]["title"],
"Understanding multicellular function and disease with human tissue-specific networks",
) # noqa E501
self.assertEquals(result["csl_item"]["DOI"], "10.1038/ng.3259")
self.assertEquals(
self.assertEqual(result["csl_item"]["DOI"], "10.1038/ng.3259")
self.assertEqual(
result["oa_pdf_location"]["url_for_pdf"],
"http://europepmc.org/articles/pmc4828725?pdf=render",
)
Expand All @@ -244,12 +244,12 @@ def test_search_by_url_pmid(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://www.ncbi.nlm.nih.gov/pubmed/18888140"}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertEquals(result["url"], data["url"])
self.assertEqual(result["url"], data["url"])
self.assertFalse(result["url_is_pdf"])
self.assertFalse(result["url_is_unsupported_pdf"])
self.assertEquals(
self.assertEqual(
result["csl_item"]["title"],
"[Major achievements in the second plan year in the Soviet Union].",
) # noqa E501
Expand All @@ -260,7 +260,7 @@ def test_search_by_url_unsupported_pdf(self):
url = self.base_url + "search_by_url/"
data = {"url": "https://bitcoin.org/bitcoin.pdf"}
response = get_authenticated_post_response(self.user, url, data)
self.assertEquals(response.status_code, 200)
self.assertEqual(response.status_code, 200)
result = response.data
self.assertTrue(result["url_is_pdf"])
self.assertTrue(result["url_is_unsupported_pdf"])
Expand Down
12 changes: 6 additions & 6 deletions src/paper/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.test import TestCase, TransactionTestCase, tag
from psycopg2.errors import UniqueViolation

from paper.serializers import DynamicPaperSerializer, PaperSerializer
from paper.serializers import DynamicPaperSerializer
from paper.tasks import handle_duplicate_doi
from paper.utils import (
convert_journal_url_to_pdf_url,
Expand Down Expand Up @@ -168,14 +168,14 @@ def test_journal_to_pdf(self):
pdf_url, exists = convert_journal_url_to_pdf_url(url)
if exists:
print(pdf_url)
self.assertEquals(pdf_url, self.pdf_test_urls[i])
self.assertEqual(pdf_url, self.pdf_test_urls[i])

def test_pdf_to_journal(self):
for i, url in enumerate(self.pdf_test_urls):
journal_url, exists = convert_pdf_url_to_journal_url(url)
if exists:
print(journal_url)
self.assertEquals(journal_url, self.journal_test_urls[i])
self.assertEqual(journal_url, self.journal_test_urls[i])


class PaperPatchTest(TestCase, TestHelper, IntegrationTestHelper):
Expand All @@ -197,9 +197,9 @@ def test_patch_paper(self):
url = f"{self.base_url}{paper.id}/?make_public=true"
response = client.patch(url, form, content_type="application/json")
data = response.data
self.assertEquals(response.status_code, 200)
self.assertEquals(data["title"], updated_title)
self.assertEquals(
self.assertEqual(response.status_code, 200)
self.assertEqual(data["title"], updated_title)
self.assertEqual(
data["raw_authors"], [{"first_name": "First", "last_name": "Last"}]
)

Expand Down
20 changes: 7 additions & 13 deletions src/reputation/tests/test_upvote_rsc_distribution.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
import decimal
import math

from django.contrib.admin.options import get_content_type_for_model
from django.test import TestCase

import reputation.distributions as distributions
from discussion.models import Vote as GrmVote
from discussion.tests.helpers import create_rh_comment
from reputation.models import Distribution, Escrow
from researchhub_case.constants.case_constants import APPROVED
from researchhub_case.models import AuthorClaimCase
from researchhub_case.tasks import after_approval_flow
from user.models import Author
from utils.test_helpers import TestHelper

Expand Down Expand Up @@ -65,8 +59,8 @@ def test_comment_upvote_distribution(self):
comment = create_rh_comment(created_by=new_user, paper=self.original_paper)
GrmVote.objects.create(item=comment, vote_type=1, created_by=voter_user)
distribution = distributions.Distribution(1, 1, 1)
self.assertEquals(Distribution.objects.count(), 1)
self.assertEquals(distribution.amount, Distribution.objects.first().amount)
self.assertEqual(Distribution.objects.count(), 1)
self.assertEqual(distribution.amount, Distribution.objects.first().amount)

def test_upvote_downvote_upvote(self):
if Distribution.objects.count() > 0:
Expand Down Expand Up @@ -99,14 +93,14 @@ def test_upvote_downvote_upvote(self):
)

distribution = distributions.Distribution(1, 1, 1)
self.assertEquals(Distribution.objects.count(), 1)
self.assertEquals(distribution.amount, Distribution.objects.first().amount)
self.assertEqual(Distribution.objects.count(), 1)
self.assertEqual(distribution.amount, Distribution.objects.first().amount)
reply_vote.vote_type = 2
reply_vote.save()
reply_vote.vote_type = 1
reply_vote.save()
self.assertEquals(Distribution.objects.count(), 1)
self.assertEquals(distribution.amount, Distribution.objects.first().amount)
self.assertEqual(Distribution.objects.count(), 1)
self.assertEqual(distribution.amount, Distribution.objects.first().amount)

def test_upvote_distribution(self):
if Distribution.objects.count() > 0:
Expand All @@ -128,4 +122,4 @@ def test_upvote_distribution(self):
eligible_user.save()

distribution = distributions.Distribution(1, 1, 1)
self.assertEquals(distribution.amount, 1)
self.assertEqual(distribution.amount, 1)
12 changes: 6 additions & 6 deletions src/reputation/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ def test_deposit_user_can_list_deposits(self):
self.client.force_authenticate(user)
response = self.client.get("/api/deposit/")

self.assertEquals(response.status_code, 200)
self.assertEquals(response.data["count"], 1)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 1)

def test_deposit_user_cannot_list_other_deposits(self):
user = create_random_authenticated_user("deposit_user")
Expand All @@ -68,8 +68,8 @@ def test_deposit_user_cannot_list_other_deposits(self):
self.client.force_authenticate(other_user)
response = self.client.get("/api/deposit/")

self.assertEquals(response.status_code, 200)
self.assertEquals(response.data["count"], 0)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 0)

def test_deposit_deposit_staff_user_can_list_all_deposits(self):
user1 = create_random_authenticated_user("user1")
Expand All @@ -84,8 +84,8 @@ def test_deposit_deposit_staff_user_can_list_all_deposits(self):
self.client.force_authenticate(staff_user)
response = self.client.get("/api/deposit/")

self.assertEquals(response.status_code, 200)
self.assertEquals(response.data["count"], 2)
self.assertEqual(response.status_code, 200)
self.assertEqual(response.data["count"], 2)

def test_suspecious_user_cannot_withdraw_rsc(self):
user = create_random_authenticated_user("rep_user")
Expand Down
4 changes: 2 additions & 2 deletions src/researchhub_case/tests/test_approval_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def test_mark_user_verified_after_approval(self):

after_approval_flow(case.id)
requesting_user.refresh_from_db()
self.assertEquals(requesting_user.is_verified, True)
self.assertEqual(requesting_user.is_verified, True)

def attribute_paper_to_author(self):
requesting_user = create_random_default_user("2")
Expand All @@ -34,4 +34,4 @@ def attribute_paper_to_author(self):
after_approval_flow(case.id)
requesting_user.refresh_from_db()
self.paper.refresh_from_db()
self.assertEquals(self.paper.authors.first().id, requesting_user.id)
self.assertEqual(self.paper.authors.first().id, requesting_user.id)
12 changes: 5 additions & 7 deletions src/topic/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

from rest_framework.test import APITestCase

from paper.models import Paper
from paper.openalex_util import process_openalex_works
from topic.models import Topic


Expand All @@ -19,7 +17,7 @@ def test_create_topic(self):
Topic.upsert_from_openalex(topic)

created_topic = Topic.objects.filter(openalex_id=topic["id"]).first()
self.assertEquals(created_topic.openalex_id, topic["id"])
self.assertEqual(created_topic.openalex_id, topic["id"])

def test_update_topic(self):
old_topic = self.topics[0]
Expand All @@ -36,7 +34,7 @@ def test_update_topic(self):
Topic.upsert_from_openalex(new_topic)

created_topic = Topic.objects.filter(openalex_id=new_topic["id"]).first()
self.assertEquals(created_topic.display_name, "new topic")
self.assertEqual(created_topic.display_name, "new topic")

def test_create_topic_should_create_related_entities(self):
topic = self.topics[0]
Expand All @@ -46,6 +44,6 @@ def test_create_topic_should_create_related_entities(self):
field = subfield.field
domain = field.domain

self.assertEquals(domain.openalex_id, topic["domain"]["id"])
self.assertEquals(subfield.openalex_id, topic["subfield"]["id"])
self.assertEquals(field.openalex_id, topic["field"]["id"])
self.assertEqual(domain.openalex_id, topic["domain"]["id"])
self.assertEqual(subfield.openalex_id, topic["subfield"]["id"])
self.assertEqual(field.openalex_id, topic["field"]["id"])
6 changes: 3 additions & 3 deletions src/user/tests/test_audit_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_reg_user_cannot_bulk_flag_and_remove(self):
"send_email": False,
},
)
self.assertEquals(http_response.status_code, 403)
self.assertEqual(http_response.status_code, 403)

def test_editor_can_dismiss_flag(self):
self.client.force_authenticate(self.test_editor)
Expand All @@ -121,7 +121,7 @@ def test_editor_can_dismiss_flag(self):
http_response = self.client.post(
DISMISS_FLAGGED_CONTENT_URL, {"flag_ids": [target_flag.id]}
)
self.assertEquals(http_response.status_code, 200)
self.assertEqual(http_response.status_code, 200)

def test_reg_user_cannot_dismiss_flag(self):
self.client.force_authenticate(self.reg_user)
Expand All @@ -132,4 +132,4 @@ def test_reg_user_cannot_dismiss_flag(self):
http_response = self.client.post(
DISMISS_FLAGGED_CONTENT_URL, {"flag_ids": [target_flag.id]}
)
self.assertEquals(http_response.status_code, 403)
self.assertEqual(http_response.status_code, 403)

0 comments on commit 6192106

Please sign in to comment.