mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-05-20 03:19:24 +02:00
Merge remote-tracking branch 'origin/za/additional-data-transferred-domains' into za/additional-data-transferred-domains
This commit is contained in:
commit
2dd54de3dd
4 changed files with 59 additions and 17 deletions
|
@ -324,6 +324,7 @@ class Command(BaseCommand):
|
|||
**options,
|
||||
):
|
||||
"""Parse the data files and create TransitionDomains."""
|
||||
args = TransitionDomainArguments(**options)
|
||||
### Process JSON file ###
|
||||
# If a JSON was provided, use its values instead of defaults.
|
||||
# TODO: there is no way to discern user overrides from those arg’s defaults.
|
||||
|
@ -332,7 +333,7 @@ class Command(BaseCommand):
|
|||
try:
|
||||
data = json.load(jsonFile)
|
||||
# Create an instance of TransitionDomainArguments
|
||||
args = TransitionDomainArguments()
|
||||
|
||||
# Iterate over the data from the JSON file
|
||||
for key, value in data.items():
|
||||
# Check if the key exists in TransitionDomainArguments
|
||||
|
@ -346,32 +347,57 @@ class Command(BaseCommand):
|
|||
""")
|
||||
raise err
|
||||
|
||||
sep = options.get("sep")
|
||||
sep = args.sep
|
||||
|
||||
# If --resetTable was used, prompt user to confirm
|
||||
# deletion of table data
|
||||
if options.get("resetTable"):
|
||||
if args.resetTable:
|
||||
self.prompt_table_reset()
|
||||
|
||||
# Get --debug argument
|
||||
debug_on = options.get("debug")
|
||||
debug_on = args.debug
|
||||
|
||||
# Get --LimitParse argument
|
||||
debug_max_entries_to_parse = int(
|
||||
options.get("limitParse")
|
||||
args.limitParse
|
||||
) # set to 0 to parse all entries
|
||||
|
||||
## Variables for Additional TransitionDomain Information ##
|
||||
|
||||
# Desired directory for additional TransitionDomain data
|
||||
# (In the event they are stored seperately)
|
||||
directory = options.get("directory")
|
||||
directory = args.directory
|
||||
# Add a slash if the last character isn't one
|
||||
if directory and directory[-1] != "/":
|
||||
directory += "/"
|
||||
|
||||
# Main script filenames
|
||||
# TODO: @ZANDER to replace this with new TransitionDomainArgument object
|
||||
domain_contacts_filename = directory + "/" + options.get("domain_contacts_filename")
|
||||
contacts_filename = directory + "/" + options.get("contacts_filename")
|
||||
domain_statuses_filename = directory + "/" + options.get("domain_statuses_filename")
|
||||
# Main script filenames - these do not have defaults
|
||||
domain_contacts_filename = None
|
||||
try:
|
||||
domain_contacts_filename = directory + options.get("domain_contacts_filename")
|
||||
except TypeError as err:
|
||||
logger.error(
|
||||
f"Invalid filename of '{args.domain_contacts_filename}'"
|
||||
" was provided for domain_contacts_filename"
|
||||
)
|
||||
|
||||
contacts_filename = None
|
||||
try:
|
||||
contacts_filename = directory + options.get("contacts_filename")
|
||||
except TypeError as err:
|
||||
logger.error(
|
||||
f"Invalid filename of '{args.contacts_filename}'"
|
||||
" was provided for contacts_filename"
|
||||
)
|
||||
|
||||
domain_statuses_filename = None
|
||||
try:
|
||||
domain_statuses_filename = directory + options.get("domain_statuses_filename")
|
||||
except TypeError as err:
|
||||
logger.error(
|
||||
f"Invalid filename of '{args.domain_statuses_filename}'"
|
||||
" was provided for domain_statuses_filename"
|
||||
)
|
||||
|
||||
# Agency information
|
||||
agency_adhoc_filename = options.get("agency_adhoc_filename")
|
||||
|
@ -593,7 +619,7 @@ class Command(BaseCommand):
|
|||
|
||||
# Prompt the user if they want to load additional data on the domains
|
||||
title = "Do you wish to load additional data for TransitionDomains?"
|
||||
do_parse_extra = TerminalHelper.prompt_for_execution(
|
||||
proceed = TerminalHelper.prompt_for_execution(
|
||||
system_exit_on_terminate=False,
|
||||
info_to_inspect=f"""
|
||||
!!! ENSURE THAT ALL FILENAMES ARE CORRECT BEFORE PROCEEDING
|
||||
|
@ -617,6 +643,6 @@ class Command(BaseCommand):
|
|||
""",
|
||||
prompt_title=title,
|
||||
)
|
||||
if do_parse_extra:
|
||||
if proceed:
|
||||
arguments = TransitionDomainArguments(**options)
|
||||
self.parse_extra(arguments)
|
||||
|
|
|
@ -294,7 +294,7 @@ class Command(BaseCommand):
|
|||
command_script = "load_transition_domain"
|
||||
command_string = (
|
||||
f"./manage.py {command_script} "
|
||||
f"{file_location+migration_json_filename}"
|
||||
f"{file_location+migration_json_filename} "
|
||||
)
|
||||
if sep is not None and sep != "|":
|
||||
command_string += f"--sep {sep} "
|
||||
|
|
|
@ -176,6 +176,7 @@ class LoadExtraTransitionDomain:
|
|||
|
||||
# Check if the instance has changed before saving
|
||||
#if updated_transition_domain.__dict__ != transition_domain.__dict__:
|
||||
|
||||
updated_transition_domain.save()
|
||||
updated_transition_domains.append(updated_transition_domain)
|
||||
if self.debug:
|
||||
|
@ -214,6 +215,7 @@ class LoadExtraTransitionDomain:
|
|||
"""
|
||||
)
|
||||
else:
|
||||
# TODO - update
|
||||
logger.error(
|
||||
f"""{TerminalColors.FAIL}
|
||||
============= FINISHED WITH ERRORS ===============
|
||||
|
@ -222,6 +224,9 @@ class LoadExtraTransitionDomain:
|
|||
{TerminalColors.ENDC}
|
||||
"""
|
||||
)
|
||||
# TODO
|
||||
if TransitionDomain.objects.all().count() != len(updated_transition_domains):
|
||||
logger.error("Something bad happened")
|
||||
|
||||
def parse_creation_expiration_data(self, domain_name, transition_domain):
|
||||
"""Grabs expiration_date from the parsed files and associates it
|
||||
|
@ -517,7 +522,6 @@ class LoadExtraTransitionDomain:
|
|||
def get_domain_data(self, desired_id) -> DomainAdditionalData:
|
||||
"""Grabs a corresponding row within the DOMAIN_ADDITIONAL file,
|
||||
based off a desired_id"""
|
||||
l = self.get_object_by_id(EnumFilenames.DOMAIN_ADDITIONAL, desired_id.lower())
|
||||
return self.get_object_by_id(EnumFilenames.DOMAIN_ADDITIONAL, desired_id)
|
||||
|
||||
def get_organization_adhoc(self, desired_id) -> OrganizationAdhoc:
|
||||
|
@ -545,6 +549,7 @@ class LoadExtraTransitionDomain:
|
|||
based off a desired_id"""
|
||||
return self.get_object_by_id(EnumFilenames.DOMAIN_ESCROW, desired_id)
|
||||
|
||||
# TODO - renamed / needs a return section
|
||||
def get_object_by_id(self, file_type: EnumFilenames, desired_id):
|
||||
"""Returns a field in a dictionary based off the type and id.
|
||||
|
||||
|
@ -591,7 +596,7 @@ class LoadExtraTransitionDomain:
|
|||
)
|
||||
return obj
|
||||
|
||||
|
||||
# TODO - change name
|
||||
@dataclass
|
||||
class PatternMap:
|
||||
"""Helper class that holds data and metadata about a requested file.
|
||||
|
@ -612,7 +617,6 @@ class PatternMap:
|
|||
id_field: data_type(...),
|
||||
...
|
||||
}
|
||||
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
|
@ -635,6 +639,7 @@ class PatternMap:
|
|||
self.data_type = data_type
|
||||
|
||||
### What the id should be in the holding dict ###
|
||||
# TODO - rename to id_field_name
|
||||
self.id_field = id_field
|
||||
|
||||
# Object data #
|
||||
|
@ -743,9 +748,17 @@ class ExtraTransitionDomain:
|
|||
AuthorityAdhoc,
|
||||
"authorityid",
|
||||
),
|
||||
(
|
||||
EnumFilenames.AUTHORITY_ADHOC,
|
||||
options.authority_adhoc_filename,
|
||||
AuthorityAdhoc,
|
||||
"authorityid",
|
||||
),
|
||||
]
|
||||
|
||||
self.file_data = self.populate_file_data(pattern_map_params)
|
||||
|
||||
# TODO - revise comment
|
||||
def populate_file_data(
|
||||
self, pattern_map_params: List[Tuple[EnumFilenames, str, type, str]]
|
||||
):
|
||||
|
|
|
@ -352,6 +352,8 @@ class TestMigrations(TestCase):
|
|||
)
|
||||
]
|
||||
|
||||
|
||||
#TransitionDomain.objects.filter(domain_name = "fakewebsite3.gov")
|
||||
# Afterwards, their values should be what we expect
|
||||
all_transition_domains = TransitionDomain.objects.all()
|
||||
for domain in all_transition_domains:
|
||||
|
@ -433,6 +435,7 @@ class TestMigrations(TestCase):
|
|||
expected.id = domain.id
|
||||
expected.created_at = domain.created_at
|
||||
expected.updated_at = domain.updated_at
|
||||
|
||||
self.assertEqual(domain, expected)
|
||||
|
||||
def test_transfer_transition_domains_to_domains(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue