Fix test cases + logging fixes

This commit is contained in:
zandercymatics 2023-11-08 16:32:02 -07:00
parent 1ad40cc709
commit 9409b3f41c
No known key found for this signature in database
GPG key ID: FF4636ABEC9682B7
5 changed files with 20 additions and 16 deletions

View file

@ -339,7 +339,7 @@ class Command(BaseCommand):
try: try:
data = json.load(jsonFile) data = json.load(jsonFile)
# Create an instance of TransitionDomainArguments # Create an instance of TransitionDomainArguments
has_desired_args = False
# Iterate over the data from the JSON file # Iterate over the data from the JSON file
for key, value in data.items(): for key, value in data.items():
# Check if the key exists in TransitionDomainArguments # Check if the key exists in TransitionDomainArguments

View file

@ -269,7 +269,7 @@ class Command(BaseCommand):
if file_directory and file_directory[-1] != "/": if file_directory and file_directory[-1] != "/":
file_directory += "/" file_directory += "/"
json_filepath = file_directory+migration_json_filename json_filepath = migration_json_filename
"""Runs the load_transition_domain script""" """Runs the load_transition_domain script"""
# Create the command string # Create the command string
command_script = "load_transition_domain" command_script = "load_transition_domain"
@ -285,6 +285,8 @@ class Command(BaseCommand):
command_string += "--debug " command_string += "--debug "
if debug_max_entries_to_parse > 0: if debug_max_entries_to_parse > 0:
command_string += f"--limitParse {debug_max_entries_to_parse} " command_string += f"--limitParse {debug_max_entries_to_parse} "
if file_directory:
command_string += f"--directory {file_directory}"
# Execute the command string # Execute the command string
proceed = False proceed = False

View file

@ -185,11 +185,8 @@ class LoadExtraTransitionDomain:
) )
# Check if the instance has changed before saving # Check if the instance has changed before saving
#if updated_transition_domain.__dict__ != transition_domain.__dict__:
updated_transition_domain.save() updated_transition_domain.save()
updated_transition_domains.append(updated_transition_domain) updated_transition_domains.append(updated_transition_domain)
logger.info( logger.info(
f"{TerminalColors.OKCYAN}" f"{TerminalColors.OKCYAN}"
f"Successfully updated {domain_name}" f"Successfully updated {domain_name}"
@ -208,17 +205,16 @@ class LoadExtraTransitionDomain:
) )
failed_transition_domains.append(domain_name) failed_transition_domains.append(domain_name)
if self.debug:
# Display misc errors (not associated to a domain)
self.parse_logs.display_logs_by_domain_name(None)
failed_count = len(failed_transition_domains) failed_count = len(failed_transition_domains)
if failed_count == 0: if failed_count == 0:
TerminalHelper.print_conditional(self.debug, f"{TerminalHelper.array_as_string(updated_transition_domains)}") if self.debug:
for domain in updated_transition_domains:
logger.debug(domain.display_transition_domain())
logger.info( logger.info(
f"""{TerminalColors.OKGREEN} f"""{TerminalColors.OKGREEN}
============= FINISHED =============== ============= FINISHED ===============
Updated {len(updated_transition_domains)} transition domain entries: Updated {len(updated_transition_domains)} transition domain entries:
{[domain for domain in updated_transition_domains]}
{TerminalColors.ENDC} {TerminalColors.ENDC}
""" """
) )
@ -228,18 +224,20 @@ class LoadExtraTransitionDomain:
logger.error( logger.error(
f"""{TerminalColors.FAIL} f"""{TerminalColors.FAIL}
============= FINISHED WITH ERRORS =============== ============= FINISHED WITH ERRORS ===============
Updated {len(updated_transition_domains)} transition domain entries, Updated {len(updated_transition_domains)} transition domain entries:
Failed to update {failed_count} transition domain entries {[domain for domain in updated_transition_domains]}
Failed to update {failed_count} transition domain entries:
{[domain for domain in failed_transition_domains]}
{TerminalColors.ENDC} {TerminalColors.ENDC}
""" """
) )
# DATA INTEGRITY CHECK # DATA INTEGRITY CHECK
# Make sure every Transition Domain got updated # Make sure every Transition Domain got updated
total_transition_domains = TransitionDomain.objects.all().count() total_transition_domains = len(updated_transition_domains)
total_updates_made = TransitionDomain.objects.all().count() total_updates_made = TransitionDomain.objects.all().count()
if total_transition_domains != total_updates_made: if total_transition_domains != total_updates_made:
logger.error(f"""{TerminalColors.Fail} logger.error(f"""{TerminalColors.FAIL}
WARNING: something went wrong processing domain information data. WARNING: something went wrong processing domain information data.
Total Transition Domains expecting a data update: {total_transition_domains} Total Transition Domains expecting a data update: {total_transition_domains}

View file

@ -79,6 +79,10 @@ class TransitionDomain(TimeStampedModel):
) )
def __str__(self): def __str__(self):
return f"{self.username}, {self.domain_name}"
def display_transition_domain(self):
"""Displays all information about a TransitionDomain in string format"""
return ( return (
f"\n-----TRANSITION DOMAIN------\n" f"\n-----TRANSITION DOMAIN------\n"
f"domainName: {self.domain_name}, \n" f"domainName: {self.domain_name}, \n"

View file

@ -159,8 +159,8 @@ class TestMigrations(TestCase):
# STEP 2: (analyze the tables just like the # STEP 2: (analyze the tables just like the
# migration script does, but add assert statements) # migration script does, but add assert statements)
expected_total_transition_domains = 9 expected_total_transition_domains = 9
expected_total_domains = 4 expected_total_domains = 5
expected_total_domain_informations = 4 expected_total_domain_informations = 5
expected_total_domain_invitations = 7 expected_total_domain_invitations = 7
expected_missing_domains = 0 expected_missing_domains = 0