mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-22 02:36:02 +02:00
Tests
This commit is contained in:
parent
bfde3076b4
commit
86441c0383
4 changed files with 59 additions and 5 deletions
|
@ -9,7 +9,7 @@ from django.urls import include, path
|
||||||
from django.views.generic import RedirectView
|
from django.views.generic import RedirectView
|
||||||
|
|
||||||
from registrar import views
|
from registrar import views
|
||||||
from registrar.views.admin_views import (
|
from registrar.views.report_views import (
|
||||||
ExportDataDomainsGrowth,
|
ExportDataDomainsGrowth,
|
||||||
ExportDataFederal,
|
ExportDataFederal,
|
||||||
ExportDataFull,
|
ExportDataFull,
|
||||||
|
|
|
@ -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):
|
||||||
|
@ -201,6 +203,7 @@ class CsvReportsTest(MockDb):
|
||||||
class ExportDataTest(MockDb, MockEppLib):
|
class ExportDataTest(MockDb, MockEppLib):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
super().setUp()
|
super().setUp()
|
||||||
|
self.factory = RequestFactory()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
super().tearDown()
|
super().tearDown()
|
||||||
|
@ -259,6 +262,55 @@ 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"""
|
||||||
|
self.maxDiff = None
|
||||||
|
# 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,,,, ,"
|
||||||
|
',dotgov@cisa.dhs.gov,"meoward@rocks.com, info@example.com, big_lebowski@dude.co, staff@example.com",'
|
||||||
|
"woofwardthethird@rocks.com\n"
|
||||||
|
"adomain2.gov,Dns needed,(blank),(blank),Interstate,,,,, ,,registrar@dotgov.gov,"
|
||||||
|
'"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.assertEqual(csv_content, expected_content)
|
||||||
|
|
||||||
@less_console_noise_decorator
|
@less_console_noise_decorator
|
||||||
def test_domain_data_full(self):
|
def test_domain_data_full(self):
|
||||||
"""Shows security contacts, filtered by state"""
|
"""Shows security contacts, filtered by state"""
|
||||||
|
@ -446,9 +498,7 @@ class ExportDataTest(MockDb, MockEppLib):
|
||||||
# Create a CSV file in memory
|
# Create a CSV file in memory
|
||||||
csv_file = StringIO()
|
csv_file = StringIO()
|
||||||
DomainUnmanaged.export_data_to_csv(
|
DomainUnmanaged.export_data_to_csv(
|
||||||
csv_file,
|
csv_file, start_date=self.start_date.strftime("%Y-%m-%d"), end_date=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
|
# Reset the CSV file's position to the beginning
|
||||||
|
|
|
@ -543,6 +543,7 @@ class DomainDataType(DomainExport):
|
||||||
"federal_agency__agency",
|
"federal_agency__agency",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class DomainDataTypeUser(DomainDataType):
|
class DomainDataTypeUser(DomainDataType):
|
||||||
"""
|
"""
|
||||||
The DomainDataType report, but sliced on the current request user
|
The DomainDataType report, but sliced on the current request user
|
||||||
|
|
|
@ -157,8 +157,10 @@ class ExportDataType(View):
|
||||||
csv_export.DomainDataType.export_data_to_csv(response)
|
csv_export.DomainDataType.export_data_to_csv(response)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class ExportDataTypeUser(View):
|
class ExportDataTypeUser(View):
|
||||||
"""Returns a domain report for a given user on the request"""
|
"""Returns a domain report for a given user on the request"""
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
# match the CSV example with all the fields
|
# match the CSV example with all the fields
|
||||||
response = HttpResponse(content_type="text/csv")
|
response = HttpResponse(content_type="text/csv")
|
||||||
|
@ -166,6 +168,7 @@ class ExportDataTypeUser(View):
|
||||||
csv_export.DomainDataTypeUser.export_data_to_csv(response, request=request)
|
csv_export.DomainDataTypeUser.export_data_to_csv(response, request=request)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class ExportDataFull(View):
|
class ExportDataFull(View):
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
# Smaller export based on 1
|
# Smaller export based on 1
|
Loading…
Add table
Add a link
Reference in a new issue