Skip to content

Commit

Permalink
Remove unnecessary mocks in organisation document tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kevincarrogan committed Feb 6, 2024
1 parent 518f755 commit 9caf6ac
Showing 1 changed file with 8 additions and 44 deletions.
52 changes: 8 additions & 44 deletions api/organisations/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,7 @@ def test_create_organisation_document_other_organisation(self, mock_virus_scan,

self.assertEqual(response.status_code, 403)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_list_organisation_documents(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False
def test_list_organisation_documents(self):
DocumentOnOrganisationFactory.create(
document__name="some-document-one",
document__s3_key="thisisakey",
Expand Down Expand Up @@ -106,24 +102,15 @@ def test_list_organisation_documents(self, mock_virus_scan, mock_s3_operations_g
self.assertEqual(response.status_code, 200)
self.assertEqual(len(response.json()["documents"]), 3)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_list_organisation_documents_other_organisation(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False

def test_list_organisation_documents_other_organisation(self):
other_organisation, _ = self.create_organisation_with_exporter_user()
url = reverse("organisations:documents", kwargs={"pk": other_organisation.pk})

response = self.client.get(url, **self.exporter_headers)

self.assertEqual(response.status_code, 403)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_retrieve_organisation_documents(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False
def test_retrieve_organisation_documents(self):
document_on_application = DocumentOnOrganisationFactory.create(
organisation=self.organisation,
expiry_date=datetime.date(2026, 1, 1),
Expand Down Expand Up @@ -164,11 +151,7 @@ def test_retrieve_organisation_documents(self, mock_virus_scan, mock_s3_operatio
},
)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_retrieve_organisation_documents_invalid_organisation(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False
def test_retrieve_organisation_documents_invalid_organisation(self):
other_organisation, _ = self.create_organisation_with_exporter_user()
document_on_application = DocumentOnOrganisationFactory.create(
organisation=other_organisation,
Expand All @@ -190,12 +173,7 @@ def test_retrieve_organisation_documents_invalid_organisation(self, mock_virus_s

self.assertEqual(response.status_code, 403)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_delete_organisation_documents(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False

def test_delete_organisation_documents(self):
document_on_application = DocumentOnOrganisationFactory.create(organisation=self.organisation)

url = reverse(
Expand All @@ -211,12 +189,7 @@ def test_delete_organisation_documents(self, mock_virus_scan, mock_s3_operations
with self.assertRaises(DocumentOnOrganisation.DoesNotExist):
DocumentOnOrganisation.objects.get(pk=document_on_application.pk)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_delete_organisation_document_other_organisation(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False

def test_delete_organisation_document_other_organisation(self):
other_organisation, _ = self.create_organisation_with_exporter_user()
document_on_application = DocumentOnOrganisationFactory.create(organisation=other_organisation)

Expand All @@ -232,11 +205,7 @@ def test_delete_organisation_document_other_organisation(self, mock_virus_scan,
self.assertEqual(response.status_code, 403)
self.assertTrue(DocumentOnOrganisation.objects.filter(pk=document_on_application.pk).exists())

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_update_organisation_documents(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False
def test_update_organisation_documents(self):
document_on_application = DocumentOnOrganisationFactory.create(organisation=self.organisation)

url = reverse(
Expand Down Expand Up @@ -267,12 +236,7 @@ def test_update_organisation_documents(self, mock_virus_scan, mock_s3_operations
"567",
)

@mock.patch("api.documents.libraries.s3_operations.get_object")
@mock.patch("api.documents.libraries.av_operations.scan_file_for_viruses")
def test_update_organisation_documents_other_organisation(self, mock_virus_scan, mock_s3_operations_get_object):
mock_s3_operations_get_object.return_value = self.document_data
mock_virus_scan.return_value = False

def test_update_organisation_documents_other_organisation(self):
other_organisation, _ = self.create_organisation_with_exporter_user()
document_on_application = DocumentOnOrganisationFactory.create(organisation=other_organisation)

Expand Down

0 comments on commit 9caf6ac

Please sign in to comment.