Skip to content

Commit

Permalink
UPDATE product_footprint.py - make validity_period optional so it can…
Browse files Browse the repository at this point in the history
… be built off ref_period
  • Loading branch information
JohnVonNeumann committed Sep 13, 2024
1 parent bd1333a commit 2568782
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def __init__(
updated (DateTime | None): The date and time when the ProductFootprint was last updated.
status (ProductFootprintStatus): The status of the ProductFootprint.
status_comment (str | None): A comment describing the status of the ProductFootprint.
validity_period (ValidityPeriod): The validity period for the ProductFootprint.
validity_period (ValidityPeriod | None): The validity period for the ProductFootprint.
company_name (str): The name of the company that owns the ProductFootprint.
company_ids (list[CompanyId]): A list of CompanyIds for the company that owns the ProductFootprint.
product_description (str): A description of the product.
Expand Down
19 changes: 16 additions & 3 deletions tests/product_footprint/test_product_footprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from datetime import datetime

from pathfinder_framework.carbon_footprint.biogenic_accounting_methodology import BiogenicAccountingMethodology
from pathfinder_framework.carbon_footprint.carbon_footprint import CarbonFootprint
from pathfinder_framework.assurance.assurance import (
Assurance,
Expand Down Expand Up @@ -61,7 +62,7 @@ def version() -> Version:

@pytest.fixture(scope="module")
def start_and_end_time() -> (DateTime, DateTime):
return DateTime.now(), DateTime.now()
return DateTime.now(), DateTime.create_datetime_years_from_now(3)


@pytest.fixture
Expand Down Expand Up @@ -114,6 +115,7 @@ def valid_carbon_footprint_data(start_and_end_time):
standard_name="Example standard name",
comments="Example comments",
),
"biogenic_accounting_methodology": BiogenicAccountingMethodology.GHGP
}


Expand All @@ -123,7 +125,7 @@ def carbon_footprint(valid_carbon_footprint_data):


@pytest.fixture
def valid_product_footprint_data(valid_carbon_footprint_data):
def valid_product_footprint_data(valid_carbon_footprint_data, carbon_footprint):
company_ids = [
CompanyId("urn:pathfinder:company:customcode:buyer-assigned:acme-corp")
]
Expand All @@ -134,7 +136,7 @@ def valid_product_footprint_data(valid_carbon_footprint_data):
valid_cpc = cpc_code_lookup.lookup("0111")
version = Version(1)

validity_period = ValidityPeriod(start=DateTime.now(), end=DateTime.now())
validity_period = ValidityPeriod(reference_period_end=carbon_footprint.reference_period.end)
extensions = [
DataModelExtension(
spec_version="2.0.0",
Expand Down Expand Up @@ -317,6 +319,17 @@ def test_product_footprint_empty_validity_period(valid_product_footprint_data):
assert isinstance(product_footprint.validity_period, ValidityPeriod)


def test_product_footprint_default_reference_period(valid_product_footprint_data):
product_footprint = ProductFootprint(**valid_product_footprint_data)
# The start date of the validity period should be equal to the end date of the reference period.
expected_start_date = product_footprint.pcf.reference_period.end
assert DateTime.same_day(product_footprint.validity_period.start, expected_start_date)

# The end date should be 3 years after the start date.
expected_end_date = ValidityPeriod.three_years_from_end(product_footprint.validity_period.start)
assert product_footprint.validity_period.end == expected_end_date


@pytest.mark.parametrize("company_name", [123, 1.0, None, [], {}, ""])
def test_product_footprint_invalid_company_name(
valid_product_footprint_data, company_name
Expand Down

0 comments on commit 2568782

Please sign in to comment.