mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-05 09:21:54 +02:00
merge main
This commit is contained in:
commit
8e3c821aa0
61 changed files with 1629 additions and 522 deletions
|
@ -1,12 +1,16 @@
|
|||
import io
|
||||
from django.test import Client, RequestFactory
|
||||
from io import StringIO
|
||||
from registrar.models.domain_request import DomainRequest
|
||||
from registrar.models.domain import Domain
|
||||
from registrar.models import (
|
||||
DomainRequest,
|
||||
Domain,
|
||||
UserDomainRole,
|
||||
)
|
||||
from registrar.utility.csv_export import (
|
||||
DomainDataFull,
|
||||
DomainDataType,
|
||||
DomainDataFederal,
|
||||
DomainDataTypeUser,
|
||||
DomainGrowth,
|
||||
DomainManaged,
|
||||
DomainUnmanaged,
|
||||
|
@ -22,6 +26,7 @@ from django.core.management import call_command
|
|||
from unittest.mock import MagicMock, call, mock_open, patch
|
||||
from api.views import get_current_federal, get_current_full
|
||||
from django.conf import settings
|
||||
from django.test import RequestFactory
|
||||
from botocore.exceptions import ClientError
|
||||
import boto3_mocking
|
||||
from registrar.utility.s3_bucket import S3ClientError, S3ClientErrorCodes # type: ignore
|
||||
|
@ -204,7 +209,7 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
@less_console_noise_decorator
|
||||
def test_domain_data_type(self):
|
||||
"""Shows security contacts, domain managers, so"""
|
||||
self.maxDiff = None
|
||||
|
||||
# Add security email information
|
||||
self.domain_1.name = "defaultsecurity.gov"
|
||||
self.domain_1.save()
|
||||
|
@ -256,6 +261,57 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
self.maxDiff = None
|
||||
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
|
||||
UserDomainRole.objects.create(user=self.user, domain=self.domain_2)
|
||||
|
||||
# Create a request object
|
||||
factory = RequestFactory()
|
||||
request = factory.get("/")
|
||||
request.user = self.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),"big_lebowski@dude.co, info@example.com, meoward@rocks.com",'
|
||||
"woofwardthethird@rocks.com\n"
|
||||
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,(blank),"
|
||||
'"info@example.com, meoward@rocks.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)
|
||||
|
||||
@less_console_noise_decorator
|
||||
def test_domain_data_full(self):
|
||||
"""Shows security contacts, filtered by state"""
|
||||
|
@ -366,8 +422,8 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
# Call the export functions
|
||||
DomainGrowth.export_data_to_csv(
|
||||
csv_file,
|
||||
self.start_date.strftime("%Y-%m-%d"),
|
||||
self.end_date.strftime("%Y-%m-%d"),
|
||||
start_date=self.start_date.strftime("%Y-%m-%d"),
|
||||
end_date=self.end_date.strftime("%Y-%m-%d"),
|
||||
)
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
@ -408,8 +464,8 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
# Call the export functions
|
||||
DomainManaged.export_data_to_csv(
|
||||
csv_file,
|
||||
self.start_date.strftime("%Y-%m-%d"),
|
||||
self.end_date.strftime("%Y-%m-%d"),
|
||||
start_date=self.start_date.strftime("%Y-%m-%d"),
|
||||
end_date=self.end_date.strftime("%Y-%m-%d"),
|
||||
)
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
@ -446,7 +502,7 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
# Create a CSV file in memory
|
||||
csv_file = StringIO()
|
||||
DomainUnmanaged.export_data_to_csv(
|
||||
csv_file, self.start_date.strftime("%Y-%m-%d"), self.end_date.strftime("%Y-%m-%d")
|
||||
csv_file, start_date=self.start_date.strftime("%Y-%m-%d"), end_date=self.end_date.strftime("%Y-%m-%d")
|
||||
)
|
||||
|
||||
# Reset the CSV file's position to the beginning
|
||||
|
@ -493,8 +549,8 @@ class ExportDataTest(MockDbForIndividualTests, MockEppLib):
|
|||
# Call the export functions
|
||||
DomainRequestGrowth.export_data_to_csv(
|
||||
csv_file,
|
||||
self.start_date.strftime("%Y-%m-%d"),
|
||||
self.end_date.strftime("%Y-%m-%d"),
|
||||
start_date=self.start_date.strftime("%Y-%m-%d"),
|
||||
end_date=self.end_date.strftime("%Y-%m-%d"),
|
||||
)
|
||||
# Reset the CSV file's position to the beginning
|
||||
csv_file.seek(0)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue