How to use Organization method in argos

Best JavaScript code snippet using argos

test_organizations.py

Source:test_organizations.py Github

copy

Full Screen

1# Copyright (c) 2015 Ansible, Inc.2# All Rights Reserved.3# Python4import os5from backports.tempfile import TemporaryDirectory6from django.conf import settings7import pytest8from unittest import mock9# AWX10from awx.main.models import ProjectUpdate11from awx.api.versioning import reverse12@pytest.fixture13def create_job_factory(job_factory, project):14 def fn(status='running'):15 j = job_factory()16 j.status = status17 j.project = project18 j.save()19 return j20 return fn21@pytest.fixture22def create_project_update_factory(organization, project):23 def fn(status='running'):24 pu = ProjectUpdate(project=project)25 pu.status = status26 pu.organization = organization27 pu.save()28 return pu29 return fn30@pytest.fixture31def organization_jobs_successful(create_job_factory, create_project_update_factory):32 return [create_job_factory(status='successful') for i in range(0, 2)] + \33 [create_project_update_factory(status='successful') for i in range(0, 2)]34@pytest.fixture35def organization_jobs_running(create_job_factory, create_project_update_factory):36 return [create_job_factory(status='running') for i in range(0, 2)] + \37 [create_project_update_factory(status='running') for i in range(0, 2)]38@pytest.mark.django_db39def test_organization_list_access_tests(options, head, get, admin, alice):40 options(reverse('api:organization_list'), user=admin, expect=200)41 head(reverse('api:organization_list'), user=admin, expect=200)42 get(reverse('api:organization_list'), user=admin, expect=200)43 options(reverse('api:organization_list'), user=alice, expect=200)44 head(reverse('api:organization_list'), user=alice, expect=200)45 get(reverse('api:organization_list'), user=alice, expect=200)46 options(reverse('api:organization_list'), user=None, expect=401)47 head(reverse('api:organization_list'), user=None, expect=401)48 get(reverse('api:organization_list'), user=None, expect=401)49@pytest.mark.django_db50def test_organization_access_tests(organization, get, admin, alice, bob):51 organization.member_role.members.add(alice)52 get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=admin, expect=200)53 get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=alice, expect=200)54 get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=bob, expect=403)55 get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=None, expect=401)56@pytest.mark.django_db57def test_organization_list_integrity(organization, get, admin, alice):58 res = get(reverse('api:organization_list'), user=admin)59 for field in ['id', 'url', 'name', 'description', 'created']:60 assert field in res.data['results'][0]61@pytest.mark.django_db62def test_organization_list_visibility(organizations, get, admin, alice):63 orgs = organizations(2)64 res = get(reverse('api:organization_list'), user=admin)65 assert res.data['count'] == 266 assert len(res.data['results']) == 267 res = get(reverse('api:organization_list'), user=alice)68 assert res.data['count'] == 069 orgs[1].member_role.members.add(alice)70 res = get(reverse('api:organization_list'), user=alice)71 assert res.data['count'] == 172 assert len(res.data['results']) == 173 assert res.data['results'][0]['id'] == orgs[1].id74@pytest.mark.django_db75def test_organization_project_list(organization, project_factory, get, alice, bob, rando):76 prj1 = project_factory('project-one')77 project_factory('project-two')78 organization.admin_role.members.add(alice)79 organization.member_role.members.add(bob)80 prj1.use_role.members.add(bob)81 assert get(reverse('api:organization_projects_list', kwargs={'pk': organization.id}), user=alice).data['count'] == 282 assert get(reverse('api:organization_projects_list', kwargs={'pk': organization.id}), user=bob).data['count'] == 183 assert get(reverse('api:organization_projects_list', kwargs={'pk': organization.id}), user=rando).status_code == 40384@pytest.mark.django_db85def test_organization_user_list(organization, get, admin, alice, bob):86 organization.admin_role.members.add(alice)87 organization.member_role.members.add(alice)88 organization.member_role.members.add(bob)89 assert get(reverse('api:organization_users_list', kwargs={'pk': organization.id}), user=admin).data['count'] == 290 assert get(reverse('api:organization_users_list', kwargs={'pk': organization.id}), user=alice).data['count'] == 291 assert get(reverse('api:organization_users_list', kwargs={'pk': organization.id}), user=bob).data['count'] == 292 assert get(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), user=admin).data['count'] == 193 assert get(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), user=alice).data['count'] == 194 assert get(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), user=bob).data['count'] == 195@pytest.mark.django_db96def test_organization_inventory_list(organization, inventory_factory, get, alice, bob, rando):97 inv1 = inventory_factory('inventory-one')98 inventory_factory('inventory-two')99 organization.admin_role.members.add(alice)100 organization.member_role.members.add(bob)101 inv1.use_role.members.add(bob)102 assert get(reverse('api:organization_inventories_list', kwargs={'pk': organization.id}), user=alice).data['count'] == 2103 assert get(reverse('api:organization_inventories_list', kwargs={'pk': organization.id}), user=bob).data['count'] == 1104 get(reverse('api:organization_inventories_list', kwargs={'pk': organization.id}), user=rando, expect=403)105 106@pytest.mark.django_db107@mock.patch('awx.api.views.feature_enabled', lambda feature: True)108def test_create_organization(post, admin, alice):109 new_org = {110 'name': 'new org',111 'description': 'my description'112 }113 res = post(reverse('api:organization_list'), new_org, user=admin, expect=201)114 assert res.data['name'] == new_org['name']115 res = post(reverse('api:organization_list'), new_org, user=admin, expect=400)116@pytest.mark.django_db117@mock.patch('awx.api.views.feature_enabled', lambda feature: True)118def test_create_organization_xfail(post, alice):119 new_org = {120 'name': 'new org',121 'description': 'my description'122 }123 post(reverse('api:organization_list'), new_org, user=alice, expect=403)124@pytest.mark.django_db125def test_add_user_to_organization(post, organization, alice, bob):126 organization.admin_role.members.add(alice)127 post(reverse('api:organization_users_list', kwargs={'pk': organization.id}), {'id': bob.id}, user=alice, expect=204)128 assert bob in organization.member_role129 post(reverse('api:organization_users_list', kwargs={'pk': organization.id}), {'id': bob.id, 'disassociate': True} , user=alice, expect=204)130 assert bob not in organization.member_role131@pytest.mark.django_db132def test_add_user_to_organization_xfail(post, organization, alice, bob):133 organization.member_role.members.add(alice)134 post(reverse('api:organization_users_list', kwargs={'pk': organization.id}), {'id': bob.id}, user=alice, expect=403)135@pytest.mark.django_db136def test_add_admin_to_organization(post, organization, alice, bob):137 organization.admin_role.members.add(alice)138 post(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), {'id': bob.id}, user=alice, expect=204)139 assert bob in organization.admin_role140 assert bob in organization.member_role141 post(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), {'id': bob.id, 'disassociate': True} , user=alice, expect=204)142 assert bob not in organization.admin_role143 assert bob not in organization.member_role144@pytest.mark.django_db145def test_add_admin_to_organization_xfail(post, organization, alice, bob):146 organization.member_role.members.add(alice)147 post(reverse('api:organization_admins_list', kwargs={'pk': organization.id}), {'id': bob.id}, user=alice, expect=403)148@pytest.mark.django_db149def test_update_organization(get, put, organization, alice, bob):150 organization.admin_role.members.add(alice)151 data = get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=alice, expect=200).data152 data['description'] = 'hi'153 put(reverse('api:organization_detail', kwargs={'pk': organization.id}), data, user=alice, expect=200)154 organization.refresh_from_db()155 assert organization.description == 'hi'156 data['description'] = 'bye'157 put(reverse('api:organization_detail', kwargs={'pk': organization.id}), data, user=bob, expect=403)158@pytest.mark.django_db159def test_update_organization_max_hosts(get, put, organization, admin, alice, bob):160 # Admin users can get and update max_hosts161 data = get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=admin, expect=200).data162 assert organization.max_hosts == 0163 data['max_hosts'] = 3164 put(reverse('api:organization_detail', kwargs={'pk': organization.id}), data, user=admin, expect=200)165 organization.refresh_from_db()166 assert organization.max_hosts == 3167 # Organization admins can get the data and can update other fields, but not max_hosts168 organization.admin_role.members.add(alice)169 data = get(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=alice, expect=200).data170 data['max_hosts'] = 5171 put(reverse('api:organization_detail', kwargs={'pk': organization.id}), data, user=alice, expect=400)172 organization.refresh_from_db()173 assert organization.max_hosts == 3174 # Ordinary users shouldn't be able to update either.175 put(reverse('api:organization_detail', kwargs={'pk': organization.id}), data, user=bob, expect=403)176 organization.refresh_from_db()177 assert organization.max_hosts == 3178@pytest.mark.django_db179@mock.patch('awx.main.access.BaseAccess.check_license', lambda *a, **kw: True)180def test_delete_organization(delete, organization, admin):181 delete(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=admin, expect=204)182@pytest.mark.django_db183@mock.patch('awx.main.access.BaseAccess.check_license', lambda *a, **kw: True)184def test_delete_organization2(delete, organization, alice):185 organization.admin_role.members.add(alice)186 delete(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=alice, expect=204)187@pytest.mark.django_db188@mock.patch('awx.main.access.BaseAccess.check_license', lambda *a, **kw: True)189def test_delete_organization_xfail1(delete, organization, alice):190 organization.member_role.members.add(alice)191 delete(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=alice, expect=403)192@pytest.mark.django_db193@mock.patch('awx.main.access.BaseAccess.check_license', lambda *a, **kw: True)194def test_delete_organization_xfail2(delete, organization):195 delete(reverse('api:organization_detail', kwargs={'pk': organization.id}), user=None, expect=401)196@pytest.mark.django_db197def test_organization_custom_virtualenv(get, patch, organization, admin):198 with TemporaryDirectory(dir=settings.BASE_VENV_PATH) as temp_dir:199 os.makedirs(os.path.join(temp_dir, 'bin', 'activate'))200 url = reverse('api:organization_detail', kwargs={'pk': organization.id})201 patch(url, {'custom_virtualenv': temp_dir}, user=admin, expect=200)202 assert get(url, user=admin).data['custom_virtualenv'] == os.path.join(temp_dir, '')203@pytest.mark.django_db204def test_organization_invalid_custom_virtualenv(get, patch, organization, admin):205 url = reverse('api:organization_detail', kwargs={'pk': organization.id})206 resp = patch(url, {'custom_virtualenv': '/foo/bar'}, user=admin, expect=400)207 assert resp.data['custom_virtualenv'] == [208 '/foo/bar is not a valid virtualenv in {}'.format(settings.BASE_VENV_PATH)209 ]210@pytest.mark.django_db211@pytest.mark.parametrize('value', ["", None])212def test_organization_unset_custom_virtualenv(get, patch, organization, admin, value):213 url = reverse('api:organization_detail', kwargs={'pk': organization.id})214 resp = patch(url, {'custom_virtualenv': value}, user=admin, expect=200)215 assert resp.data['custom_virtualenv'] is None216@pytest.mark.django_db217def test_organization_delete(delete, admin, organization, organization_jobs_successful):218 url = reverse('api:organization_detail', kwargs={'pk': organization.id})219 delete(url, None, user=admin, expect=204)220@pytest.mark.django_db221def test_organization_delete_with_active_jobs(delete, admin, organization, organization_jobs_running):222 def sort_keys(x):223 return (x['type'], str(x['id']))224 url = reverse('api:organization_detail', kwargs={'pk': organization.id})225 resp = delete(url, None, user=admin, expect=409)226 expect_transformed = [dict(id=j.id, type=j.model_to_str()) for j in organization_jobs_running]227 resp_sorted = sorted(resp.data['active_jobs'], key=sort_keys)228 expect_sorted = sorted(expect_transformed, key=sort_keys)229 assert resp.data['error'] == u"Resource is being used by running jobs."...

