def test_edit_reset__edit_pending_do_nothing(create_user, ahj_obj): user = create_user() old_value = 'oldname' new_value = 'newname' set_obj_field(ahj_obj, 'AHJName', old_value) edit_dict = { 'ChangedBy': user, 'ApprovedBy': None, 'SourceTable': 'AHJ', 'SourceRow': ahj_obj.pk, 'SourceColumn': 'AHJName', 'OldValue': old_value, 'NewValue': new_value, 'DateRequested': timezone.now(), 'DateEffective': None, 'ReviewStatus': 'P', 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) views_edits.reset_edit(user, edit) edit_dict['OldValue'], edit_dict['NewValue'] = old_value, edit_dict[ 'OldValue'] edit_dict['ReviewStatus'] = 'A' edit_dict['ApprovedBy'], edit_dict['DateEffective'] = user, timezone.now() assert not check_edit_exists(edit_dict) assert Edit.objects.all().count() == 1
def test_edit_reset__edit_deletion(parent_model_name, model_name, review_status, create_user, create_minimal_obj, ahj_obj): user = create_user() parent_obj = create_minimal_obj(parent_model_name) obj = create_minimal_obj(model_name) relation = obj.create_relation_to(parent_obj) set_obj_field(relation, relation.get_relation_status_field(), False if review_status == 'A' else True) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': relation.__class__.__name__, 'SourceRow': relation.pk, 'SourceColumn': relation.get_relation_status_field(), 'OldValue': True, 'NewValue': False, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': review_status, 'EditType': 'A', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) views_edits.reset_edit(user, edit) edit_dict['ApprovedBy'], edit_dict['ReviewStatus'], edit_dict[ 'DateEffective'] = None, 'P', None assert check_edit_exists(edit_dict) is True assert get_obj_field( relation, relation.get_relation_status_field()) is edit_dict['OldValue']
def test_edit_reset__edit_deletion(parent_model_name, model_name, review_status, create_user, create_minimal_obj, ahj_obj): user = create_user() parent_obj = create_minimal_obj(parent_model_name) obj = create_minimal_obj(model_name) relation = obj.create_relation_to(parent_obj) set_obj_field(relation, relation.get_relation_status_field(), review_status != 'A') edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': relation.__class__.__name__, 'SourceRow': relation.pk, 'SourceColumn': relation.get_relation_status_field(), 'OldValue': True, 'NewValue': False, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': review_status, 'IsApplied': review_status == 'A', 'EditType': 'A', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) assert views_edits.reset_edit(user, edit) edit = Edit.objects.get(EditID=edit.EditID) assert edit_is_pending(edit) assert get_obj_field( relation, relation.get_relation_status_field()) == edit_dict['OldValue']
def test_edit_reset__edit_update(model_name, field_name, old_value, new_value, create_user, ahj_obj, create_minimal_obj, expected_value, add_enums): user = create_user() obj = create_minimal_obj(model_name) set_obj_field(obj, field_name, new_value) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': model_name, 'SourceRow': obj.pk, 'SourceColumn': field_name, 'OldValue': old_value, 'NewValue': new_value, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': 'A', 'IsApplied': True, 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) assert views_edits.reset_edit(user, edit) assert edit_is_pending(edit) if expected_value == 'old_value': expected_value = get_value_or_enum_row(field_name, old_value) assert get_obj_field(obj, field_name) == expected_value
def test_edit_reset__edit_update(model_name, field_name, old_value, new_value, create_user, ahj_obj, make_later_edit, later_new_value, create_minimal_obj, expected_value, add_enums): user = create_user() obj = create_minimal_obj(model_name) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': model_name, 'SourceRow': obj.pk, 'SourceColumn': field_name, 'OldValue': old_value, 'NewValue': new_value, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': 'A', 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) edits_to_apply = [edit] if make_later_edit: edit_dict['OldValue'], edit_dict[ 'NewValue'] = new_value, later_new_value edit_dict['DateRequested'], edit_dict['DateEffective'] = timezone.now( ), timezone.now() later_edit = Edit.objects.create(**edit_dict) edits_to_apply.append(later_edit) # NOTE: apply_edits is tested separately above views_edits.apply_edits(ready_edits=edits_to_apply) views_edits.reset_edit(user, edit) if make_later_edit: edit_dict['OldValue'], edit_dict[ 'NewValue'] = later_new_value, old_value else: edit_dict['ApprovedBy'], edit_dict['ReviewStatus'], edit_dict[ 'DateEffective'] = None, 'P', None assert check_edit_exists(edit_dict) is True if expected_value == 'old_value': expected_value = get_value_or_enum_row(field_name, old_value) assert get_obj_field(obj, field_name) == expected_value
def test_edit_reset__edit_rejected_always_make_pending_only( create_user, ahj_obj): user = create_user() old_value = 'oldname' middle_value = 'newername' new_value = 'newestname' set_obj_field(ahj_obj, 'AHJName', old_value) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': 'AHJ', 'SourceRow': ahj_obj.pk, 'SourceColumn': 'AHJName', 'OldValue': old_value, 'NewValue': middle_value, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': 'R', 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) edit_dict['NewValue'] = new_value later_edit = Edit.objects.create(**edit_dict) views_edits.reset_edit(user, edit) views_edits.reset_edit(user, later_edit) edit_dict['ReviewStatus'] = 'A' edit_dict['OldValue'], edit_dict['NewValue'] = middle_value, old_value assert check_edit_exists(edit_dict) is False edit = Edit.objects.get(EditID=edit.EditID) assert edit.ReviewStatus == 'P' assert edit.ApprovedBy is None assert edit.DateEffective is None edit_dict['OldValue'], edit_dict['NewValue'] = new_value, old_value assert check_edit_exists(edit_dict) is False later_edit = Edit.objects.get(EditID=edit.EditID) assert later_edit.ReviewStatus == 'P' assert later_edit.ApprovedBy is None assert later_edit.DateEffective is None assert get_obj_field(ahj_obj, 'AHJName') == old_value
def test_edit_reset__kwargs(force_resettable, skip_undo, create_user, ahj_obj): user = create_user() old_value = 'oldname' new_value = 'newname' later_value = 'newname_later' set_obj_field(ahj_obj, 'AHJName', later_value) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': 'AHJ', 'SourceRow': ahj_obj.pk, 'SourceColumn': 'AHJName', 'OldValue': old_value, 'NewValue': new_value, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': 'A', 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) edit_dict['OldValue'], edit_dict['NewValue'] = edit_dict[ 'NewValue'], later_value later_edit = Edit.objects.create(**edit_dict) views_edits.reset_edit(user, edit, force_resettable=force_resettable, skip_undo=skip_undo) edit = Edit.objects.get(EditID=edit.EditID) if force_resettable and not skip_undo: assert get_obj_field(ahj_obj, 'AHJName') == old_value elif force_resettable and skip_undo: assert get_obj_field(ahj_obj, 'AHJName') == later_value assert edit.OldValue == later_value assert edit.NewValue == new_value assert edit.ReviewStatus == 'P' assert edit.ApprovedBy is None assert edit.DateEffective is None