How to use test_objects method in assertpy

Best Python code snippet using assertpy_python

test_models.py

Source:test_models.py Github

copy

Full Screen

1from mayan.apps.acls.models import AccessControlList2from mayan.apps.testing.tests.base import BaseTestCase3from ..models import EventSubscription, Notification, ObjectEventSubscription4from ..permissions import permission_events_view5from .mixins import NotificationTestMixin6class EventNotificationModelTestCase(NotificationTestMixin, BaseTestCase):7 def setUp(self):8 super().setUp()9 self._create_test_event_type()10 self._create_local_test_user()11 self._create_local_test_object()12 def test_event_notification_single_user_no_permission(self):13 notification_count = Notification.objects.count()14 EventSubscription.objects.create(15 stored_event_type=self.test_event_type.stored_event_type,16 user=self.test_user17 )18 self.test_event_type.commit(target=self.test_object)19 self.assertEqual(Notification.objects.count(), notification_count)20 def test_event_notification_single_user_with_access(self):21 notification_count = Notification.objects.count()22 EventSubscription.objects.create(23 stored_event_type=self.test_event_type.stored_event_type,24 user=self.test_user25 )26 AccessControlList.objects.grant(27 obj=self.test_object, permission=permission_events_view,28 role=self.test_role29 )30 result = self.test_event_type.commit(target=self.test_object)31 self.assertEqual(Notification.objects.count(), notification_count + 1)32 notification = Notification.objects.first()33 self.assertEqual(notification.user, self.test_user)34 self.assertEqual(notification.action, result)35 def test_event_notification_multiple_users_with_user_0_access(self):36 self._create_local_test_user()37 notification_count = Notification.objects.count()38 EventSubscription.objects.create(39 stored_event_type=self.test_event_type.stored_event_type,40 user=self.test_users[0]41 )42 EventSubscription.objects.create(43 stored_event_type=self.test_event_type.stored_event_type,44 user=self.test_users[1]45 )46 AccessControlList.objects.grant(47 obj=self.test_object, permission=permission_events_view,48 role=self.test_roles[0]49 )50 result = self.test_event_type.commit(target=self.test_object)51 self.assertEqual(Notification.objects.count(), notification_count + 1)52 notification = Notification.objects.first()53 self.assertEqual(notification.user, self.test_users[0])54 self.assertEqual(notification.action, result)55 def test_event_notification_multiple_users_with_user_1_access(self):56 self._create_local_test_user()57 notification_count = Notification.objects.count()58 EventSubscription.objects.create(59 stored_event_type=self.test_event_type.stored_event_type,60 user=self.test_users[0]61 )62 EventSubscription.objects.create(63 stored_event_type=self.test_event_type.stored_event_type,64 user=self.test_users[1]65 )66 AccessControlList.objects.grant(67 obj=self.test_object, permission=permission_events_view,68 role=self.test_roles[1]69 )70 result = self.test_event_type.commit(target=self.test_object)71 self.assertEqual(Notification.objects.count(), notification_count + 1)72 notification = Notification.objects.first()73 self.assertEqual(notification.user, self.test_users[1])74 self.assertEqual(notification.action, result)75 def test_event_notification_multiple_users_with_all_user_access(self):76 self._create_local_test_user()77 notification_count = Notification.objects.count()78 EventSubscription.objects.create(79 stored_event_type=self.test_event_type.stored_event_type,80 user=self.test_users[0]81 )82 EventSubscription.objects.create(83 stored_event_type=self.test_event_type.stored_event_type,84 user=self.test_users[1]85 )86 AccessControlList.objects.grant(87 obj=self.test_object, permission=permission_events_view,88 role=self.test_roles[0]89 )90 AccessControlList.objects.grant(91 obj=self.test_object, permission=permission_events_view,92 role=self.test_roles[1]93 )94 result = self.test_event_type.commit(target=self.test_object)95 self.assertEqual(Notification.objects.count(), notification_count + 2)96 notifications = Notification.objects.all()97 user_pk_list = notifications.values_list('user__id', flat=True)98 self.assertTrue(self.test_users[0].pk in user_pk_list)99 self.assertEqual(notifications[0].action, result)100 self.assertTrue(self.test_users[1].pk in user_pk_list)101 self.assertEqual(notifications[1].action, result)102class ObjectEventNotificationModelTestCase(NotificationTestMixin, BaseTestCase):103 def setUp(self):104 super().setUp()105 self._create_test_event_type()106 self._create_local_test_user()107 self._create_local_test_object()108 def test_object_notification_single_user_no_permission(self):109 notification_count = Notification.objects.count()110 ObjectEventSubscription.objects.create(111 content_object=self.test_object,112 stored_event_type=self.test_event_type.stored_event_type,113 user=self.test_user114 )115 self.test_event_type.commit(target=self.test_object)116 self.assertEqual(Notification.objects.count(), notification_count)117 def test_object_notification_single_user_with_access(self):118 notification_count = Notification.objects.count()119 ObjectEventSubscription.objects.create(120 content_object=self.test_object,121 stored_event_type=self.test_event_type.stored_event_type,122 user=self.test_user123 )124 AccessControlList.objects.grant(125 obj=self.test_object, permission=permission_events_view,126 role=self.test_role127 )128 result = self.test_event_type.commit(target=self.test_object)129 self.assertEqual(Notification.objects.count(), notification_count + 1)130 notification = Notification.objects.first()131 self.assertEqual(notification.user, self.test_user)132 self.assertEqual(notification.action, result)133 def test_object_notification_single_user_and_multiple_objects_with_object_0_access(self):134 self._create_local_test_object()135 notification_count = Notification.objects.count()136 ObjectEventSubscription.objects.create(137 content_object=self.test_objects[0],138 stored_event_type=self.test_event_type.stored_event_type,139 user=self.test_user140 )141 ObjectEventSubscription.objects.create(142 content_object=self.test_objects[1],143 stored_event_type=self.test_event_type.stored_event_type,144 user=self.test_user145 )146 AccessControlList.objects.grant(147 obj=self.test_objects[0], permission=permission_events_view,148 role=self.test_role149 )150 result_0 = self.test_event_type.commit(target=self.test_objects[0])151 self.test_event_type.commit(target=self.test_objects[1])152 self.assertEqual(Notification.objects.count(), notification_count + 1)153 notification = Notification.objects.first()154 self.assertEqual(notification.user, self.test_user)155 self.assertEqual(notification.action, result_0)156 def test_object_notification_single_user_and_multiple_objects_with_object_0_target_access(self):157 self._create_local_test_object()158 notification_count = Notification.objects.count()159 ObjectEventSubscription.objects.create(160 content_object=self.test_objects[0],161 stored_event_type=self.test_event_type.stored_event_type,162 user=self.test_user163 )164 ObjectEventSubscription.objects.create(165 content_object=self.test_objects[1],166 stored_event_type=self.test_event_type.stored_event_type,167 user=self.test_user168 )169 AccessControlList.objects.grant(170 obj=self.test_objects[0], permission=permission_events_view,171 role=self.test_role172 )173 result_0 = self.test_event_type.commit(174 target=self.test_objects[0], action_object=self.test_objects[1]175 )176 self.assertEqual(Notification.objects.count(), notification_count + 1)177 notification = Notification.objects.first()178 self.assertEqual(notification.user, self.test_user)179 self.assertEqual(notification.action, result_0)180 def test_object_notification_single_user_and_multiple_objects_with_object_1_action_object_access(self):181 self._create_local_test_object()182 notification_count = Notification.objects.count()183 ObjectEventSubscription.objects.create(184 content_object=self.test_objects[0],185 stored_event_type=self.test_event_type.stored_event_type,186 user=self.test_user187 )188 ObjectEventSubscription.objects.create(189 content_object=self.test_objects[1],190 stored_event_type=self.test_event_type.stored_event_type,191 user=self.test_user192 )193 AccessControlList.objects.grant(194 obj=self.test_objects[1], permission=permission_events_view,195 role=self.test_role196 )197 result_0 = self.test_event_type.commit(198 target=self.test_objects[0], action_object=self.test_objects[1]199 )200 self.assertEqual(Notification.objects.count(), notification_count + 1)201 notification = Notification.objects.first()202 self.assertEqual(notification.user, self.test_user)203 self.assertEqual(notification.action, result_0)204 def test_object_notification_multiple_users_and_single_object_with_user_0_access(self):205 self._create_local_test_user()206 notification_count = Notification.objects.count()207 ObjectEventSubscription.objects.create(208 content_object=self.test_objects[0],209 stored_event_type=self.test_event_type.stored_event_type,210 user=self.test_users[0]211 )212 ObjectEventSubscription.objects.create(213 content_object=self.test_objects[0],214 stored_event_type=self.test_event_type.stored_event_type,215 user=self.test_users[1]216 )217 AccessControlList.objects.grant(218 obj=self.test_objects[0], permission=permission_events_view,219 role=self.test_roles[0]220 )221 result_0 = self.test_event_type.commit(target=self.test_objects[0])222 self.assertEqual(Notification.objects.count(), notification_count + 1)223 notification = Notification.objects.first()224 self.assertEqual(notification.user, self.test_users[0])225 self.assertEqual(notification.action, result_0)226 def test_object_notification_multiple_users_and_single_object_with_user_1_access(self):227 self._create_local_test_user()228 notification_count = Notification.objects.count()229 ObjectEventSubscription.objects.create(230 content_object=self.test_objects[0],231 stored_event_type=self.test_event_type.stored_event_type,232 user=self.test_users[0]233 )234 ObjectEventSubscription.objects.create(235 content_object=self.test_objects[0],236 stored_event_type=self.test_event_type.stored_event_type,237 user=self.test_users[1]238 )239 AccessControlList.objects.grant(240 obj=self.test_objects[0], permission=permission_events_view,241 role=self.test_roles[1]242 )243 result_0 = self.test_event_type.commit(target=self.test_objects[0])244 self.assertEqual(Notification.objects.count(), notification_count + 1)245 notification = Notification.objects.first()246 self.assertEqual(notification.user, self.test_users[1])247 self.assertEqual(notification.action, result_0)248 def test_object_notification_multiple_users_and_single_object_with_both_user_access(self):249 self._create_local_test_user()250 notification_count = Notification.objects.count()251 ObjectEventSubscription.objects.create(252 content_object=self.test_objects[0],253 stored_event_type=self.test_event_type.stored_event_type,254 user=self.test_users[0]255 )256 ObjectEventSubscription.objects.create(257 content_object=self.test_objects[0],258 stored_event_type=self.test_event_type.stored_event_type,259 user=self.test_users[1]260 )261 AccessControlList.objects.grant(262 obj=self.test_objects[0], permission=permission_events_view,263 role=self.test_roles[0]264 )265 AccessControlList.objects.grant(266 obj=self.test_objects[0], permission=permission_events_view,267 role=self.test_roles[1]268 )269 result_0 = self.test_event_type.commit(target=self.test_objects[0])270 self.assertEqual(Notification.objects.count(), notification_count + 2)271 notifications = Notification.objects.all()272 user_pk_list = notifications.values_list('user__id', flat=True)273 self.assertTrue(self.test_users[0].pk in user_pk_list)274 self.assertEqual(notifications[0].action, result_0)275 self.assertTrue(self.test_users[1].pk in user_pk_list)276 self.assertEqual(notifications[1].action, result_0)277 def test_object_notification_multiple_users_and_multiple_object_with_user_0_and_object_0_access(self):278 self._create_local_test_user()279 self._create_local_test_object()280 notification_count = Notification.objects.count()281 ObjectEventSubscription.objects.create(282 content_object=self.test_objects[0],283 stored_event_type=self.test_event_type.stored_event_type,284 user=self.test_users[0]285 )286 ObjectEventSubscription.objects.create(287 content_object=self.test_objects[1],288 stored_event_type=self.test_event_type.stored_event_type,289 user=self.test_users[0]290 )291 ObjectEventSubscription.objects.create(292 content_object=self.test_objects[0],293 stored_event_type=self.test_event_type.stored_event_type,294 user=self.test_users[1]295 )296 ObjectEventSubscription.objects.create(297 content_object=self.test_objects[1],298 stored_event_type=self.test_event_type.stored_event_type,299 user=self.test_users[1]300 )301 AccessControlList.objects.grant(302 obj=self.test_objects[0], permission=permission_events_view,303 role=self.test_roles[0]304 )305 result_0 = self.test_event_type.commit(target=self.test_objects[0])306 self.test_event_type.commit(target=self.test_objects[1])307 self.assertEqual(Notification.objects.count(), notification_count + 1)308 notifications = Notification.objects.all()309 self.assertEqual(notifications[0].user, self.test_users[0])310 self.assertEqual(notifications[0].action, result_0)311 def test_object_notification_multiple_users_and_multiple_object_with_user_0_and_object_0_action_object_access(self):312 self._create_local_test_user()313 self._create_local_test_object()314 notification_count = Notification.objects.count()315 ObjectEventSubscription.objects.create(316 content_object=self.test_objects[0],317 stored_event_type=self.test_event_type.stored_event_type,318 user=self.test_users[0]319 )320 ObjectEventSubscription.objects.create(321 content_object=self.test_objects[1],322 stored_event_type=self.test_event_type.stored_event_type,323 user=self.test_users[0]324 )325 ObjectEventSubscription.objects.create(326 content_object=self.test_objects[0],327 stored_event_type=self.test_event_type.stored_event_type,328 user=self.test_users[1]329 )330 ObjectEventSubscription.objects.create(331 content_object=self.test_objects[1],332 stored_event_type=self.test_event_type.stored_event_type,333 user=self.test_users[1]334 )335 AccessControlList.objects.grant(336 obj=self.test_objects[0], permission=permission_events_view,337 role=self.test_roles[0]338 )339 result_0 = self.test_event_type.commit(340 action_object=self.test_objects[1], target=self.test_objects[0]341 )342 result_1 = self.test_event_type.commit(343 action_object=self.test_objects[0], target=self.test_objects[1]344 )345 self.assertEqual(Notification.objects.count(), notification_count + 2)346 notifications = Notification.objects.all()347 self.assertEqual(notifications[0].user, self.test_users[0])348 self.assertEqual(notifications[0].action, result_1)349 self.assertEqual(notifications[1].user, self.test_users[0])...

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 assertpy 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