Full Screen

Full Screen

test_organization_counts.py

Source:test_organization_counts.py Github

copy

Full Screen

1import pytest2from awx.api.versioning import reverse3@pytest.fixture4def organization_resource_creator(organization, user):5 def rf(users, admins, job_templates, projects, inventories, teams):6 # Associate one resource of every type with the organization7 for i in range(users):8 member_user = user('org-member %s' % i)9 organization.member_role.members.add(member_user)10 for i in range(admins):11 admin_user = user('org-admin %s' % i)12 organization.admin_role.members.add(admin_user)13 for i in range(teams):14 organization.teams.create(name='org-team %s' % i)15 for i in range(inventories):16 inventory = organization.inventories.create(name="associated-inv %s" % i)17 for i in range(projects):18 organization.projects.create(name="test-proj %s" % i,19 description="test-proj-desc")20 # Mix up the inventories and projects used by the job templates21 i_proj = 022 i_inv = 023 for i in range(job_templates):24 project = organization.projects.all()[i_proj]25 inventory = organization.inventories.all()[i_inv]26 project.jobtemplates.create(name="test-jt %s" % i,27 description="test-job-template-desc",28 inventory=inventory,29 playbook="test_playbook.yml")30 i_proj += 131 i_inv += 132 if i_proj >= organization.projects.count():33 i_proj = 034 if i_inv >= organization.inventories.count():35 i_inv = 036 return organization37 return rf38COUNTS_PRIMES = {39 'users': 11,40 'admins': 5,41 'job_templates': 3,42 'projects': 3,43 'inventories': 7,44 'teams': 545}46COUNTS_ZEROS = {47 'users': 0,48 'admins': 0,49 'job_templates': 0,50 'projects': 0,51 'inventories': 0,52 'teams': 053}54@pytest.fixture55def resourced_organization(organization_resource_creator):56 return organization_resource_creator(**COUNTS_PRIMES)57@pytest.mark.django_db58def test_org_counts_detail_admin(resourced_organization, user, get):59 # Check that all types of resources are counted by a superuser60 external_admin = user('admin', True)61 response = get(reverse('api:organization_detail',62 kwargs={'pk': resourced_organization.pk}), external_admin)63 assert response.status_code == 20064 counts = response.data['summary_fields']['related_field_counts']65 assert counts == COUNTS_PRIMES66@pytest.mark.django_db67def test_org_counts_detail_member(resourced_organization, user, get):68 # Check that a non-admin org member can only see users / admin in detail view69 member_user = resourced_organization.member_role.members.get(username='org-member 1')70 response = get(reverse('api:organization_detail',71 kwargs={'pk': resourced_organization.pk}), member_user)72 assert response.status_code == 20073 counts = response.data['summary_fields']['related_field_counts']74 assert counts == {75 'users': COUNTS_PRIMES['users'], # Policy is that members can see other users and admins76 'admins': COUNTS_PRIMES['admins'],77 'job_templates': 0,78 'projects': 0,79 'inventories': 0,80 'teams': 081 }82@pytest.mark.django_db83def test_org_counts_list_admin(resourced_organization, user, get):84 # Check that all types of resources are counted by a superuser85 external_admin = user('admin', True)86 response = get(reverse('api:organization_list'), external_admin)87 assert response.status_code == 20088 counts = response.data['results'][0]['summary_fields']['related_field_counts']89 assert counts == COUNTS_PRIMES90@pytest.mark.django_db91def test_org_counts_list_member(resourced_organization, user, get):92 # Check that a non-admin user can only see the full project and93 # user count, consistent with the RBAC rules94 member_user = resourced_organization.member_role.members.get(username='org-member 1')95 response = get(reverse('api:organization_list'), member_user)96 assert response.status_code == 20097 counts = response.data['results'][0]['summary_fields']['related_field_counts']98 assert counts == {99 'users': COUNTS_PRIMES['users'], # Policy is that members can see other users and admins100 'admins': COUNTS_PRIMES['admins'],101 'job_templates': 0,102 'projects': 0,103 'inventories': 0,104 'teams': 0105 }106@pytest.mark.django_db107def test_new_org_zero_counts(user, post):108 # Check that a POST to the organization list endpoint returns109 # correct counts, including the new record110 org_list_url = reverse('api:organization_list')111 post_response = post(url=org_list_url, data={'name': 'test organization',112 'description': ''}, user=user('admin', True))113 assert post_response.status_code == 201114 new_org_list = post_response.render().data115 counts_dict = new_org_list['summary_fields']['related_field_counts']116 assert counts_dict == COUNTS_ZEROS117@pytest.mark.django_db118def test_two_organizations(resourced_organization, organizations, user, get):119 # Check correct results for two organizations are returned120 external_admin = user('admin', True)121 organization_zero = organizations(1)[0]122 response = get(reverse('api:organization_list'), external_admin)123 assert response.status_code == 200124 org_id_full = resourced_organization.id125 org_id_zero = organization_zero.id126 counts = {}127 for i in range(2):128 org_id = response.data['results'][i]['id']129 counts[org_id] = response.data['results'][i]['summary_fields']['related_field_counts']130 assert counts[org_id_full] == COUNTS_PRIMES131 assert counts[org_id_zero] == COUNTS_ZEROS132@pytest.mark.django_db133def test_scan_JT_counted(resourced_organization, user, get):134 admin_user = user('admin', True)135 counts_dict = COUNTS_PRIMES136 # Test list view137 list_response = get(reverse('api:organization_list'), admin_user)138 assert list_response.status_code == 200139 assert list_response.data['results'][0]['summary_fields']['related_field_counts'] == counts_dict140 # Test detail view141 detail_response = get(reverse('api:organization_detail', kwargs={'pk': resourced_organization.pk}), admin_user)142 assert detail_response.status_code == 200143 assert detail_response.data['summary_fields']['related_field_counts'] == counts_dict144@pytest.mark.django_db145def test_JT_not_double_counted(resourced_organization, user, get):146 admin_user = user('admin', True)147 # Add a run job template to the org148 resourced_organization.projects.all()[0].jobtemplates.create(149 job_type='run',150 inventory=resourced_organization.inventories.all()[0],151 project=resourced_organization.projects.all()[0],152 name='double-linked-job-template')153 counts_dict = COUNTS_PRIMES154 counts_dict['job_templates'] += 1155 # Test list view156 list_response = get(reverse('api:organization_list'), admin_user)157 assert list_response.status_code == 200158 assert list_response.data['results'][0]['summary_fields']['related_field_counts'] == counts_dict159 # Test detail view160 detail_response = get(reverse('api:organization_detail', kwargs={'pk': resourced_organization.pk}), admin_user)161 assert detail_response.status_code == 200162 assert detail_response.data['summary_fields']['related_field_counts'] == counts_dict163@pytest.mark.django_db164def test_JT_associated_with_project(organizations, project, user, get):165 # Check that adding a project to an organization gets the project's JT166 # included in the organization's JT count167 external_admin = user('admin', True)168 two_orgs = organizations(2)169 organization = two_orgs[0]170 other_org = two_orgs[1]171 unrelated_inv = other_org.inventories.create(name='not-in-organization')172 organization.projects.add(project)173 project.jobtemplates.create(name="test-jt",174 description="test-job-template-desc",175 inventory=unrelated_inv,176 playbook="test_playbook.yml")177 response = get(reverse('api:organization_list'), external_admin)178 assert response.status_code == 200179 org_id = organization.id180 counts = {}181 for org_json in response.data['results']:182 working_id = org_json['id']183 counts[working_id] = org_json['summary_fields']['related_field_counts']184 assert counts[org_id] == {185 'users': 0,186 'admins': 0,187 'job_templates': 1,188 'projects': 1,189 'inventories': 0,190 'teams': 0...

