ansible / eda-server

Event Driven Ansible for AAP
Apache License 2.0
64 stars 41 forks source link

chore: update RBAC test factory to use fixture based data #879

Closed Dostonbek1 closed 4 months ago

Dostonbek1 commented 4 months ago

NOTE: This PR looks to have too many changes but main changes are in dab_rbac folder and other tests mostly have fixture rename changes.

JIRA: AAP-23570

mkanoor commented 4 months ago

@Dostonbek1 Since the create serializer is not being used here and we are getting a model as dict we get a lot of read only attributes and these are being sent during post. If we start enforcing checks on eda-server when an object is being created these tests are going to fail.

For example this is the post data for Project

{'id': 1, 'organization': 1, 'organization_id': 1, 'name': 'default-project-rbac', 'description': 'Default Project', 'url': 'https://git.example.com/acme/project-01', 'proxy': 'http://user:secret@myproxy.com', 'git_hash': '684f62df18ce5f8d5c428e53203b9b975426eed0', 'verify_ssl': True, 'eda_credential': 2, 'eda_credential_id': 2, 'import_state': Project.ImportState.COMPLETED, 'import_task_id': 'c8a7a0e3-05e7-4376-831a-6b8af80107bd', 'scm_type': Project.ScmType.GIT, 'scm_branch': 'main', 'signature_validation_credential': 1, 'signature_validation_credential_id': 1}

These are the read only variables that are being sent via Post for a create.

If we enforce checks on the incoming params this request will fail.

Not ideal but I was able to do this with the Serializer

(Pdb) from aap_eda.api.serializers.decision_environment import DecisionEnvironmentCreateSerializer
(Pdb) x=DecisionEnvironmentCreateSerializer(instance=model_obj)
(Pdb) x.data

{'name': 'default_decision_environment', 'description': 'Default DE', 'image_url': 'quay.io/ansible/ansible-rulebook:latest', 'organization_id': 1, 'eda_credential_id': 1}