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_revert__edit_addition(parent_model_name, model_name, 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(), True) edit_dict = { 'ChangedBy': user, 'ApprovedBy': user, 'SourceTable': relation.__class__.__name__, 'SourceRow': relation.pk, 'SourceColumn': relation.get_relation_status_field(), 'OldValue': None, 'NewValue': True, 'DateRequested': timezone.now(), 'DateEffective': timezone.now(), 'ReviewStatus': 'A', 'EditType': 'A', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) assert views_edits.revert_edit(user, edit) edit_dict['OldValue'], edit_dict['NewValue'] = edit_dict['NewValue'], False assert check_edit_exists(edit_dict) assert get_obj_field( relation, relation.get_relation_status_field()) == edit_dict['NewValue']
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_update_old_value_all_awaiting_apply_or_review( model_name, field_name, old_value, new_value, create_user, ahj_obj, create_minimal_obj, 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', 'IsApplied': True, 'EditType': 'U', 'AHJPK': ahj_obj } edit = Edit.objects.create(**edit_dict) edit_dict['IsApplied'] = False approved_edit = Edit.objects.create(**edit_dict) edit_dict['ReviewStatus'] = 'P' pending_edit = Edit.objects.create(**edit_dict) views_edits.apply_edits(ready_edits=[edit]) views_edits.edit_update_old_value_all_awaiting_apply_or_review(edit) approved_edit = Edit.objects.get(EditID=approved_edit.EditID) pending_edit = Edit.objects.get(EditID=pending_edit.EditID) assert approved_edit.OldValue == str(new_value) assert pending_edit.OldValue == str(new_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