Full Screen

Full Screen

test_rbac_core.py

Source:test_rbac_core.py Github

copy

Full Screen

1import pytest2from awx.main.models import (3 Role,4 Organization,5 Project,6)7from awx.main.fields import update_role_parentage_for_instance8@pytest.mark.django_db9def test_auto_inheritance_by_children(organization, alice):10 A = Role.objects.create()11 B = Role.objects.create()12 A.members.add(alice)13 assert alice not in organization.admin_role14 assert Organization.accessible_objects(alice, 'admin_role').count() == 015 A.children.add(B)16 assert alice not in organization.admin_role17 assert Organization.accessible_objects(alice, 'admin_role').count() == 018 A.children.add(organization.admin_role)19 assert alice in organization.admin_role20 assert Organization.accessible_objects(alice, 'admin_role').count() == 121 A.children.remove(organization.admin_role)22 assert alice not in organization.admin_role23 B.children.add(organization.admin_role)24 assert alice in organization.admin_role25 B.children.remove(organization.admin_role)26 assert alice not in organization.admin_role27 assert Organization.accessible_objects(alice, 'admin_role').count() == 028 # We've had the case where our pre/post save init handlers in our field descriptors29 # end up creating a ton of role objects because of various not-so-obvious issues30 assert Role.objects.count() < 5031@pytest.mark.django_db32def test_auto_inheritance_by_parents(organization, alice):33 A = Role.objects.create()34 B = Role.objects.create()35 A.members.add(alice)36 assert alice not in organization.admin_role37 B.parents.add(A)38 assert alice not in organization.admin_role39 organization.admin_role.parents.add(A)40 assert alice in organization.admin_role41 organization.admin_role.parents.remove(A)42 assert alice not in organization.admin_role43 organization.admin_role.parents.add(B)44 assert alice in organization.admin_role45 organization.admin_role.parents.remove(B)46 assert alice not in organization.admin_role47@pytest.mark.django_db48def test_accessible_objects(organization, alice, bob):49 A = Role.objects.create()50 A.members.add(alice)51 B = Role.objects.create()52 B.members.add(alice)53 B.members.add(bob)54 assert Organization.accessible_objects(alice, 'admin_role').count() == 055 assert Organization.accessible_objects(bob, 'admin_role').count() == 056 A.children.add(organization.admin_role)57 assert Organization.accessible_objects(alice, 'admin_role').count() == 158 assert Organization.accessible_objects(bob, 'admin_role').count() == 059@pytest.mark.django_db60def test_team_symantics(organization, team, alice):61 assert alice not in organization.auditor_role62 team.member_role.children.add(organization.auditor_role)63 assert alice not in organization.auditor_role64 team.member_role.members.add(alice)65 assert alice in organization.auditor_role66 team.member_role.members.remove(alice)67 assert alice not in organization.auditor_role68@pytest.mark.django_db69def test_auto_field_adjustments(organization, inventory, team, alice):70 'Ensures the auto role reparenting is working correctly through non m2m fields'71 org2 = Organization.objects.create(name='Org 2', description='org 2')72 org2.admin_role.members.add(alice)73 assert alice not in inventory.admin_role74 inventory.organization = org275 inventory.save()76 assert alice in inventory.admin_role77 inventory.organization = organization78 inventory.save()79 assert alice not in inventory.admin_role80 #assert False81@pytest.mark.django_db82def test_implicit_deletes(alice):83 'Ensures implicit resources and roles delete themselves'84 delorg = Organization.objects.create(name='test-org')85 child = Role.objects.create()86 child.parents.add(delorg.admin_role)87 delorg.admin_role.members.add(alice)88 admin_role_id = delorg.admin_role.id89 auditor_role_id = delorg.auditor_role.id90 assert child.ancestors.count() > 191 assert Role.objects.filter(id=admin_role_id).count() == 192 assert Role.objects.filter(id=auditor_role_id).count() == 193 n_alice_roles = alice.roles.count()94 n_system_admin_children = Role.singleton('system_administrator').children.count()95 delorg.delete()96 assert Role.objects.filter(id=admin_role_id).count() == 097 assert Role.objects.filter(id=auditor_role_id).count() == 098 assert alice.roles.count() == (n_alice_roles - 1)99 assert Role.singleton('system_administrator').children.count() == (n_system_admin_children - 1)100 assert child.ancestors.count() == 1101 assert child.ancestors.all()[0] == child102@pytest.mark.django_db103def test_content_object(user):104 'Ensure our content_object stuf seems to be working'105 org = Organization.objects.create(name='test-org')106 assert org.admin_role.content_object.id == org.id107@pytest.mark.django_db108def test_hierarchy_rebuilding_multi_path():109 'Tests a subdtle cases around role hierarchy rebuilding when you have multiple paths to the same role of different length'110 X = Role.objects.create()111 A = Role.objects.create()112 B = Role.objects.create()113 C = Role.objects.create()114 D = Role.objects.create()115 A.children.add(B)116 A.children.add(D)117 B.children.add(C)118 C.children.add(D)119 assert A.is_ancestor_of(D)120 assert X.is_ancestor_of(D) is False121 X.children.add(A)122 assert X.is_ancestor_of(D) is True123 X.children.remove(A)124 # This can be the stickler, the rebuilder needs to ensure that D's role125 # hierarchy is built after both A and C are updated.126 assert X.is_ancestor_of(D) is False127@pytest.mark.django_db128def test_auto_parenting():129 org1 = Organization.objects.create(name='org1')130 org2 = Organization.objects.create(name='org2')131 prj1 = Project.objects.create(name='prj1')132 prj2 = Project.objects.create(name='prj2')133 assert org1.admin_role.is_ancestor_of(prj1.admin_role) is False134 assert org1.admin_role.is_ancestor_of(prj2.admin_role) is False135 assert org2.admin_role.is_ancestor_of(prj1.admin_role) is False136 assert org2.admin_role.is_ancestor_of(prj2.admin_role) is False137 prj1.organization = org1138 prj1.save()139 assert org1.admin_role.is_ancestor_of(prj1.admin_role)140 assert org1.admin_role.is_ancestor_of(prj2.admin_role) is False141 assert org2.admin_role.is_ancestor_of(prj1.admin_role) is False142 assert org2.admin_role.is_ancestor_of(prj2.admin_role) is False143 prj2.organization = org1144 prj2.save()145 assert org1.admin_role.is_ancestor_of(prj1.admin_role)146 assert org1.admin_role.is_ancestor_of(prj2.admin_role)147 assert org2.admin_role.is_ancestor_of(prj1.admin_role) is False148 assert org2.admin_role.is_ancestor_of(prj2.admin_role) is False149 prj1.organization = org2150 prj1.save()151 assert org1.admin_role.is_ancestor_of(prj1.admin_role) is False152 assert org1.admin_role.is_ancestor_of(prj2.admin_role)153 assert org2.admin_role.is_ancestor_of(prj1.admin_role)154 assert org2.admin_role.is_ancestor_of(prj2.admin_role) is False155 prj2.organization = org2156 prj2.save()157 assert org1.admin_role.is_ancestor_of(prj1.admin_role) is False158 assert org1.admin_role.is_ancestor_of(prj2.admin_role) is False159 assert org2.admin_role.is_ancestor_of(prj1.admin_role)160 assert org2.admin_role.is_ancestor_of(prj2.admin_role)161@pytest.mark.django_db162def test_update_parents_keeps_teams(team, project):163 project.update_role.parents.add(team.member_role)164 assert team.member_role in project.update_role # test prep sanity check165 update_role_parentage_for_instance(project)...

Full Screen

Full Screen

views.py

Source:views.py Github

copy

Full Screen

1from django.utils.translation import ugettext_lazy as _2from rest_framework import mixins3from rest_framework.exceptions import PermissionDenied4from rest_framework.generics import get_object_or_4045from rest_framework.permissions import IsAuthenticated6from rest_framework.viewsets import GenericViewSet7from bothub.api.v2.metadata import Metadata8from bothub.authentication.models import User9from bothub.common.models import Organization, OrganizationAuthorization10from .filters import OrganizationAuthorizationFilter11from .permissions import (12 OrganizationAdminManagerAuthorization,13 OrganizationHasPermission,14)15from .serializers import (16 OrganizationSeralizer,17 OrganizationAuthorizationSerializer,18 OrganizationAuthorizationRoleSerializer,19)20class OrganizationViewSet(21 mixins.ListModelMixin,22 mixins.RetrieveModelMixin,23 mixins.CreateModelMixin,24 mixins.UpdateModelMixin,25 mixins.DestroyModelMixin,26 GenericViewSet,27):28 queryset = Organization.objects.all()29 serializer_class = OrganizationSeralizer30 permission_classes = [IsAuthenticated, OrganizationHasPermission]31 lookup_field = "nickname"32 metadata_class = Metadata33 def get_queryset(self, *args, **kwargs):34 if getattr(self, "swagger_fake_view", False):35 # queryset just for schema generation metadata36 return Organization.objects.none()37 auth = (38 OrganizationAuthorization.objects.exclude(role=0)39 .filter(user=self.request.user)40 .values("organization")41 )42 return self.queryset.filter(repository_owner__in=auth)43class OrganizationProfileViewSet(mixins.RetrieveModelMixin, GenericViewSet):44 """45 Get organization profile46 """47 serializer_class = OrganizationSeralizer48 queryset = Organization.objects49 lookup_field = "nickname"50class OrganizationAuthorizationViewSet(51 mixins.ListModelMixin,52 mixins.UpdateModelMixin,53 mixins.DestroyModelMixin,54 GenericViewSet,55):56 queryset = OrganizationAuthorization.objects.exclude(57 role=OrganizationAuthorization.ROLE_NOT_SETTED58 )59 serializer_class = OrganizationAuthorizationSerializer60 filter_class = OrganizationAuthorizationFilter61 permission_classes = [IsAuthenticated]62 lookup_fields = ["organization_nickname", "user__nickname"]63 def get_object(self):64 organization = get_object_or_404(65 Organization, nickname=self.kwargs.get("organization_nickname")66 )67 user = get_object_or_404(User, nickname=self.kwargs.get("user__nickname"))68 obj = organization.get_organization_authorization(user)69 self.check_object_permissions(self.request, obj)70 return obj71 def update(self, *args, **kwargs):72 self.filter_class = None73 self.serializer_class = OrganizationAuthorizationRoleSerializer74 self.permission_classes = [75 IsAuthenticated,76 OrganizationAdminManagerAuthorization,77 ]78 response = super().update(*args, **kwargs)79 self.get_object()80 return response81 def destroy(self, request, *args, **kwargs):82 self.filter_class = None83 self.serializer_class = OrganizationAuthorizationRoleSerializer84 self.permission_classes = [85 IsAuthenticated,86 OrganizationAdminManagerAuthorization,87 ]88 return super().destroy(request, *args, **kwargs)89 def perform_destroy(self, instance):90 user = self.kwargs.get("user__nickname")91 if self.request.user.nickname == user:92 raise PermissionDenied(_("You cannot delete your own user."))...

Full Screen

Full Screen

test_models.py

Source:test_models.py Github

copy

Full Screen

...6from mcod.organizations.models import Organization7@pytest.mark.django_db8class TestOrganizationModel:9 def test_organization_create(self):10 organization = Organization()11 organization.slug = "test"12 organization.title = "test"13 organization.postal_code = "00-001"14 organization.city = "Warszwa"15 organization.street = "Królewska"16 organization.street_number = "27"17 organization.flat_number = "1"18 organization.street_type = "ul"19 organization.email = "email@email.pl"20 organization.fax = "123123123"21 organization.tel = "123123123"22 organization.epuap = "epuap"23 organization.regon = "123123123"24 organization.website = "www.www.www"25 assert organization.id is None26 organization.save()27 assert organization.id is not None28 assert Organization.objects.last().id == organization.id29 def test_required_fields_validation(self):30 org = Organization()31 with pytest.raises(ValidationError) as e:32 org.full_clean()33 e = str(e.value)34 assert "'slug'" in e35 assert "'title'" in e36 assert "'postal_code'" in e37 assert "'city'" in e38 assert "'street'" in e39 # assert "'street_number'" in e40 # assert "'flat_number'" in e41 assert "'street_type'" in e42 assert "'email'" in e43 assert "'fax'" in e44 assert "'tel'" in e45 assert "'epuap'" in e46 assert "'regon'" in e47 assert "'website'" in e48 def test_name_uniqness(self, valid_organization):49 org = Organization()50 org.slug = valid_organization.slug51 with pytest.raises(ValidationError) as e:52 org.full_clean()53 assert "'slug': " in str(e.value)54 def test_str(self, valid_organization):55 valid_organization.name = 'test-name'56 valid_organization.title = 'Title'57 assert 'Title' == str(valid_organization)58 def test_str_no_title(self, valid_organization):59 valid_organization.slug = 'test-name'60 valid_organization.title = ''61 assert 'test-name' == str(valid_organization)62 def test_get_url_path(self, valid_organization):63 assert f'/applications/application/{valid_organization.id}/change/' == valid_organization.get_url_path()64 def test_get_url_path_no_reverse(self):65 org = Organization()66 assert '' == org.get_url_path()67 def test_short_description(self):68 org = Organization()69 org.description = "<p>Paragraph</p>"70 assert 'Paragraph' == org.short_description71 def test_short_description_no_description(self):72 org = Organization()73 org.description = None74 assert '' == org.short_description75 def test_image_url_and_path(self, valid_organization):76 assert not valid_organization.image77 valid_organization.image = SimpleUploadedFile("somefile.jpg", b"""1px""")78 valid_organization.save()79 assert valid_organization.image80 date_folder = date.today().isoformat().replace('-', '')81 image_name = valid_organization.image.name82 assert valid_organization.image.url == f"/test/media/images/organizations/{image_name}"83 assert valid_organization.image.path == f"{settings.IMAGES_MEDIA_ROOT}/organizations/{image_name}"84 assert date_folder in valid_organization.image.url...

Full Screen

Full Screen

organization.py

Source:organization.py Github

copy

Full Screen

1# Copyright (c) 2017 Ansible, Inc.2# All Rights Reserved.3from django.conf.urls import url4from awx.api.views import (5 OrganizationList,6 OrganizationDetail,7 OrganizationUsersList,8 OrganizationAdminsList,9 OrganizationInventoriesList,10 OrganizationProjectsList,11 OrganizationWorkflowJobTemplatesList,12 OrganizationTeamsList,13 OrganizationCredentialList,14 OrganizationActivityStreamList,15 OrganizationNotificationTemplatesList,16 OrganizationNotificationTemplatesAnyList,17 OrganizationNotificationTemplatesErrorList,18 OrganizationNotificationTemplatesSuccessList,19 OrganizationInstanceGroupsList,20 OrganizationObjectRolesList,21 OrganizationAccessList,22 OrganizationApplicationList,23)24urls = [ 25 url(r'^$', OrganizationList.as_view(), name='organization_list'),26 url(r'^(?P<pk>[0-9]+)/$', OrganizationDetail.as_view(), name='organization_detail'),27 url(r'^(?P<pk>[0-9]+)/users/$', OrganizationUsersList.as_view(), name='organization_users_list'),28 url(r'^(?P<pk>[0-9]+)/admins/$', OrganizationAdminsList.as_view(), name='organization_admins_list'),29 url(r'^(?P<pk>[0-9]+)/inventories/$', OrganizationInventoriesList.as_view(), name='organization_inventories_list'),30 url(r'^(?P<pk>[0-9]+)/projects/$', OrganizationProjectsList.as_view(), name='organization_projects_list'),31 url(r'^(?P<pk>[0-9]+)/workflow_job_templates/$', OrganizationWorkflowJobTemplatesList.as_view(), name='organization_workflow_job_templates_list'),32 url(r'^(?P<pk>[0-9]+)/teams/$', OrganizationTeamsList.as_view(), name='organization_teams_list'),33 url(r'^(?P<pk>[0-9]+)/credentials/$', OrganizationCredentialList.as_view(), name='organization_credential_list'),34 url(r'^(?P<pk>[0-9]+)/activity_stream/$', OrganizationActivityStreamList.as_view(), name='organization_activity_stream_list'),35 url(r'^(?P<pk>[0-9]+)/notification_templates/$', OrganizationNotificationTemplatesList.as_view(), name='organization_notification_templates_list'),36 url(r'^(?P<pk>[0-9]+)/notification_templates_any/$', OrganizationNotificationTemplatesAnyList.as_view(),37 name='organization_notification_templates_any_list'),38 url(r'^(?P<pk>[0-9]+)/notification_templates_error/$', OrganizationNotificationTemplatesErrorList.as_view(),39 name='organization_notification_templates_error_list'),40 url(r'^(?P<pk>[0-9]+)/notification_templates_success/$', OrganizationNotificationTemplatesSuccessList.as_view(),41 name='organization_notification_templates_success_list'),42 url(r'^(?P<pk>[0-9]+)/instance_groups/$', OrganizationInstanceGroupsList.as_view(), name='organization_instance_groups_list'),43 url(r'^(?P<pk>[0-9]+)/object_roles/$', OrganizationObjectRolesList.as_view(), name='organization_object_roles_list'),44 url(r'^(?P<pk>[0-9]+)/access_list/$', OrganizationAccessList.as_view(), name='organization_access_list'),45 url(r'^(?P<pk>[0-9]+)/applications/$', OrganizationApplicationList.as_view(), name='organization_applications_list'),46]...

Full Screen

Full Screen

OrganizationInfo.py

Source:OrganizationInfo.py Github

copy

Full Screen

1# coding=utf82# Copyright 2018 JDCLOUD.COM3#4# Licensed under the Apache License, Version 2.0 (the "License");5# you may not use this file except in compliance with the License.6# You may obtain a copy of the License at7#8# http://www.apache.org/licenses/LICENSE-2.09#10# Unless required by applicable law or agreed to in writing, software11# distributed under the License is distributed on an "AS IS" BASIS,12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13# See the License for the specific language governing permissions and14# limitations under the License.15#16# NOTE: This class is auto generated by the jdcloud code generator program.17class OrganizationInfo(object):18 def __init__(self, organizationCode=None, organizationName=None, organizationFullPath=None, organizationFullname=None, organizationLevel=None):19 """20 :param organizationCode: (Optional) 组织机构编码21 :param organizationName: (Optional) 组织机构名称22 :param organizationFullPath: (Optional) 组织机构全路径23 :param organizationFullname: (Optional) 组织机构全名24 :param organizationLevel: (Optional) 组织机构级别25 """26 self.organizationCode = organizationCode27 self.organizationName = organizationName28 self.organizationFullPath = organizationFullPath29 self.organizationFullname = organizationFullname...

Full Screen

Full Screen

urls.py

Source:urls.py Github

copy

Full Screen

1from django.urls import path, include2from .views.organization_organs_inventory import organization_organs_inventory3from .views.organization_add_edit_organ import organization_add_edit_organ4from .views.organization_directory import organization_directory5from .views.organization_organ_details import organization_organ_details6from .views.organization_organs_list import organization_organs_list7from .views.organization_analytics import organization_analytics8from .views.organization_organization_details import organization_organization_details9urlpatterns = [10 path('organization_organs_inventory', organization_organs_inventory,11 name='organization_organs_inventory'),12 path('organization_add_edit_organ', organization_add_edit_organ,13 name='organization_add_edit_organ'),14 path('organization_directory', organization_directory,15 name='organization_directory'),16 path('organization_organ_details', organization_organ_details,17 name='organization_organ_details'),18 path('organization_organs_list', organization_organs_list,19 name='organization_organs_list'),20 path('organization_analytics', organization_analytics,21 name='organization_analytics'),22 path('organization_organization_details', organization_organization_details,23 name='organization_organization_details'),...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var Organization = require('argos-sdk/src/Models/Account/Organization');2var org = new Organization();3var Organization = require('argos-sdk/src/Models/Account/Organization');4var org = new Organization();5org.getOrganizationInfo().then(function (result) {6 console.log(result);7}).fail(function (error) {8 console.log(error);9});10var Organization = require('argos-sdk/src/Models/Account/Organization');11var org = new Organization();12org.getOrganizationInfo().then(function (result) {13 console.log(result);14}).fail(function (error) {15 console.log(error);16});17var Organization = require('argos-sdk/src/Models/Account/Organization');18var org = new Organization();19org.getOrganizationInfo().then(function (result) {20 console.log(result);21}).fail(function (error) {22 console.log(error);23});24var Organization = require('argos-sdk/src/Models/Account/Organization');25var org = new Organization();26org.getOrganizationInfo().then(function (result) {27 console.log(result);28}).fail(function (error) {29 console.log(error);30});31var Organization = require('argos-sdk/src/Models/Account/Organization');32var org = new Organization();33org.getOrganizationInfo().then(function (result) {34 console.log(result);35}).fail(function (error) {36 console.log(error);37});38var Organization = require('argos-sdk/src/Models/Account/Organization');39var org = new Organization();40org.getOrganizationInfo().then(function (result) {41 console.log(result);42}).fail(function (error) {43 console.log(error);44});45var Organization = require('argos-sdk/src/Models/Account/Organization');46var org = new Organization();47org.getOrganizationInfo().then(function (result) {48 console.log(result);49}).fail(function (error) {50 console.log(error);51});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Organization = require('argos-sdk/Models/Organization').default;2var org = new Organization();3org.getOrganizationName().then(function(name) {4 console.log('Organization Name: ' + name);5});6import Organization from 'argos-sdk/Models/Organization';7var org = new Organization();8org.getOrganizationName().then(function(name) {9 console.log('Organization Name: ' + name);10});11import { Organization } from 'argos-sdk/Models/Organization';12var org = new Organization();13org.getOrganizationName().then(function(name) {14 console.log('Organization Name: ' + name);15});16import { Organization } from 'argos-sdk/Models';17var org = new Organization();18org.getOrganizationName().then(function(name) {19 console.log('Organization Name: ' + name);20});21import { Organization } from 'argos-sdk';22var org = new Organization();23org.getOrganizationName().then(function(name) {24 console.log('Organization Name: ' + name);25});26import Organization from 'argos-sdk';27var org = new Organization();28org.getOrganizationName().then(function(name) {29 console.log('Organization Name: ' + name);30});31var Organization = require('argos-sdk');32var org = new Organization();33org.getOrganizationName().then(function(name) {34 console.log('Organization Name: ' + name);35});36var Organization = require('argos-sdk/Models');37var org = new Organization();38org.getOrganizationName().then(function(name) {39 console.log('Organization Name: ' + name);40});41var Organization = require('argos-sdk/Models/Organization');42var org = new Organization();43org.getOrganizationName().then(function(name) {44 console.log('Organization Name: ' + name);45});

Full Screen

Using AI Code Generation

copy

Full Screen

1const sdk = require('argos-sdk');2const Organization = sdk.Organization;3const organization = new Organization();4organization.getOrganization('orgid').then((org) => {5 console.log(org);6});7const sdk = require('argos-sdk');8const Organization = sdk.Organization;9const organization = new Organization();10organization.getOrganization('orgid').then((org) => {11 console.log(org);12});13const sdk = require('argos-sdk');14const Organization = sdk.Organization;15const organization = new Organization();16organization.getOrganization('orgid').then((org) => {17 console.log(org);18});19const sdk = require('argos-sdk');20const Organization = sdk.Organization;21const organization = new Organization();22organization.getOrganization('orgid').then((org) => {23 console.log(org);24});25const sdk = require('argos-sdk');26const Organization = sdk.Organization;27const organization = new Organization();28organization.getOrganization('orgid').then((org) => {29 console.log(org);30});31const sdk = require('argos-sdk');32const Organization = sdk.Organization;33const organization = new Organization();34organization.getOrganization('orgid').then((org) => {35 console.log(org);36});37const sdk = require('argos-sdk');38const Organization = sdk.Organization;39const organization = new Organization();40organization.getOrganization('orgid').then((org) => {41 console.log(org);42});43const sdk = require('argos-sdk');44const Organization = sdk.Organization;45const organization = new Organization();46organization.getOrganization('orgid').then((org) => {47 console.log(org);48});49const sdk = require('argos-sdk');50const Organization = sdk.Organization;51const organization = new Organization();52organization.getOrganization('orgid').then((org) => {53 console.log(org);54});

Full Screen

Using AI Code Generation

copy

Full Screen

1var Organization = require('argos-sdk/src/Organization')2var org = new Organization()3org.getOrganizationId().then(function(orgId) {4 console.log(orgId)5})6var Organization = require('argos-sdk/src/Organization')7var org = new Organization()8org.getOrganizationId().then(function(orgId) {9 console.log(orgId)10})11var Organization = require('argos-sdk/src/Organization')12var org = new Organization()13org.getOrganizationId().then(function(orgId) {14 console.log(orgId)15})16var Organization = require('argos-sdk/src/Organization')17var org = new Organization()18org.getOrganizationId().then(function(orgId) {19 console.log(orgId)20})21var Organization = require('argos-sdk/src/Organization')22var org = new Organization()23org.getOrganizationId().then(function(orgId) {24 console.log(orgId)25})26var Organization = require('argos-sdk/src/Organization')27var org = new Organization()28org.getOrganizationId().then(function(orgId) {29 console.log(orgId)30})31var Organization = require('argos-sdk/src/Organization')32var org = new Organization()33org.getOrganizationId().then(function(orgId) {34 console.log(orgId)35})36var Organization = require('argos-sdk/src/Organization')37var org = new Organization()38org.getOrganizationId().then(function(orgId) {39 console.log(orgId)40})41var Organization = require('argos-sdk/src/Organization')42var org = new Organization()43org.getOrganizationId().then(function(orgId) {44 console.log(orgId)45})46var Organization = require('argos-sdk/src/Organization')47var org = new Organization()

Full Screen

Using AI Code Generation

copy

Full Screen

1var Organization = require('argos-sdk/models/Organization');2var org = new Organization();3org.getOrganization('orgId').then(function(org) {4 console.log(org);5});6var Organization = require('./models/Organization');7module.exports = {8 models: {9 }10};11var lang = require('argos-sdk/lang');12var MODEL_TYPES = require('argos-sdk/Models/Types');13var MODEL_NAMES = require('argos-sdk/Models/Names');14var MODEL_BASE = require('argos-sdk/Models/_ModelBase');15var __class = lang.declare(MODEL_BASE, {16 createQueryModels: function createQueryModels() {17 return [{18 }, {19 }];20 }21});22lang.setObject('icboe.Models.Organization', __class);23module.exports = __class;24var lang = require('argos-sdk/lang');25var MODEL_BASE = require('argos-sdk/Models/_OfflineModelBase');26var MODEL_NAMES = require('argos-sdk/Models/Names');27var __class = lang.declare(MODEL_BASE, {28 createQueryModels: function createQueryModels() {29 return [{

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful