|
| 1 | +--- |
| 2 | +- name: Test django users |
| 3 | + gather_facts: false |
| 4 | + hosts: localhost |
| 5 | + vars: |
| 6 | + pulp_url: http://localhost:8080 |
| 7 | + pulp_admin_username: admin |
| 8 | + pulp_admin_password: password |
| 9 | + pulp_validate_certs: true |
| 10 | + tasks: |
| 11 | + - name: Query groups |
| 12 | + uri: |
| 13 | + url: "{{ pulp_url }}/pulp/api/v3/groups/" |
| 14 | + user: "{{ pulp_admin_username }}" |
| 15 | + password: "{{ pulp_admin_password }}" |
| 16 | + method: GET |
| 17 | + body_format: json |
| 18 | + status_code: 200 |
| 19 | + force_basic_auth: true |
| 20 | + register: groups_result |
| 21 | + |
| 22 | + - name: Create groups |
| 23 | + uri: |
| 24 | + url: "{{ pulp_url }}/pulp/api/v3/groups/" |
| 25 | + user: "{{ pulp_admin_username }}" |
| 26 | + password: "{{ pulp_admin_password }}" |
| 27 | + method: POST |
| 28 | + body: |
| 29 | + name: "{{ item }}" |
| 30 | + body_format: json |
| 31 | + status_code: 201 |
| 32 | + force_basic_auth: true |
| 33 | + loop: |
| 34 | + - test_group1 |
| 35 | + - test_group2 |
| 36 | + when: item not in groups_result.json.results | map(attribute='name') | list |
| 37 | + |
| 38 | + - include_role: |
| 39 | + name: pulp_django_user |
| 40 | + vars: |
| 41 | + pulp_django_users: |
| 42 | + - username: test_user |
| 43 | + password: correct horse battery staple |
| 44 | + groups: |
| 45 | + - test_group1 |
| 46 | + |
| 47 | + - name: Query user |
| 48 | + uri: |
| 49 | + url: "{{ pulp_url }}/pulp/api/v3/users/?username=test_user" |
| 50 | + user: "{{ pulp_admin_username }}" |
| 51 | + password: "{{ pulp_admin_password }}" |
| 52 | + method: GET |
| 53 | + status_code: 200 |
| 54 | + force_basic_auth: true |
| 55 | + register: user_result |
| 56 | + |
| 57 | + - name: Verify django user creation |
| 58 | + assert: |
| 59 | + that: |
| 60 | + - user_result.json.count == 1 |
| 61 | + - user_result.json.results[0].username == "test_user" |
| 62 | + - user_result.json.results[0].groups | length == 1 |
| 63 | + - user_result.json.results[0].groups[0].name == "test_group1" |
| 64 | + |
| 65 | + # Update group membership. |
| 66 | + - include_role: |
| 67 | + name: pulp_django_user |
| 68 | + vars: |
| 69 | + pulp_django_users: |
| 70 | + - username: test_user |
| 71 | + password: correct horse battery staple |
| 72 | + groups: |
| 73 | + - test_group2 |
| 74 | + |
| 75 | + - name: Query user |
| 76 | + uri: |
| 77 | + url: "{{ pulp_url }}/pulp/api/v3/users/?username=test_user" |
| 78 | + user: "{{ pulp_admin_username }}" |
| 79 | + password: "{{ pulp_admin_password }}" |
| 80 | + method: GET |
| 81 | + status_code: 200 |
| 82 | + force_basic_auth: true |
| 83 | + register: user_result |
| 84 | + |
| 85 | + - name: Verify django user group update |
| 86 | + assert: |
| 87 | + that: |
| 88 | + - user_result.json.count == 1 |
| 89 | + - user_result.json.results[0].username == "test_user" |
| 90 | + - user_result.json.results[0].groups | length == 1 |
| 91 | + - user_result.json.results[0].groups[0].name == "test_group2" |
0 commit comments