class TerminationFactory(TrackedModelMixin): class Meta: model = "regulations.Termination" target_regulation = subfactory(RegulationFactory) enacting_regulation = factory.SubFactory( RegulationFactory, # FIXME synthetic-record-order make this field transaction=factory.SelfAttribute("..transaction") ) effective_date = Dates().datetime_now
def test_starts_on_minimum_date( measure_data, date_ranges: Dates, measure_creation_pattern: MeasureCreationPattern, ): measure_data["validity_start"] = date_ranges.no_end_before( date_ranges.now).lower measure_data["goods_nomenclature"] = factories.GoodsNomenclatureFactory( valid_between=TaricDateRange(date_ranges.now, None), ) measure = measure_creation_pattern.create(**measure_data) assert measure.valid_between.lower == date_ranges.now
class QuotaEventFactory(TrackedModelMixin): class Meta: model = "quotas.QuotaEvent" subrecord_code = FuzzyChoice(QuotaEventType.values) quota_definition = factory.SubFactory(QuotaDefinitionFactory) occurrence_timestamp = factory.LazyFunction(lambda: Dates().datetime_now) @factory.lazy_attribute def data(self): now = f"{Dates().now:%Y-%m-%d}" if self.subrecord_code == "00": return { "old.balance": "0.0", "new.balance": "0.0", "imported.amount": "0.0", "last.import.date.in.allocation": now, } if self.subrecord_code == "05": return { "unblocking.date": now, } if self.subrecord_code == "10": return { "critical.state": "Y", "critical.state.change.date": now, } if self.subrecord_code == "15": return { "exhaustion.date": now, } if self.subrecord_code == "20": return { "reopening.date": now, } if self.subrecord_code == "25": return { "unsuspension.date": now, } if self.subrecord_code == "30": return { "transfer.date": now, "quota.closed": "Y", "transferred.amount": "0.0", "target.quota.definition.sid": "1", }
class RegulationFactory(TrackedModelMixin): class Meta: model = "regulations.Regulation" regulation_id = factory.Sequence(lambda n: f"R{Dates().now:%y}{n:04d}0") approved = True role_type = 1 valid_between = factory.LazyAttribute( lambda o: Dates().no_end if o.role_type == 1 else None, ) community_code = 1 regulation_group = factory.LazyAttribute( lambda o: RegulationGroupFactory( valid_between=o.valid_between, transaction=o.transaction, ) if o.role_type == 1 else None, ) information_text = string_sequence(length=50) public_identifier = factory.sequence(lambda n: f"S.I. 2021/{n}") url = factory.sequence(lambda n: f"https://legislation.gov.uk/uksi/2021/{n}")
def test_validity_range_contains_range(overall, contained, expected): dates = Dates() overall = getattr(dates, overall) contained = getattr(dates, contained) assert util.validity_range_contains_range(overall, contained) == expected
def date_ranges(name): return factory.LazyFunction(lambda: getattr(Dates(), name))
class BaseRegulationFactory(RegulationFactory): regulation_group = factory.SubFactory(RegulationGroupFactory) role_type = 1 valid_between = Dates().no_end
def end_date(name): return factory.LazyFunction(lambda: getattr(Dates(), name).upper)
def date_ranges() -> Dates: return Dates()