Skip to content

Commit

Permalink
test: remove potential side effects of test infrastructure
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jan 21, 2025
1 parent 683990a commit fdab5dd
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,31 +142,43 @@ def build(cls):
@classmethod
def pare_data_single_product_flaring(cls):
# Pare down build data to data needed for this test
ReportProductEmissionAllocation.objects.exclude(emission_category_id=1).delete()
ReportProduct.objects.exclude(product_id=1).delete()
ReportEmission.objects.exclude(gas_type_id=1).delete()
t = cls.build()
t.allocation_2.delete()
t.allocation_3.delete()
t.allocation_4.delete()
t.allocation_5.delete()
t.allocation_6.delete()
t.report_product_2.delete()
t.report_product_3.delete()
t.report_emission_2.delete()
t.report_emission_3.delete()
t.report_emission_4.delete()
return t

@classmethod
def pare_data_remove_reporting_only(cls):
# Pare down build data to data needed for this test
ReportProductEmissionAllocation.objects.filter(emission_category__in=[5, 12]).delete()
ReportEmission.objects.filter(gas_type_id=3).delete()
t = cls.build()
t.allocation_4.delete()
t.allocation_5.delete()
t.report_emission_4.delete()
return t

@classmethod
def reporting_year_2025(cls):
t = cls.build()
reporting_year = make_recipe(
"reporting.tests.utils.reporting_year",
reporting_year=2025,
reporting_window_start='2025-12-31 16:00:00-08',
reporting_window_end='2026-12-31 16:00:00-08',
report_due_date='2025-05-31 16:59:59.999-07',
)
report = Report.objects.get(reporting_year_id=2024)
report.reporting_year = reporting_year
report.save()
Report.objects.filter(pk=t.report_1.id).update(reporting_year=reporting_year)
return t

@classmethod
def new_entrant(cls):
operation = Operation.objects.get(name='test sfo')
operation.registration_purpose = 'New Entrant Operation'
operation.save()
t = cls.build()
Operation.objects.filter(pk=t.operation_1.id).update(registration_purpose='New Entrant Operation')
return t
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
class TestComplianceSummaryServiceClass(TestCase):
def test_compliance_summary_only_flaring_single_product(self):
# Assertion values from compliance_class_manual_calcs.xlsx sheet 1
build_data = ComplianceTestInfrastructure.build()
ComplianceTestInfrastructure.pare_data_single_product_flaring()
build_data = ComplianceTestInfrastructure.pare_data_single_product_flaring()

result = ComplianceService.get_calculated_compliance_data(build_data.report_version_1.id)

Expand All @@ -19,8 +18,7 @@ def test_compliance_summary_only_flaring_single_product(self):

def test_with_industrial_process_emissions(self):
# Assertion values from compliance_class_manual_calcs.xlsx sheet 2
build_data = ComplianceTestInfrastructure.build()
ComplianceTestInfrastructure.pare_data_remove_reporting_only()
build_data = ComplianceTestInfrastructure.pare_data_remove_reporting_only()

result = ComplianceService.get_calculated_compliance_data(build_data.report_version_1.id)

Expand All @@ -46,8 +44,7 @@ def test_compliance_summary_with_all_data(self):

def test_compliance_summary_2025_period(self):
# Assertion values from compliance_class_manual_calcs.xlsx sheet 4
build_data = ComplianceTestInfrastructure.build()
ComplianceTestInfrastructure.reporting_year_2025()
build_data = ComplianceTestInfrastructure.reporting_year_2025()

result = ComplianceService.get_calculated_compliance_data(build_data.report_version_1.id)

Expand All @@ -59,8 +56,7 @@ def test_compliance_summary_2025_period(self):
assert result.credited_emissions == 0

def test_new_entrant(self):
build_data = ComplianceTestInfrastructure.build()
ComplianceTestInfrastructure.new_entrant()
build_data = ComplianceTestInfrastructure.new_entrant()
## TESTS ##
result = ComplianceService.get_calculated_compliance_data(build_data.report_version_1.id)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,10 @@ def test_get_regulatory_values_by_naics_code(self):
report_version_1 = make_recipe("reporting.tests.utils.report_version")
report_version_2 = make_recipe("reporting.tests.utils.report_version")
# Override parent values auto-generated by recipe
operation = Operation.objects.get(pk=report_version_1.report.operation.id)
report = Report.objects.get(pk=report_version_1.report_id)
operation.naics_code_id = 1
operation.save()
report.reporting_year_id = 2024
report.save()
operation = Operation.objects.get(pk=report_version_2.report.operation.id)
report = Report.objects.get(pk=report_version_2.report_id)
operation.naics_code_id = 22
operation.save()
report.reporting_year_id = 2024
report.save()
Operation.objects.filter(pk=report_version_1.report.operation.id).update(naics_code_id=1)
Report.objects.filter(pk=report_version_1.report_id).update(reporting_year_id=2024)
Operation.objects.filter(pk=report_version_2.report.operation.id).update(naics_code_id=22)
Report.objects.filter(pk=report_version_2.report_id).update(reporting_year_id=2024)

## TESTS ##
# Test service function returns correct values
Expand Down Expand Up @@ -251,9 +243,7 @@ def test_get_reporting_only_allocated(self):
emission_category=EmissionCategory.objects.get(pk=1),
allocated_quantity=Decimal('12.0'),
)
rp = ReportProduct.objects.get(pk=fog_product_allocation.report_product_id)
rp.product_id = 39
rp.save()
ReportProduct.objects.filter(pk=fog_product_allocation.report_product_id).update(product_id=39)

# Correctly aggregates reporting-only emissions when there is a fog product
reporting_only_with_fog_for_test = ComplianceService.get_reporting_only_allocated(
Expand Down

0 comments on commit fdab5dd

Please sign in to comment.