def test_validate_effective_date_not_in_future(session): """Assert that the effective date of change cannot be in the future.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) business, filing = common_setup(identifier, now) # The effective date _cannot_ be in the future. tomorrow = datetime(2001, 8, 6, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(tomorrow) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert err # The effective date _can_ be today. today = datetime(2001, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(today) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert not err # The effective date _can_ be in the past. yesterday = datetime(2001, 8, 4, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(yesterday) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert not err
def test_validate_effective_date_not_before_founding(session): """Assert that the effective date cannot be a date prior to their Incorporation Date.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) business, filing = common_setup(identifier, now) # The effective date _cannot_ be before their Incorporation Date. before = datetime(2000, 8, 4, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(before) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert err # The effective date _can_ be on their Incorporation Date. on = datetime(2000, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(on) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert not err # The effective date _can_ be after their Incorporation Date. after = datetime(2000, 8, 6, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(after) filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert not err
def test_business_comment_json_output(session, client, jwt): """Assert the json output of a comment is correctly formatted.""" identifier = 'CP7654321' b = factory_business(identifier) u = User(username='******', firstname='firstname', lastname='lastname', sub='sub', iss='iss') u.save() now = datetime.datetime(1970, 1, 1, 0, 0).replace(tzinfo=datetime.timezone.utc) with freeze_time(now): factory_business_comment(b, 'some specific text', u) rv = client.get(f'/api/v2/businesses/{identifier}/comments', headers=create_header(jwt, [STAFF_ROLE])) assert HTTPStatus.OK == rv.status_code assert 'some specific text' == rv.json.get('comments')[0].get( 'comment').get('comment') assert 'firstname lastname' == rv.json.get('comments')[0].get( 'comment').get('submitterDisplayName') assert now.isoformat() == rv.json.get('comments')[0].get( 'comment').get('timestamp')
def test_validate_effective_date_not_before_founding(session): """Assert the filing is not before the business was founded. Rules: - The effective date cannot be a date prior to their Incorporation Date """ # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) business, filing = common_setup(identifier, now) # The effective date cannot be a date prior to their Incorporation Date effective_date = now - datedelta.DAY business.founding_date = now filing['filing']['header']['effectiveDate'] = effective_date.isoformat() with freeze_time(now): err = validate_effective_date(business, filing) assert err business.founding_date = now - datedelta.YEAR with freeze_time(now): err = validate_effective_date(business, filing) assert not err
def test_effective_date_sanity_check(session): """Assert that a COD with a valid effective date passes validation.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) filing_json = copy.deepcopy(FILING_HEADER) filing_json['filing']['header']['effectiveDate'] = ( now - datedelta.MONTH).isoformat() filing_json['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) business = Business(identifier=identifier, founding_date=now - datedelta.datedelta(years=4)) business.save() # create a COD factory_completed_filing(business=business, data_dict=filing_json, filing_date=(now - datedelta.MONTH)) # move the COD to now filing_json['filing']['header']['effectiveDate'] = now.isoformat() with freeze_time(now): err = validate_effective_date(business, filing_json) assert not err
def test_validate_effective_date_not_before_other_AR_with_COD( session): # noqa: N802; COD is an acronym """Assert that the filing ordering rules are correct. Rules: - The effective date of change cannot be a date that is farther in the past as a previous COD filing(Standalone or AR). """ # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) filing_ar = copy.deepcopy(ANNUAL_REPORT) filing_ar['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) business = Business(identifier=identifier, founding_date=now - datedelta.datedelta(years=4)) business.save() # create a COD factory_completed_filing(business=business, data_dict=filing_ar, filing_date=now) # move the COD BACK a MONTH filing_ar['filing']['header']['effectiveDate'] = ( now - datedelta.MONTH).isoformat() # The effective date of change cannot be before the previous COD with freeze_time(now): err = validate_effective_date(business, filing_ar) assert err
def test_effective_date_sanity_check(session): """Assert that a COD with a valid effective date passes validation.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) business, filing = common_setup(identifier, now) with freeze_time(now): err = validate_effective_date(business, filing) assert not err
def test_validate_effective_date_not_in_future(session): """Assert that the effective date of change cannot be in the future.""" # setup identifier = 'CP1234567' now = datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc) business, filing = common_setup(identifier, now) # The effective date of change cannot be in the future with freeze_time(now): err = validate_effective_date(business, filing) assert not err
def test_is_future_effective(session): """Assert that is_future_effective property works as expected.""" filing = Filing() filing_type = 'bogus type' filing.storage.filing_json = {'filing': {'header': {'name': filing_type}}} filing.storage._payment_token = '12345' filing.storage._filing_type = filing_type now = datetime(2019, 7, 1) with freeze_time(now): filing.storage.effective_date = now assert not filing.is_future_effective filing.storage.payment_completion_date = now assert not filing.is_future_effective
def get_ar_dates(self, next_ar_year): """Get ar min and max date for the specific year.""" ar_min_date = datetime(next_ar_year, 1, 1).date() ar_max_date = datetime(next_ar_year, 12, 31).date() if self.legal_type == self.LegalTypes.COOP.value: # This could extend by moving it into a table with start and end date against each year when extension # is required. We need more discussion to understand different scenario's which can come across in future. if next_ar_year == 2020: # For year 2020, set the max date as October 31th next year (COVID extension). ar_max_date = datetime(next_ar_year + 1, 10, 31).date() else: # If this is a CO-OP, set the max date as April 30th next year. ar_max_date = datetime(next_ar_year + 1, 4, 30).date() elif self.legal_type == self.LegalTypes.BCOMP.value: # For BCOMP min date is next anniversary date. ar_min_date = datetime(next_ar_year, self.founding_date.month, self.founding_date.day).date() ar_max_date = ar_min_date + datedelta.datedelta(days=60) if ar_max_date > datetime.utcnow().date(): ar_max_date = datetime.utcnow().date() return ar_min_date, ar_max_date
def test_set_effective(session): """Assert that the core filing is saved to the backing store.""" now = datetime(2021, 9, 17, 7, 36, 43, 903557, tzinfo=timezone.utc) with freeze_time(now): payment_date = now + datedelta.DAY filing = Filing() filing_type = 'annualReport' filing.json = ANNUAL_REPORT filing.save() filing.storage._payment_token = '12345' filing.storage._filing_type = filing_type filing.storage.effective_date = now filing._storage.skip_status_listener = True filing._storage.payment_completion_date = payment_date filing._storage.save() filing.storage.set_processed() # assert that the effective date is the payment date assert filing._storage.effective_date assert filing._storage.effective_date.replace( tzinfo=None) == payment_date.replace(tzinfo=None) assert not filing.is_future_effective future_date = now + datedelta.DAY alt_payment_date = now filing._storage.skip_status_listener = True filing._storage.payment_completion_date = alt_payment_date filing._storage.save() filing.storage.set_processed() # assert that the effective date is the future date assert filing._storage.effective_date assert filing._storage.effective_date.replace( tzinfo=None) == future_date.replace(tzinfo=None) assert filing.is_future_effective
def test_validate_effective_date_not_before_other_COD( session): # noqa: N802; COD is an acronym """Assert that the effective date of change cannot be before a previous COD filing.""" # setup identifier = 'CP1234567' founding_date = datetime(2000, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) business = Business(identifier=identifier, founding_date=founding_date) business.save() now = datetime(2020, 7, 30, 12, 0, 0, 0, tzinfo=timezone.utc) # create the previous COD filing filing_cod = copy.deepcopy(FILING_HEADER) filing_cod['filing']['header']['name'] = 'changeOfDirectors' filing_cod['filing']['changeOfDirectors'] = copy.deepcopy( CHANGE_OF_DIRECTORS) filing_date = datetime(2010, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) factory_completed_filing(business=business, data_dict=filing_cod, filing_date=filing_date) # The effective date _cannot_ be before the previous COD. before = datetime(2010, 8, 4, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(before) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert err # The effective date _can_ be on the same date as the previous COD. on = datetime(2010, 8, 5, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(on) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert not err # The effective date _can_ be after the previous COD. after = datetime(2010, 8, 6, 12, 0, 0, 0, tzinfo=timezone.utc) effective_date = as_effective_date(after) filing_cod['filing']['header']['effectiveDate'] = effective_date.isoformat( ) with freeze_time(now): err = validate_effective_date(business, filing_cod) assert not err
import datedelta import pytest from freezegun import freeze_time from registry_schemas.example_data import CHANGE_OF_DIRECTORS, FILING_HEADER from legal_api.models import Business from legal_api.services.filings import validate from legal_api.utils.datetime import datetime, timezone from tests.unit.services.filings.validations import lists_are_equal @pytest.mark.parametrize( 'test_name, now, delivery_region_1, delivery_country_1, delivery_region_2, delivery_country_2,' 'expected_code, expected_msg', [ ('SUCCESS', datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc), 'BC', 'CA', 'BC', 'CA', None, None), ('SUCCESS-NON_CA_COUNTRY', datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc), 'AM', 'DE', 'AM', 'DE', None, None), ('Director[1] Nonsense Country', datetime(2001, 8, 5, 0, 0, 0, 0, tzinfo=timezone.utc), 'BC', 'CA', 'BC', 'nonsense', HTTPStatus.BAD_REQUEST, [{ 'error': 'Address Country must resolve to a valid ISO-2 country.', 'path': '/filing/changeOfDirectors/directors/1/deliveryAddress/addressCountry' }]), ]) def test_validate_cod_basic(session, test_name, now, delivery_region_1, delivery_country_1, delivery_region_2,