galatea-associates / fuse-test-data-gen

Repository for the Galatea internal data generator tool, used for generating domain data for POCs
0 stars 0 forks source link

Amend Account attribute "closing_date" #215

Closed WilfGala closed 4 years ago

WilfGala commented 4 years ago

Issue Description

The 'Expected Values' column of the data model attributes specification found on google drive states that the Account domain object's closing_date attribute should take the following values:

Empty or String date of form YYYYMMDD

Currently it is set to only take the latter of the two options (the string date of form YYYYMMDD) and not Empty

Design

account_factory.py

Amend the __create_closing_date method in the AccountFactory class of account_factory.py to return either a date string as currently implemented, or the string "Empty". To save time consider deciding which to return before evaluating the date, eg:

def __create_closing_date(self, opening_date):
    if random.getrandbits(1): # fastest way to flip a coin
        return "Empty"
    else:
        from_year = int(opening_date[:4])
        from_month = int(opening_date[4:6])
        from_day = int(opening_date[6:])
        return self.create_random_date(from_year=from_year,
            from_month=from_month,
            from_day=from_day).strftime('%Y%m%d')

account_test.py

The closing_date_valid method in account_test.py should be amended to check the new return value, possibly using a regex to check all cases like so:

def closing_date_valid(record):
    closing_date = record["closing_date"]
    if re.match("^[0-9]{8}$", closing_date):
        date_valid(closing_date)
        opening_date = record["opening_date"]
        o_year, o_month, o_day = int(opening_date[:4]), int(opening_date[4:6]),\
            int(opening_date[6:])
        c_year, c_month, c_day = int(closing_date[:4]), int(closing_date[4:6]),\
            int(closing_date[6:])
        assert datetime(o_year, o_month, o_day) <= datetime(c_year, c_month, c_day)
    else:
        assert closing_date == "Empty"

Documentation Changes

Amend __create_closing_date and closing_date_valid docstrings to account for new possible return value

Test Evidence

Newly written test should pass

Validation in Develop

Output from running python src/app.py should be as expected.