Beispiel #1
0
def test_edit_undo_apply(model_name, field_name, old_value, new_value,
                         create_user, ahj_obj, expected_value,
                         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',
        'EditType': 'U',
        'AHJPK': ahj_obj
    }
    edit = Edit.objects.create(**edit_dict)
    views_edits.apply_edits(ready_edits=[edit])
    views_edits.edit_undo_apply(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
Beispiel #2
0
def test_edit_update__normal_use(ahj_obj,
                                 generate_client_with_webpage_credentials):
    client = generate_client_with_webpage_credentials(Username='******')
    user = User.objects.get(Username='******')
    inspection = AHJInspection.objects.create(AHJPK=ahj_obj,
                                              AHJInspectionName='Inspection1',
                                              TechnicianRequired=1,
                                              InspectionStatus=True)
    url = reverse('edit-update')
    input = [{
        'AHJPK': ahj_obj.AHJPK,
        'SourceTable': 'AHJInspection',
        'SourceRow': inspection.pk,
        'SourceColumn': 'AHJInspectionName',
        'NewValue': 'NewName'
    }]
    response = client.post(url, input, format='json')
    assert response.status_code == 200
    edit = Edit.objects.get(
        AHJPK=ahj_obj.AHJPK
    )  # Got newly created edit object and set it as approved
    edit.ReviewStatus = 'A'
    edit.DateEffective = timezone.now()
    edit.ApprovedBy = user
    edit.save()
    views_edits.apply_edits(
    )  # Now that it's approved, apply edits will apply it.
    Inspection = AHJInspection.objects.get(AHJPK=ahj_obj)
    assert Inspection.AHJInspectionName == 'NewName'
Beispiel #3
0
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)
Beispiel #4
0
def test_apply_edits(ReviewStatus, DateEffective, create_user, ahj_obj):
    field_name = 'AHJName'
    old_value = 'oldname'
    new_value = 'newname'
    user = create_user()
    set_obj_field(ahj_obj, field_name, old_value)
    edit_dict = {
        'ChangedBy': user,
        'ApprovedBy': user if DateEffective is not None else None,
        'SourceTable': 'AHJ',
        'SourceRow': ahj_obj.pk,
        'SourceColumn': field_name,
        'OldValue': old_value,
        'NewValue': new_value,
        'DateRequested': timezone.now(),
        'DateEffective': DateEffective,
        'ReviewStatus': ReviewStatus,
        'IsApplied': False,
        'EditType': 'U',
        'AHJPK': ahj_obj
    }
    edit = Edit.objects.create(**edit_dict)
    views_edits.apply_edits()
    ahj = AHJ.objects.get(AHJPK=ahj_obj.AHJPK)
    is_date_effective = (DateEffective.date() == datetime.date.today()
                         ) if DateEffective is not None else False
    edit_should_apply = is_date_effective and ReviewStatus == 'A'
    edit_is_applied = getattr(ahj, field_name) == new_value
    assert edit_is_applied == edit_should_apply
    edit = Edit.objects.get(EditID=edit.EditID)
    assert edit.IsApplied == edit_should_apply
def test_approve_edit(apply_now, create_user, ahj_obj):
    user = create_user()
    edit = Edit.objects.create(AHJPK=ahj_obj,
                               ChangedBy=user,
                               EditType='U',
                               SourceTable='AHJ',
                               SourceColumn='AHJName',
                               SourceRow=ahj_obj.pk,
                               NewValue='NewName',
                               DateRequested=timezone.now())
    admin_actions.approve_edit(edit, user, timezone.now(), apply_now)
    edit = Edit.objects.get(EditID=edit.EditID)
    ahj = AHJ.objects.get(AHJPK=ahj_obj.pk)
    assert edit.ApprovedBy.UserID == user.UserID
    assert edit.DateEffective.date() == datetime.date.today()
    assert edit.ReviewStatus == 'A'
    if apply_now:
        assert ahj.AHJName == 'NewName'
    else:
        ahj = AHJ.objects.get(AHJPK=ahj_obj.pk)
        assert ahj.AHJName != 'NewName'
        # NOTE: apply_edits is tested separately in test_view_edits.py
        apply_edits()
        ahj = AHJ.objects.get(AHJPK=ahj_obj.pk)
        assert ahj.AHJName == 'NewName'
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
Beispiel #7
0
def test_proc():
    if settings.APPLY_APPROVED_EDITS:
        apply_edits()
Beispiel #8
0
def edits_take_effect():
    if settings.APPLY_APPROVED_EDITS:
        apply_edits()