Exemple #1
0
def test_jt_existing_values_are_nonsensitive(job_template_with_ids, user_unit):
    """Assure that permission checks are not required if submitted data is
    identical to what the job template already has."""

    data = model_to_dict(job_template_with_ids)
    access = JobTemplateAccess(user_unit)

    assert access.changes_are_non_sensitive(job_template_with_ids, data)
Exemple #2
0
def test_change_jt_sensitive_data(job_template_with_ids, mocker, user_unit):
    """Assure that can_add is called with all ForeignKeys."""
    class RoleReturnsTrue(Role):
        class Meta:
            proxy = True

        def __contains__(self, accessor):
            return True

    job_template_with_ids.admin_role = RoleReturnsTrue()
    job_template_with_ids.organization.job_template_admin_role = RoleReturnsTrue(
    )

    inv2 = Inventory()
    inv2.use_role = RoleReturnsTrue()
    data = {'inventory': inv2}

    access = JobTemplateAccess(user_unit)

    assert not access.changes_are_non_sensitive(job_template_with_ids, data)

    job_template_with_ids.inventory.use_role = RoleReturnsTrue()
    job_template_with_ids.project.use_role = RoleReturnsTrue()
    assert access.can_change(job_template_with_ids, data)