How to use add_project method in dbt-osmosis

Best Python code snippet using dbt-osmosis_python

test_direct_rel.py

Source:test_direct_rel.py Github

copy

Full Screen

1from django.contrib.auth import get_user_model2from django.contrib.auth.models import Group, Permission3from django.test import TestCase4from guardian.shortcuts import assign_perm5from guardian.shortcuts import get_groups_with_perms6from guardian.shortcuts import get_objects_for_group7from guardian.shortcuts import get_objects_for_user8from guardian.shortcuts import get_users_with_perms9from guardian.shortcuts import remove_perm10from guardian.testapp.models import Mixed, ReverseMixed11from guardian.testapp.models import Project12from guardian.testapp.models import ProjectGroupObjectPermission13from guardian.testapp.models import ProjectUserObjectPermission14from guardian.testapp.tests.conf import skipUnlessTestApp15User = get_user_model()16@skipUnlessTestApp17class TestDirectUserPermissions(TestCase):18 def setUp(self):19 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')20 self.project = Project.objects.create(name='Foobar')21 def get_perm(self, codename):22 filters = {'content_type__app_label': 'testapp', 'codename': codename}23 return Permission.objects.get(**filters)24 def test_after_perm_is_created_without_shortcut(self):25 perm = self.get_perm('add_project')26 # we should not use assign here - if generic user obj perms model is27 # used then everything could go fine if using assign shortcut and we28 # would not be able to see any problem29 ProjectUserObjectPermission.objects.create(30 user=self.joe,31 permission=perm,32 content_object=self.project,33 )34 self.assertTrue(self.joe.has_perm('add_project', self.project))35 def test_assign_perm(self):36 assign_perm('add_project', self.joe, self.project)37 filters = {38 'content_object': self.project,39 'permission__codename': 'add_project',40 'user': self.joe,41 }42 result = ProjectUserObjectPermission.objects.filter(**filters).count()43 self.assertEqual(result, 1)44 def test_remove_perm(self):45 assign_perm('add_project', self.joe, self.project)46 filters = {47 'content_object': self.project,48 'permission__codename': 'add_project',49 'user': self.joe,50 }51 result = ProjectUserObjectPermission.objects.filter(**filters).count()52 self.assertEqual(result, 1)53 remove_perm('add_project', self.joe, self.project)54 result = ProjectUserObjectPermission.objects.filter(**filters).count()55 self.assertEqual(result, 0)56 def test_get_users_with_perms(self):57 User.objects.create_user('john', 'john@foobar.com', 'john')58 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')59 assign_perm('add_project', self.joe, self.project)60 assign_perm('change_project', self.joe, self.project)61 assign_perm('change_project', jane, self.project)62 self.assertEqual(get_users_with_perms(self.project, attach_perms=True),63 {64 self.joe: ['add_project', 'change_project'],65 jane: ['change_project'],66 })67 def test_get_users_with_perms_plus_groups(self):68 User.objects.create_user('john', 'john@foobar.com', 'john')69 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')70 group = Group.objects.create(name='devs')71 self.joe.groups.add(group)72 assign_perm('add_project', self.joe, self.project)73 assign_perm('change_project', group, self.project)74 assign_perm('change_project', jane, self.project)75 self.assertEqual(get_users_with_perms(self.project, attach_perms=True),76 {77 self.joe: ['add_project', 'change_project'],78 jane: ['change_project'],79 })80 def test_get_objects_for_user(self):81 foo = Project.objects.create(name='foo')82 bar = Project.objects.create(name='bar')83 assign_perm('add_project', self.joe, foo)84 assign_perm('add_project', self.joe, bar)85 assign_perm('change_project', self.joe, bar)86 result = get_objects_for_user(self.joe, 'testapp.add_project')87 self.assertEqual(sorted(p.pk for p in result),88 sorted([foo.pk, bar.pk]))89 def test_get_all_permissions(self):90 foo = Project.objects.create(name='foo')91 assign_perm('add_project', self.joe, foo)92 assign_perm('change_project', self.joe, foo)93 result = self.joe.get_all_permissions(foo)94 self.assertEqual(result, set(('add_project', 'change_project')))95 def test_get_all_permissions_no_object(self):96 foo = Project.objects.create(name='foo')97 assign_perm('add_project', self.joe, foo)98 assign_perm('change_project', self.joe, foo)99 result = self.joe.get_all_permissions()100 self.assertEqual(result, set())101@skipUnlessTestApp102class TestDirectGroupPermissions(TestCase):103 def setUp(self):104 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')105 self.group = Group.objects.create(name='admins')106 self.joe.groups.add(self.group)107 self.project = Project.objects.create(name='Foobar')108 def get_perm(self, codename):109 filters = {'content_type__app_label': 'testapp', 'codename': codename}110 return Permission.objects.get(**filters)111 def test_after_perm_is_created_without_shortcut(self):112 perm = self.get_perm('add_project')113 # we should not use assign here - if generic user obj perms model is114 # used then everything could go fine if using assign shortcut and we115 # would not be able to see any problem116 ProjectGroupObjectPermission.objects.create(117 group=self.group,118 permission=perm,119 content_object=self.project,120 )121 self.assertTrue(self.joe.has_perm('add_project', self.project))122 def test_assign_perm(self):123 assign_perm('add_project', self.group, self.project)124 filters = {125 'content_object': self.project,126 'permission__codename': 'add_project',127 'group': self.group,128 }129 result = ProjectGroupObjectPermission.objects.filter(**filters).count()130 self.assertEqual(result, 1)131 def test_remove_perm(self):132 assign_perm('add_project', self.group, self.project)133 filters = {134 'content_object': self.project,135 'permission__codename': 'add_project',136 'group': self.group,137 }138 result = ProjectGroupObjectPermission.objects.filter(**filters).count()139 self.assertEqual(result, 1)140 remove_perm('add_project', self.group, self.project)141 result = ProjectGroupObjectPermission.objects.filter(**filters).count()142 self.assertEqual(result, 0)143 def test_get_groups_with_perms(self):144 Group.objects.create(name='managers')145 devs = Group.objects.create(name='devs')146 assign_perm('add_project', self.group, self.project)147 assign_perm('change_project', self.group, self.project)148 assign_perm('change_project', devs, self.project)149 self.assertEqual(get_groups_with_perms(self.project, attach_perms=True),150 {151 self.group: ['add_project', 'change_project'],152 devs: ['change_project'],153 })154 def test_get_groups_with_perms_doesnt_spawn_extra_queries_for_more_groups_with_perms(self):155 Group.objects.create(name='managers')156 devs = Group.objects.create(name='devs')157 devs1 = Group.objects.create(name='devs1')158 devs2 = Group.objects.create(name='devs2')159 devs3 = Group.objects.create(name='devs3')160 devs4 = Group.objects.create(name='devs4')161 devs5 = Group.objects.create(name='devs5')162 assign_perm('add_project', self.group, self.project)163 assign_perm('change_project', self.group, self.project)164 for group in [devs, devs1, devs2, devs3, devs4, devs5]:165 assign_perm('add_project', group, self.project)166 assign_perm('change_project', group, self.project)167 with self.assertNumQueries(3):168 result = get_groups_with_perms(self.project, attach_perms=True)169 self.assertEqual(result,170 {171 self.group: ['add_project', 'change_project'],172 devs: ['add_project', 'change_project'],173 devs1: ['add_project', 'change_project'],174 devs2: ['add_project', 'change_project'],175 devs3: ['add_project', 'change_project'],176 devs4: ['add_project', 'change_project'],177 devs5: ['add_project', 'change_project'],178 })179 def test_get_objects_for_group(self):180 foo = Project.objects.create(name='foo')181 bar = Project.objects.create(name='bar')182 assign_perm('add_project', self.group, foo)183 assign_perm('add_project', self.group, bar)184 assign_perm('change_project', self.group, bar)185 result = get_objects_for_group(self.group, 'testapp.add_project')186 self.assertEqual(sorted(p.pk for p in result),187 sorted([foo.pk, bar.pk]))188@skipUnlessTestApp189class TestMixedDirectAndGenericObjectPermission(TestCase):190 def setUp(self):191 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')192 self.group = Group.objects.create(name='admins')193 self.joe.groups.add(self.group)194 self.mixed = Mixed.objects.create(name='Foobar')195 self.reverse_mixed = ReverseMixed.objects.create(name='Foobar')196 def test_get_users_with_perms_plus_groups(self):197 User.objects.create_user('john', 'john@foobar.com', 'john')198 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')199 group = Group.objects.create(name='devs')200 self.joe.groups.add(group)201 assign_perm('add_mixed', self.joe, self.mixed)202 assign_perm('change_mixed', group, self.mixed)203 assign_perm('change_mixed', jane, self.mixed)204 self.assertEqual(get_users_with_perms(self.mixed, attach_perms=True),205 {206 self.joe: ['add_mixed', 'change_mixed'],207 jane: ['change_mixed'],208 })209 result = get_objects_for_user(self.joe, 'testapp.add_mixed')210 self.assertEqual(sorted(p.pk for p in result),211 sorted([self.mixed.pk]))212 def test_get_users_with_perms_plus_groups_reverse_mixed(self):213 User.objects.create_user('john', 'john@foobar.com', 'john')214 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')215 group = Group.objects.create(name='devs')216 self.joe.groups.add(group)217 assign_perm('add_reversemixed', self.joe, self.reverse_mixed)218 assign_perm('change_reversemixed', group, self.reverse_mixed)219 assign_perm('change_reversemixed', jane, self.reverse_mixed)220 self.assertEqual(get_users_with_perms(self.reverse_mixed, attach_perms=True),221 {222 self.joe: ['add_reversemixed', 'change_reversemixed'],223 jane: ['change_reversemixed'],224 })225 result = get_objects_for_user(self.joe, 'testapp.add_reversemixed')226 self.assertEqual(sorted(p.pk for p in result),...

Full Screen

Full Screen

direct_rel_test.py

Source:direct_rel_test.py Github

copy

Full Screen

1from __future__ import unicode_literals2from .testapp.models import Mixed3from .testapp.models import Project4from .testapp.models import ProjectGroupObjectPermission5from .testapp.models import ProjectUserObjectPermission6from django.contrib.auth.models import Group, Permission7from django.test import TestCase8from guardian.compat import get_user_model9from guardian.shortcuts import assign_perm10from guardian.shortcuts import get_groups_with_perms11from guardian.shortcuts import get_objects_for_group12from guardian.shortcuts import get_objects_for_user13from guardian.shortcuts import get_users_with_perms14from guardian.shortcuts import remove_perm15User = get_user_model()16class TestDirectUserPermissions(TestCase):17 def setUp(self):18 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')19 self.project = Project.objects.create(name='Foobar')20 def get_perm(self, codename):21 filters = {'content_type__app_label': 'testapp', 'codename': codename}22 return Permission.objects.get(**filters)23 def test_after_perm_is_created_without_shortcut(self):24 perm = self.get_perm('add_project')25 # we should not use assign here - if generic user obj perms model is26 # used then everything could go fine if using assign shortcut and we27 # would not be able to see any problem28 ProjectUserObjectPermission.objects.create(29 user=self.joe,30 permission=perm,31 content_object=self.project,32 )33 self.assertTrue(self.joe.has_perm('add_project', self.project))34 def test_assign_perm(self):35 assign_perm('add_project', self.joe, self.project)36 filters = {37 'content_object': self.project,38 'permission__codename': 'add_project',39 'user': self.joe,40 }41 result = ProjectUserObjectPermission.objects.filter(**filters).count()42 self.assertEqual(result, 1)43 def test_remove_perm(self):44 assign_perm('add_project', self.joe, self.project)45 filters = {46 'content_object': self.project,47 'permission__codename': 'add_project',48 'user': self.joe,49 }50 result = ProjectUserObjectPermission.objects.filter(**filters).count()51 self.assertEqual(result, 1)52 remove_perm('add_project', self.joe, self.project)53 result = ProjectUserObjectPermission.objects.filter(**filters).count()54 self.assertEqual(result, 0)55 def test_get_users_with_perms(self):56 User.objects.create_user('john', 'john@foobar.com', 'john')57 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')58 assign_perm('add_project', self.joe, self.project)59 assign_perm('change_project', self.joe, self.project)60 assign_perm('change_project', jane, self.project)61 self.assertEqual(get_users_with_perms(self.project, attach_perms=True),62 {63 self.joe: ['add_project', 'change_project'],64 jane: ['change_project'],65 })66 def test_get_users_with_perms_plus_groups(self):67 User.objects.create_user('john', 'john@foobar.com', 'john')68 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')69 group = Group.objects.create(name='devs')70 self.joe.groups.add(group)71 assign_perm('add_project', self.joe, self.project)72 assign_perm('change_project', group, self.project)73 assign_perm('change_project', jane, self.project)74 self.assertEqual(get_users_with_perms(self.project, attach_perms=True),75 {76 self.joe: ['add_project', 'change_project'],77 jane: ['change_project'],78 })79 def test_get_objects_for_user(self):80 foo = Project.objects.create(name='foo')81 bar = Project.objects.create(name='bar')82 assign_perm('add_project', self.joe, foo)83 assign_perm('add_project', self.joe, bar)84 assign_perm('change_project', self.joe, bar)85 result = get_objects_for_user(self.joe, 'testapp.add_project')86 self.assertEqual(sorted(p.pk for p in result), sorted([foo.pk, bar.pk]))87class TestDirectGroupPermissions(TestCase):88 def setUp(self):89 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')90 self.group = Group.objects.create(name='admins')91 self.joe.groups.add(self.group)92 self.project = Project.objects.create(name='Foobar')93 def get_perm(self, codename):94 filters = {'content_type__app_label': 'testapp', 'codename': codename}95 return Permission.objects.get(**filters)96 def test_after_perm_is_created_without_shortcut(self):97 perm = self.get_perm('add_project')98 # we should not use assign here - if generic user obj perms model is99 # used then everything could go fine if using assign shortcut and we100 # would not be able to see any problem101 ProjectGroupObjectPermission.objects.create(102 group=self.group,103 permission=perm,104 content_object=self.project,105 )106 self.assertTrue(self.joe.has_perm('add_project', self.project))107 def test_assign_perm(self):108 assign_perm('add_project', self.group, self.project)109 filters = {110 'content_object': self.project,111 'permission__codename': 'add_project',112 'group': self.group,113 }114 result = ProjectGroupObjectPermission.objects.filter(**filters).count()115 self.assertEqual(result, 1)116 def test_remove_perm(self):117 assign_perm('add_project', self.group, self.project)118 filters = {119 'content_object': self.project,120 'permission__codename': 'add_project',121 'group': self.group,122 }123 result = ProjectGroupObjectPermission.objects.filter(**filters).count()124 self.assertEqual(result, 1)125 remove_perm('add_project', self.group, self.project)126 result = ProjectGroupObjectPermission.objects.filter(**filters).count()127 self.assertEqual(result, 0)128 def test_get_groups_with_perms(self):129 Group.objects.create(name='managers')130 devs = Group.objects.create(name='devs')131 assign_perm('add_project', self.group, self.project)132 assign_perm('change_project', self.group, self.project)133 assign_perm('change_project', devs, self.project)134 self.assertEqual(get_groups_with_perms(self.project, attach_perms=True),135 {136 self.group: ['add_project', 'change_project'],137 devs: ['change_project'],138 })139 def test_get_objects_for_group(self):140 foo = Project.objects.create(name='foo')141 bar = Project.objects.create(name='bar')142 assign_perm('add_project', self.group, foo)143 assign_perm('add_project', self.group, bar)144 assign_perm('change_project', self.group, bar)145 result = get_objects_for_group(self.group, 'testapp.add_project')146 self.assertEqual(sorted(p.pk for p in result), sorted([foo.pk, bar.pk]))147class TestMixedDirectAndGenericObjectPermission(TestCase):148 def setUp(self):149 self.joe = User.objects.create_user('joe', 'joe@example.com', 'foobar')150 self.group = Group.objects.create(name='admins')151 self.joe.groups.add(self.group)152 self.mixed = Mixed.objects.create(name='Foobar')153 def test_get_users_with_perms_plus_groups(self):154 User.objects.create_user('john', 'john@foobar.com', 'john')155 jane = User.objects.create_user('jane', 'jane@foobar.com', 'jane')156 group = Group.objects.create(name='devs')157 self.joe.groups.add(group)158 assign_perm('add_mixed', self.joe, self.mixed)159 assign_perm('change_mixed', group, self.mixed)160 assign_perm('change_mixed', jane, self.mixed)161 self.assertEqual(get_users_with_perms(self.mixed, attach_perms=True),162 {163 self.joe: ['add_mixed', 'change_mixed'],164 jane: ['change_mixed'],...

Full Screen

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 dbt-osmosis 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