mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-16 01:27:03 +02:00
Revert "Move test into a separate file"
This reverts commit 4c00e67f85
.
This commit is contained in:
parent
4c00e67f85
commit
4f7e44cfc9
2 changed files with 55 additions and 73 deletions
|
@ -3,10 +3,12 @@ from django.test import Client, RequestFactory
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
from registrar.models.domain_request import DomainRequest
|
from registrar.models.domain_request import DomainRequest
|
||||||
from registrar.models.domain import Domain
|
from registrar.models.domain import Domain
|
||||||
|
from registrar.models.user_domain_role import UserDomainRole
|
||||||
from registrar.utility.csv_export import (
|
from registrar.utility.csv_export import (
|
||||||
DomainDataFull,
|
DomainDataFull,
|
||||||
DomainDataType,
|
DomainDataType,
|
||||||
DomainDataFederal,
|
DomainDataFederal,
|
||||||
|
DomainDataTypeUser,
|
||||||
DomainGrowth,
|
DomainGrowth,
|
||||||
DomainManaged,
|
DomainManaged,
|
||||||
DomainUnmanaged,
|
DomainUnmanaged,
|
||||||
|
@ -27,7 +29,7 @@ import boto3_mocking
|
||||||
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
||||||
from django.utils import timezone
|
from django.utils import timezone
|
||||||
from api.tests.common import less_console_noise_decorator
|
from api.tests.common import less_console_noise_decorator
|
||||||
from .common import MockDb, MockEppLib, less_console_noise, get_time_aware_date
|
from .common import MockDb, MockEppLib, less_console_noise, get_time_aware_date, create_user
|
||||||
|
|
||||||
|
|
||||||
class CsvReportsTest(MockDb):
|
class CsvReportsTest(MockDb):
|
||||||
|
@ -598,6 +600,58 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||||
self.assertEqual(csv_content, expected_content)
|
self.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
|
@less_console_noise_decorator
|
||||||
|
def test_domain_data_type_user(self):
|
||||||
|
"""Shows security contacts, domain managers, so for the current user"""
|
||||||
|
|
||||||
|
# Add security email information
|
||||||
|
self.domain_1.name = "defaultsecurity.gov"
|
||||||
|
self.domain_1.save()
|
||||||
|
# Invoke setter
|
||||||
|
self.domain_1.security_contact
|
||||||
|
self.domain_2.security_contact
|
||||||
|
self.domain_3.security_contact
|
||||||
|
# Add a first ready date on the first domain. Leaving the others blank.
|
||||||
|
self.domain_1.first_ready = get_default_start_date()
|
||||||
|
self.domain_1.save()
|
||||||
|
|
||||||
|
# Create a user and associate it with some domains
|
||||||
|
user = create_user()
|
||||||
|
UserDomainRole.objects.create(user=user, domain=self.domain_1)
|
||||||
|
UserDomainRole.objects.create(user=user, domain=self.domain_2)
|
||||||
|
|
||||||
|
# Create a request object
|
||||||
|
request = self.factory.get("/")
|
||||||
|
request.user = user
|
||||||
|
|
||||||
|
# Create a CSV file in memory
|
||||||
|
csv_file = StringIO()
|
||||||
|
# Call the export functions
|
||||||
|
DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
|
||||||
|
# Reset the CSV file's position to the beginning
|
||||||
|
csv_file.seek(0)
|
||||||
|
# Read the content into a variable
|
||||||
|
csv_content = csv_file.read()
|
||||||
|
|
||||||
|
# We expect only domains associated with the user
|
||||||
|
expected_content = (
|
||||||
|
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,"
|
||||||
|
"City,State,SO,SO email,"
|
||||||
|
"Security contact email,Domain managers,Invited domain managers\n"
|
||||||
|
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,World War I Centennial Commission,,,, ,,"
|
||||||
|
'(blank),"meoward@rocks.com, info@example.com, big_lebowski@dude.co, staff@example.com",'
|
||||||
|
"woofwardthethird@rocks.com\n"
|
||||||
|
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),"
|
||||||
|
'"meoward@rocks.com, staff@example.com",squeaker@rocks.com\n'
|
||||||
|
)
|
||||||
|
|
||||||
|
# Normalize line endings and remove commas,
|
||||||
|
# spaces and leading/trailing whitespace
|
||||||
|
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
|
||||||
|
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
||||||
|
self.maxDiff = None
|
||||||
|
self.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
|
|
||||||
class HelperFunctions(MockDb):
|
class HelperFunctions(MockDb):
|
||||||
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
|
"""This asserts that 1=1. Its limited usefulness lies in making sure the helper methods stay healthy."""
|
||||||
|
|
|
@ -1,72 +0,0 @@
|
||||||
from django.test import RequestFactory
|
|
||||||
from io import StringIO
|
|
||||||
from registrar.models.user_domain_role import UserDomainRole
|
|
||||||
from registrar.utility.csv_export import (
|
|
||||||
DomainDataTypeUser,
|
|
||||||
get_default_start_date,
|
|
||||||
)
|
|
||||||
from api.tests.common import less_console_noise_decorator
|
|
||||||
from .common import MockDb, MockEppLib, create_user
|
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTestUserFacing(MockDb, MockEppLib):
|
|
||||||
"""Tests our data exports for users"""
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
super().setUp()
|
|
||||||
self.factory = RequestFactory()
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
super().tearDown()
|
|
||||||
|
|
||||||
@less_console_noise_decorator
|
|
||||||
def test_domain_data_type_user(self):
|
|
||||||
"""Shows security contacts, domain managers, so for the current user"""
|
|
||||||
|
|
||||||
# Add security email information
|
|
||||||
self.domain_1.name = "defaultsecurity.gov"
|
|
||||||
self.domain_1.save()
|
|
||||||
# Invoke setter
|
|
||||||
self.domain_1.security_contact
|
|
||||||
self.domain_2.security_contact
|
|
||||||
self.domain_3.security_contact
|
|
||||||
# Add a first ready date on the first domain. Leaving the others blank.
|
|
||||||
self.domain_1.first_ready = get_default_start_date()
|
|
||||||
self.domain_1.save()
|
|
||||||
|
|
||||||
# Create a user and associate it with some domains
|
|
||||||
user = create_user()
|
|
||||||
UserDomainRole.objects.create(user=user, domain=self.domain_1)
|
|
||||||
UserDomainRole.objects.create(user=user, domain=self.domain_2)
|
|
||||||
|
|
||||||
# Create a request object
|
|
||||||
request = self.factory.get("/")
|
|
||||||
request.user = user
|
|
||||||
|
|
||||||
# Create a CSV file in memory
|
|
||||||
csv_file = StringIO()
|
|
||||||
# Call the export functions
|
|
||||||
DomainDataTypeUser.export_data_to_csv(csv_file, request=request)
|
|
||||||
# Reset the CSV file's position to the beginning
|
|
||||||
csv_file.seek(0)
|
|
||||||
# Read the content into a variable
|
|
||||||
csv_content = csv_file.read()
|
|
||||||
|
|
||||||
# We expect only domains associated with the user
|
|
||||||
expected_content = (
|
|
||||||
"Domain name,Status,First ready on,Expiration date,Domain type,Agency,Organization name,"
|
|
||||||
"City,State,SO,SO email,"
|
|
||||||
"Security contact email,Domain managers,Invited domain managers\n"
|
|
||||||
"defaultsecurity.gov,Ready,2023-11-01,(blank),Federal - Executive,World War I Centennial Commission,,,, ,,"
|
|
||||||
'(blank),"meoward@rocks.com, info@example.com, big_lebowski@dude.co, staff@example.com",'
|
|
||||||
"woofwardthethird@rocks.com\n"
|
|
||||||
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),"
|
|
||||||
'"meoward@rocks.com, staff@example.com",squeaker@rocks.com\n'
|
|
||||||
)
|
|
||||||
|
|
||||||
# Normalize line endings and remove commas,
|
|
||||||
# spaces and leading/trailing whitespace
|
|
||||||
csv_content = csv_content.replace(",,", "").replace(",", "").replace(" ", "").replace("\r\n", "\n").strip()
|
|
||||||
expected_content = expected_content.replace(",,", "").replace(",", "").replace(" ", "").strip()
|
|
||||||
self.maxDiff = None
|
|
||||||
self.assertEqual(csv_content, expected_content)
|
|
Loading…
Add table
Add a link
Reference in a new issue