Commit 7eb294a6 authored by mashony's avatar mashony
Browse files

fix(migrations): update registrationDetails migration

parent d73c79cf
......@@ -5,22 +5,27 @@ CURRENT_DATETIME = datetime.datetime(2021, 7, 1)
def get_item_registration_details(item):
item_registration_details = item.get("registrationDetails", {})
registration_id = item_registration_details.get("registrationID")
if not registration_id:
registration_id = "0"
registration_date = item_registration_details.get("registrationDate")
if not registration_date:
registration_date = CURRENT_DATETIME
registration_status = item_registration_details.get("registrationStatus")
if not registration_status:
registration_status = "properlyRegistered"
return {
"registrationStatus": registration_status,
"registrationDate": registration_date,
"registrationID": registration_id,
}
item_registration_details['registrationStatus'] = registration_status
if registration_status == "properlyRegistered":
registration_id = item_registration_details.get("registrationID")
if not registration_id:
registration_id = "0"
item_registration_details['registrationID'] = registration_id
registration_date = item_registration_details.get("registrationDate")
if not registration_date:
registration_date = CURRENT_DATETIME
item_registration_details['registrationDate'] = registration_date
elif "registrationID" in item_registration_details:
registration_id = item_registration_details.get("registrationID")
if not registration_id:
item_registration_details.pop("registrationID", None)
return item_registration_details
def apply(data):
......
......@@ -18,44 +18,43 @@ def prev_obj():
class Test033Migration:
@pytest.mark.parametrize("data_to_update, expected_data", [
({}, {}),
({"registrationStatus": None}, {"registrationStatus": "properlyRegistered"}),
({"registrationStatus": ""}, {"registrationStatus": "properlyRegistered"}),
({"registrationStatus": __NO_KEY__}, {"registrationStatus": "properlyRegistered"}),
({"registrationStatus": "registrationIsNotRequired"}, {"registrationStatus": "registrationIsNotRequired"}),
({"registrationID": None}, {"registrationID": "0"}),
({"registrationID": ""}, {"registrationID": "0"}),
({"registrationID": __NO_KEY__}, {"registrationID": "0"}),
({"registrationID": "5749853jvdsd"}, {"registrationID": "5749853jvdsd"}),
({"registrationDate": None}, {"registrationDate": datetime.datetime(2021, 7, 1)}),
({"registrationDate": __NO_KEY__}, {"registrationDate": datetime.datetime(2021, 7, 1)}),
({"registrationDate": datetime.datetime(2021, 9, 1)},
{"registrationDate": datetime.datetime(2021, 9, 1)}),
@pytest.mark.parametrize("broken_data, expected_data", [
({}, {
"registrationStatus": "properlyRegistered",
"registrationID": "0",
"registrationDate": datetime.datetime(2021, 7, 1),
}),
({"registrationID": "999999"}, {
"registrationStatus": "properlyRegistered",
"registrationID": "999999",
"registrationDate": datetime.datetime(2021, 7, 1),
}),
({"registrationDate": datetime.datetime(2021, 9, 1)}, {
"registrationStatus": "properlyRegistered",
"registrationID": "0",
"registrationDate": datetime.datetime(2021, 9, 1),
}),
({"registrationStatus": "registrationIsNotRequired"}, {
"registrationStatus": "registrationIsNotRequired"
}),
({"registrationStatus": "registrationIsNotRequired", "registrationID": ""}, {
"registrationStatus": "registrationIsNotRequired"
}),
({"registrationStatus": "registrationIsNotRequired", "registrationID": None}, {
"registrationStatus": "registrationIsNotRequired"
}),
({"registrationDate": datetime.datetime(2021, 9, 1),
"registrationStatus": "registrationIsNotRequired"}, {
"registrationStatus": "registrationIsNotRequired",
"registrationDate": datetime.datetime(2021, 9, 1),
}),
])
def test_migration_apply(self, prev_obj, data_to_update, expected_data):
default_data = {
"registrationStatus": "oldRegistration",
"registrationID": "543543",
"registrationDate": datetime.datetime.now(),
}
broken_data = {**default_data}
for key, item in data_to_update.items():
if item == __NO_KEY__:
broken_data.pop(key)
else:
broken_data[key] = item
def test_migration_apply(self, prev_obj, broken_data, expected_data):
item_key = list(prev_obj['items'].keys())[0]
prev_obj['items'][item_key]['registrationDetails'] = broken_data
migrate_data = _migrate(prev_obj)
data_to_check = {**default_data, **expected_data}
item_data = prev_obj['items'][item_key]['registrationDetails']
assert item_data['registrationStatus'] == data_to_check['registrationStatus']
assert item_data['registrationDate'] == data_to_check['registrationDate']
assert item_data['registrationID'] == data_to_check['registrationID']
assert item_data == expected_data
load_procedure(migrate_data)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment