Best Python code snippet using pytest-django_python
skip_test_inforequest.py
Source:skip_test_inforequest.py
...191 def test_prefetch_branches_staticmethod(self):192 inforequest, branch1, actions = self._create_inforequest_scenario(u'advancement')193 _, (_, ((branch2, _),)) = actions194 # Without arguments195 with self.assertNumQueries(2):196 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)197 with self.assertNumQueries(0):198 self.assertEqual(inforequest.branches, [branch1, branch2])199 # With custom path and queryset200 with self.assertNumQueries(3):201 user = (User.objects202 .prefetch_related(u'inforequest_set')203 .prefetch_related(Inforequest.prefetch_branches(u'inforequest_set', Branch.objects.extra(select=dict(moo=47))))204 .get(pk=self.user1.pk))205 with self.assertNumQueries(0):206 self.assertEqual(user.inforequest_set.all()[0].branches, [branch1, branch2])207 self.assertEqual(user.inforequest_set.all()[0].branches[0].moo, 47)208 def test_branches_property(self):209 inforequest, branch1, actions = self._create_inforequest_scenario(u'advancement')210 _, (_, ((branch2, _),)) = actions211 # Property is cached212 with self.assertNumQueries(1):213 inforequest = Inforequest.objects.get(pk=inforequest.pk)214 with self.assertNumQueries(1):215 self.assertEqual(inforequest.branches, [branch1, branch2])216 with self.assertNumQueries(0):217 self.assertEqual(inforequest.branches, [branch1, branch2])218 # Property is prefetched with prefetch_branches()219 with self.assertNumQueries(2):220 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)221 with self.assertNumQueries(0):222 self.assertEqual(inforequest.branches, [branch1, branch2])223 def test_prefetch_main_branch_staticmethod(self):224 inforequest, branch, _ = self._create_inforequest_scenario(u'advancement')225 # Without arguments226 with self.assertNumQueries(2):227 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_main_branch()).get(pk=inforequest.pk)228 with self.assertNumQueries(0):229 self.assertEqual(inforequest._main_branch, [branch])230 # With custom path and queryset231 with self.assertNumQueries(3):232 user = (User.objects233 .prefetch_related(u'inforequest_set')234 .prefetch_related(Inforequest.prefetch_main_branch(u'inforequest_set', Branch.objects.extra(select=dict(moo=47))))235 .get(pk=self.user1.pk))236 with self.assertNumQueries(0):237 self.assertEqual(user.inforequest_set.all()[0]._main_branch, [branch])238 self.assertEqual(user.inforequest_set.all()[0]._main_branch[0].moo, 47)239 def test_main_branch_property(self):240 inforequest, branch, _ = self._create_inforequest_scenario(u'advancement')241 # Property is cached242 with self.assertNumQueries(1):243 inforequest = Inforequest.objects.get(pk=inforequest.pk)244 with self.assertNumQueries(1):245 self.assertEqual(inforequest.main_branch, branch)246 with self.assertNumQueries(0):247 self.assertEqual(inforequest.main_branch, branch)248 # Property uses cached branches property249 with self.assertNumQueries(1):250 inforequest = Inforequest.objects.get(pk=inforequest.pk)251 with self.assertNumQueries(1):252 inforequest.branches253 with self.assertNumQueries(0):254 self.assertEqual(inforequest.main_branch, branch)255 # Property is prefetched with prefetch_main_branch()256 with self.assertNumQueries(2):257 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_main_branch()).get(pk=inforequest.pk)258 with self.assertNumQueries(0):259 self.assertEqual(inforequest.main_branch, branch)260 # Property is prefetched with prefetch_branches()261 with self.assertNumQueries(2):262 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)263 with self.assertNumQueries(0):264 self.assertEqual(inforequest.main_branch, branch)265 def test_main_branch_property_raises_exception_if_there_is_no_main_branch(self):266 inforequest = self._create_inforequest()267 with self.assertRaisesMessage(Branch.DoesNotExist, u'Inforequest has no main branch.'):268 inforequest.main_branch269 def test_main_branch_property_raises_exception_if_there_are_multiple_main_branches(self):270 inforequest = self._create_inforequest()271 branch1 = self._create_branch(inforequest=inforequest)272 branch2 = self._create_branch(inforequest=inforequest)273 with self.assertRaisesMessage(Branch.MultipleObjectsReturned, u'Inforequest has more than one main branch.'):274 inforequest.main_branch275 def test_undecided_emails_set_property(self):276 inforequest, _, _ = self._create_inforequest_scenario()277 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)278 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)279 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)280 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)281 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)282 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)283 self.assertItemsEqual(inforequest.undecided_emails_set.all(), [email3, email6])284 def test_undecided_emails_set_property_with_no_undecided_emails(self):285 inforequest, _, _ = self._create_inforequest_scenario()286 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)287 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)288 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)289 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)290 self.assertItemsEqual(inforequest.undecided_emails_set.all(), [])291 def test_undecided_emails_set_property_is_not_ordered(self):292 inforequest, _, _ = self._create_inforequest_scenario()293 self.assertFalse(inforequest.undecided_emails_set.all().ordered)294 def test_prefetch_undecided_emails_staticmethod(self):295 inforequest, _, _ = self._create_inforequest_scenario()296 _, rel1 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)297 _, rel2 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)298 _, rel3 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)299 _, rel4 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)300 _, rel5 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)301 _, rel6 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)302 # Without arguments303 with self.assertNumQueries(2):304 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)305 with self.assertNumQueries(0):306 self.assertEqual(inforequest._undecided_emails, [rel3, rel6])307 # With custom path and queryset308 with self.assertNumQueries(3):309 user = (User.objects310 .prefetch_related(u'inforequest_set')311 .prefetch_related(Inforequest.prefetch_undecided_emails(u'inforequest_set', InforequestEmail.objects.extra(select=dict(moo=47))))312 .get(pk=self.user1.pk))313 with self.assertNumQueries(0):314 self.assertEqual(user.inforequest_set.all()[0]._undecided_emails, [rel3, rel6])315 self.assertEqual(user.inforequest_set.all()[0]._undecided_emails[0].moo, 47)316 def test_undecided_emails_property(self):317 inforequest, _, _ = self._create_inforequest_scenario()318 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)319 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)320 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)321 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)322 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)323 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)324 # Property is cached325 with self.assertNumQueries(1):326 inforequest = Inforequest.objects.get(pk=inforequest.pk)327 with self.assertNumQueries(1):328 self.assertEqual(inforequest.undecided_emails, [email3, email6])329 with self.assertNumQueries(0):330 self.assertEqual(inforequest.undecided_emails, [email3, email6])331 # Property is prefetched with prefetch_undecided_emails()332 with self.assertNumQueries(2):333 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)334 with self.assertNumQueries(0):335 self.assertEqual(inforequest.undecided_emails, [email3, email6])336 def test_undecided_emails_property_with_no_undecided_emails(self):337 inforequest, _, _ = self._create_inforequest_scenario()338 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)339 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)340 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)341 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)342 # Property is cached343 with self.assertNumQueries(1):344 inforequest = Inforequest.objects.get(pk=inforequest.pk)345 with self.assertNumQueries(1):346 self.assertEqual(inforequest.undecided_emails, [])347 with self.assertNumQueries(0):348 self.assertEqual(inforequest.undecided_emails, [])349 # Property is prefetched with prefetch_undecided_emails()350 with self.assertNumQueries(2):351 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)352 with self.assertNumQueries(0):353 self.assertEqual(inforequest.undecided_emails, [])354 def test_undecided_emails_count_property(self):355 inforequest, _, _ = self._create_inforequest_scenario()356 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)357 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)358 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)359 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)360 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)361 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)362 # Property is cached363 with self.assertNumQueries(1):364 inforequest = Inforequest.objects.get(pk=inforequest.pk)365 with self.assertNumQueries(1):366 self.assertEqual(inforequest.undecided_emails_count, 2)367 with self.assertNumQueries(0):368 self.assertEqual(inforequest.undecided_emails_count, 2)369 # Property uses cached undecided_emails property370 with self.assertNumQueries(1):371 inforequest = Inforequest.objects.get(pk=inforequest.pk)372 with self.assertNumQueries(1):373 inforequest.undecided_emails374 with self.assertNumQueries(0):375 self.assertEqual(inforequest.undecided_emails_count, 2)376 # Property is prefetched with select_undecided_emails_count()377 with self.assertNumQueries(1):378 inforequest = Inforequest.objects.select_undecided_emails_count().get(pk=inforequest.pk)379 with self.assertNumQueries(0):380 self.assertEqual(inforequest.undecided_emails_count, 2)381 # Property is prefetched with prefetch_undecided_emails()382 with self.assertNumQueries(2):383 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)384 with self.assertNumQueries(0):385 self.assertEqual(inforequest.undecided_emails_count, 2)386 def test_undecided_emails_count_property_with_no_undecided_emails(self):387 inforequest, _, _ = self._create_inforequest_scenario()388 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)389 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)390 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)391 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)392 # Property is cached393 with self.assertNumQueries(1):394 inforequest = Inforequest.objects.get(pk=inforequest.pk)395 with self.assertNumQueries(1):396 self.assertEqual(inforequest.undecided_emails_count, 0)397 with self.assertNumQueries(0):398 self.assertEqual(inforequest.undecided_emails_count, 0)399 # Property uses cached undecided_emails property400 with self.assertNumQueries(1):401 inforequest = Inforequest.objects.get(pk=inforequest.pk)402 with self.assertNumQueries(1):403 inforequest.undecided_emails404 with self.assertNumQueries(0):405 self.assertEqual(inforequest.undecided_emails_count, 0)406 # Property is prefetched with select_undecided_emails_count()407 with self.assertNumQueries(1):408 inforequest = Inforequest.objects.select_undecided_emails_count().get(pk=inforequest.pk)409 with self.assertNumQueries(0):410 self.assertEqual(inforequest.undecided_emails_count, 0)411 # Property is prefetched with prefetch_undecided_emails()412 with self.assertNumQueries(2):413 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)414 with self.assertNumQueries(0):415 self.assertEqual(inforequest.undecided_emails_count, 0)416 def test_has_undecided_emails_property(self):417 inforequest, _, _ = self._create_inforequest_scenario()418 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)419 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)420 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)421 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)422 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)423 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)424 # Property is cached425 with self.assertNumQueries(1):426 inforequest = Inforequest.objects.get(pk=inforequest.pk)427 with self.assertNumQueries(1):428 self.assertTrue(inforequest.has_undecided_emails)429 with self.assertNumQueries(0):430 self.assertTrue(inforequest.has_undecided_emails)431 # Property uses cached undecided_emails_count property432 with self.assertNumQueries(1):433 inforequest = Inforequest.objects.get(pk=inforequest.pk)434 with self.assertNumQueries(1):435 inforequest.undecided_emails_count436 with self.assertNumQueries(0):437 self.assertTrue(inforequest.has_undecided_emails)438 # Property uses cached undecided_emails property439 with self.assertNumQueries(1):440 inforequest = Inforequest.objects.get(pk=inforequest.pk)441 with self.assertNumQueries(1):442 inforequest.undecided_emails443 with self.assertNumQueries(0):444 self.assertTrue(inforequest.has_undecided_emails)445 # Property is prefetched with select_undecided_emails_count()446 with self.assertNumQueries(1):447 inforequest = Inforequest.objects.select_undecided_emails_count().get(pk=inforequest.pk)448 with self.assertNumQueries(0):449 self.assertTrue(inforequest.has_undecided_emails)450 # Property is prefetched with prefetch_undecided_emails()451 with self.assertNumQueries(2):452 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)453 with self.assertNumQueries(0):454 self.assertTrue(inforequest.has_undecided_emails)455 def test_has_undecided_emails_property_with_no_undecided_emails(self):456 inforequest, _, _ = self._create_inforequest_scenario()457 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)458 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)459 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)460 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)461 # Property is cached462 with self.assertNumQueries(1):463 inforequest = Inforequest.objects.get(pk=inforequest.pk)464 with self.assertNumQueries(1):465 self.assertFalse(inforequest.has_undecided_emails)466 with self.assertNumQueries(0):467 self.assertFalse(inforequest.has_undecided_emails)468 # Property uses cached undecided_emails_count property469 with self.assertNumQueries(1):470 inforequest = Inforequest.objects.get(pk=inforequest.pk)471 with self.assertNumQueries(1):472 inforequest.undecided_emails_count473 with self.assertNumQueries(0):474 self.assertFalse(inforequest.has_undecided_emails)475 # Property uses cached undecided_emails property476 with self.assertNumQueries(1):477 inforequest = Inforequest.objects.get(pk=inforequest.pk)478 with self.assertNumQueries(1):479 inforequest.undecided_emails480 with self.assertNumQueries(0):481 self.assertFalse(inforequest.has_undecided_emails)482 # Property is prefetched with select_undecided_emails_count()483 with self.assertNumQueries(1):484 inforequest = Inforequest.objects.select_undecided_emails_count().get(pk=inforequest.pk)485 with self.assertNumQueries(0):486 self.assertFalse(inforequest.has_undecided_emails)487 # Property is prefetched with prefetch_undecided_emails()488 with self.assertNumQueries(2):489 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)490 with self.assertNumQueries(0):491 self.assertFalse(inforequest.has_undecided_emails)492 def test_oldest_undecided_email_property(self):493 inforequest, _, _ = self._create_inforequest_scenario()494 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)495 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)496 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)497 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)498 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)499 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)500 # Property is cached501 with self.assertNumQueries(1):502 inforequest = Inforequest.objects.get(pk=inforequest.pk)503 with self.assertNumQueries(1):504 self.assertEqual(inforequest.oldest_undecided_email, email3)505 with self.assertNumQueries(0):506 self.assertEqual(inforequest.oldest_undecided_email, email3)507 # Property uses cached undecided_emails property508 with self.assertNumQueries(1):509 inforequest = Inforequest.objects.get(pk=inforequest.pk)510 with self.assertNumQueries(1):511 inforequest.undecided_emails512 with self.assertNumQueries(0):513 self.assertEqual(inforequest.oldest_undecided_email, email3)514 # Property is prefetched with prefetch_undecided_emails()515 with self.assertNumQueries(2):516 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)517 with self.assertNumQueries(0):518 self.assertEqual(inforequest.oldest_undecided_email, email3)519 def test_oldest_undecided_email_property_with_no_undecided_emails(self):520 inforequest, _, _ = self._create_inforequest_scenario()521 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)522 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)523 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)524 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)525 # Property is cached526 with self.assertNumQueries(1):527 inforequest = Inforequest.objects.get(pk=inforequest.pk)528 with self.assertNumQueries(1):529 self.assertIsNone(inforequest.oldest_undecided_email)530 with self.assertNumQueries(0):531 self.assertIsNone(inforequest.oldest_undecided_email)532 # Property uses cached undecided_emails property533 with self.assertNumQueries(1):534 inforequest = Inforequest.objects.get(pk=inforequest.pk)535 with self.assertNumQueries(1):536 inforequest.undecided_emails537 with self.assertNumQueries(0):538 self.assertIsNone(inforequest.oldest_undecided_email)539 # Property is prefetched with prefetch_undecided_emails()540 with self.assertNumQueries(2):541 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)542 with self.assertNumQueries(0):543 self.assertIsNone(inforequest.oldest_undecided_email)544 def test_prefetch_newest_undecided_email_staticmethod(self):545 inforequest, _, _ = self._create_inforequest_scenario()546 _, rel1 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)547 _, rel2 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)548 _, rel3 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)549 _, rel4 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)550 _, rel5 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)551 _, rel6 = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)552 # Without arguments553 with self.assertNumQueries(2):554 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_newest_undecided_email()).get(pk=inforequest.pk)555 with self.assertNumQueries(0):556 self.assertEqual(inforequest._newest_undecided_email, [rel6])557 # With custom path and queryset558 with self.assertNumQueries(3):559 user = (User.objects560 .prefetch_related(u'inforequest_set')561 .prefetch_related(Inforequest.prefetch_newest_undecided_email(u'inforequest_set', InforequestEmail.objects.extra(select=dict(moo=47))))562 .get(pk=self.user1.pk))563 with self.assertNumQueries(0):564 self.assertEqual(user.inforequest_set.all()[0]._newest_undecided_email, [rel6])565 self.assertEqual(user.inforequest_set.all()[0]._newest_undecided_email[0].moo, 47)566 def test_newest_undecided_email_property(self):567 inforequest, _, _ = self._create_inforequest_scenario()568 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)569 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)570 email3, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)571 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)572 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)573 email6, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)574 # Property is cached575 with self.assertNumQueries(1):576 inforequest = Inforequest.objects.get(pk=inforequest.pk)577 with self.assertNumQueries(1):578 self.assertEqual(inforequest.newest_undecided_email, email6)579 with self.assertNumQueries(0):580 self.assertEqual(inforequest.newest_undecided_email, email6)581 # Property uses cached undecided_emails property582 with self.assertNumQueries(1):583 inforequest = Inforequest.objects.get(pk=inforequest.pk)584 with self.assertNumQueries(1):585 inforequest.undecided_emails586 with self.assertNumQueries(0):587 self.assertEqual(inforequest.newest_undecided_email, email6)588 # Property is prefetched with prefetch_newest_undecided_email()589 with self.assertNumQueries(2):590 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_newest_undecided_email()).get(pk=inforequest.pk)591 with self.assertNumQueries(0):592 self.assertEqual(inforequest.newest_undecided_email, email6)593 # Property is prefetched with prefetch_undecided_emails()594 with self.assertNumQueries(2):595 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)596 with self.assertNumQueries(0):597 self.assertEqual(inforequest.newest_undecided_email, email6)598 def test_newest_undecided_email_property_with_no_undecided_emails(self):599 inforequest, _, _ = self._create_inforequest_scenario()600 email1, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNKNOWN)601 email2, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNRELATED)602 email4, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.APPLICANT_ACTION)603 email5, _ = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.OBLIGEE_ACTION)604 # Property is cached605 with self.assertNumQueries(1):606 inforequest = Inforequest.objects.get(pk=inforequest.pk)607 with self.assertNumQueries(1):608 self.assertIsNone(inforequest.newest_undecided_email)609 with self.assertNumQueries(0):610 self.assertIsNone(inforequest.newest_undecided_email)611 # Property uses cached undecided_emails property612 with self.assertNumQueries(1):613 inforequest = Inforequest.objects.get(pk=inforequest.pk)614 with self.assertNumQueries(1):615 inforequest.undecided_emails616 with self.assertNumQueries(0):617 self.assertIsNone(inforequest.newest_undecided_email)618 # Property is prefetched with prefetch_newest_undecided_email()619 with self.assertNumQueries(2):620 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_newest_undecided_email()).get(pk=inforequest.pk)621 with self.assertNumQueries(0):622 self.assertIsNone(inforequest.newest_undecided_email)623 # Property is prefetched with prefetch_undecided_emails()624 with self.assertNumQueries(2):625 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_undecided_emails()).get(pk=inforequest.pk)626 with self.assertNumQueries(0):627 self.assertIsNone(inforequest.newest_undecided_email)628 def test_can_add_x_properties_with_one_branch(self):629 inforequest, _, _ = self._create_inforequest_scenario()630 # ``branch`` last action is ``REQUEST``631 self.assertFalse(inforequest.can_add_request)632 self.assertFalse(inforequest.can_add_clarification_response)633 self.assertFalse(inforequest.can_add_appeal)634 self.assertTrue(inforequest.can_add_confirmation)635 self.assertTrue(inforequest.can_add_extension)636 self.assertTrue(inforequest.can_add_advancement)637 self.assertTrue(inforequest.can_add_clarification_request)638 self.assertTrue(inforequest.can_add_disclosure)639 self.assertTrue(inforequest.can_add_refusal)640 self.assertFalse(inforequest.can_add_affirmation)641 self.assertFalse(inforequest.can_add_reversion)642 self.assertFalse(inforequest.can_add_remandment)643 self.assertFalse(inforequest.can_add_applicant_action)644 self.assertFalse(inforequest.can_add_applicant_email_action)645 self.assertTrue(inforequest.can_add_obligee_action)646 self.assertTrue(inforequest.can_add_obligee_email_action)647 def test_can_add_x_properties_with_multiple_branches(self):648 u"""649 Checks that the set of actions allowed for an inforequest is the union of sets of actions650 allowed for its branches.651 """652 inforequest, _, _ = self._create_inforequest_scenario((u'advancement',653 [u'refusal', u'appeal', u'remandment'],654 [u'clarification_request'],655 [(u'advancement',656 [u'confirmation'],657 )],658 ))659 # The main branch last action is ``ADVANCEMENT``. The main branch adcanced to other660 # three branches ending with ``EXTENSION`` and ``CLARIFICATION_REQUEST`` and661 # ``ADVANCEMENT``, respectivelly. The latter advancement advanced to yet another branch662 # ending with ``CONFIRMATION``.663 self.assertFalse(inforequest.can_add_request)664 self.assertTrue(inforequest.can_add_clarification_response) # from ``CLARIFICATION_REQUEST``665 self.assertTrue(inforequest.can_add_appeal) # from ``ADVANCEMENT``666 self.assertFalse(inforequest.can_add_confirmation)667 self.assertTrue(inforequest.can_add_extension) # from ``REMANDMENT`` and ``CONFIRMATION``668 self.assertTrue(inforequest.can_add_advancement) # from ``CONFIRMATION``669 self.assertTrue(inforequest.can_add_clarification_request) # from ``CLARIFICATION_REQUEST`` and ``CONFIRMATION``670 self.assertTrue(inforequest.can_add_disclosure) # from ``REMANDMENT`` and ``CONFIRMATION``671 self.assertTrue(inforequest.can_add_refusal) # from ``REMANDMENT`` and ``CONFIRMATION``672 self.assertFalse(inforequest.can_add_affirmation)673 self.assertFalse(inforequest.can_add_reversion)674 self.assertFalse(inforequest.can_add_remandment)675 self.assertTrue(inforequest.can_add_applicant_action)676 self.assertTrue(inforequest.can_add_applicant_email_action)677 self.assertTrue(inforequest.can_add_obligee_action)678 self.assertTrue(inforequest.can_add_obligee_email_action)679 def test_can_add_action_method(self):680 tests = ( # expected result681 (Action.TYPES.REQUEST, False, None),682 (Action.TYPES.CLARIFICATION_RESPONSE, False, None),683 (Action.TYPES.APPEAL, False, None),684 (Action.TYPES.CONFIRMATION, True, None),685 (Action.TYPES.EXTENSION, True, None),686 (Action.TYPES.ADVANCEMENT, True, None),687 (Action.TYPES.CLARIFICATION_REQUEST, True, None),688 (Action.TYPES.DISCLOSURE, True, None),689 (Action.TYPES.REFUSAL, True, None),690 (Action.TYPES.AFFIRMATION, False, None),691 (Action.TYPES.REVERSION, False, None),692 (Action.TYPES.REMANDMENT, False, None),693 (Action.TYPES.ADVANCED_REQUEST, AttributeError, u"'Branch' object has no attribute 'can_add_advanced_request'"),694 (Action.TYPES.EXPIRATION, AttributeError, u"'Branch' object has no attribute 'can_add_expiration'"),695 (Action.TYPES.APPEAL_EXPIRATION, AttributeError, u"'Branch' object has no attribute 'can_add_appeal_expiration'"),696 )697 # Make sure we are testing all defined action types698 tested_action_types = set(a for a, _, _ in tests)699 defined_action_types = Action.TYPES._inverse.keys()700 self.assertItemsEqual(tested_action_types, defined_action_types)701 # ``branch`` last action is ``REQUEST``702 inforequest, _, _ = self._create_inforequest_scenario()703 for action_type, expected_result, expected_message in tests:704 if expected_result is True:705 self.assertTrue(inforequest.can_add_action(action_type))706 elif expected_result is False:707 self.assertFalse(inforequest.can_add_action(action_type))708 else:709 with self.assertRaisesMessage(expected_result, expected_message):710 inforequest.can_add_action(action_type)711 def test_can_add_action_method_with_multiple_arguments(self):712 tests = (713 ([Action.TYPES.REQUEST, Action.TYPES.APPEAL, Action.TYPES.REVERSION], False, None),714 ([Action.TYPES.CONFIRMATION, Action.TYPES.EXTENSION], True, None),715 ([Action.TYPES.APPEAL, Action.TYPES.EXTENSION, Action.TYPES.REVERSION], True, None),716 ([Action.TYPES.AFFIRMATION, Action.TYPES.EXPIRATION, Action.TYPES.EXTENSION], AttributeError, u"'Branch' object has no attribute 'can_add_expiration'"),717 ([], False, None),718 )719 # ``branch`` last action is ``REQUEST``720 inforequest, _, _ = self._create_inforequest_scenario()721 for action_types, expected_result, expected_message in tests:722 if expected_result is True:723 self.assertTrue(inforequest.can_add_action(*action_types), u'can_add_action(%s) is False' % action_types)724 elif expected_result is False:725 self.assertFalse(inforequest.can_add_action(*action_types), u'can_add_action(%s) is True' % action_types)726 else:727 with self.assertRaisesMessage(expected_result, expected_message):728 inforequest.can_add_action(*action_types)729 def test_branches_advanced_by_method(self):730 inforequest, branch1, actions = self._create_inforequest_scenario(u'advancement')731 _, (advancement, ((branch2, _),)) = actions732 # Fetch branches if not prefetched733 with self.assertNumQueries(1):734 inforequest = Inforequest.objects.get(pk=inforequest.pk)735 with self.assertNumQueries(1):736 self.assertItemsEqual(inforequest.branches_advanced_by(advancement), [branch2])737 # Use prefetched branches if prefetched738 with self.assertNumQueries(2):739 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)740 with self.assertNumQueries(0):741 self.assertItemsEqual(inforequest.branches_advanced_by(advancement), [branch2])742 def test_branch_by_pk_method(self):743 inforequest, branch1, actions = self._create_inforequest_scenario(u'advancement')744 _, (_, ((branch2, _),)) = actions745 # Fetch branches if not prefetched746 with self.assertNumQueries(1):747 inforequest = Inforequest.objects.get(pk=inforequest.pk)748 with self.assertNumQueries(1):749 self.assertEqual(inforequest.branch_by_pk(branch2.pk), branch2)750 # Use prefetched branches if prefetched751 with self.assertNumQueries(2):752 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)753 with self.assertNumQueries(0):754 self.assertEqual(inforequest.branch_by_pk(branch2.pk), branch2)755 def test_branch_by_pk_method_with_invalid_pk(self):756 inforequest, _, _ = self._create_inforequest_scenario(u'advancement')757 # Fetch branches if not prefetched758 with self.assertNumQueries(1):759 inforequest = Inforequest.objects.get(pk=inforequest.pk)760 with self.assertNumQueries(1):761 with self.assertRaises(ValueError):762 self.assertEqual(inforequest.branch_by_pk(47), branch2)763 # Use prefetched branches if prefetched764 with self.assertNumQueries(2):765 inforequest = Inforequest.objects.prefetch_related(Inforequest.prefetch_branches()).get(pk=inforequest.pk)766 with self.assertNumQueries(0):767 with self.assertRaises(ValueError):768 self.assertEqual(inforequest.branch_by_pk(47), branch2)769 def test_send_notification(self):770 u"""771 Checks the notification sender and recipients and that it's queued to be sent.772 """773 user = self._create_user(first_name=u'John', last_name=u'Smith', email=u'smith@example.com')774 inforequest, _, _ = self._create_inforequest_scenario(user)775 email, rel = self._create_inforequest_email(inforequest=inforequest, reltype=InforequestEmail.TYPES.UNDECIDED)776 with self.settings(DEFAULT_FROM_EMAIL=u'info@example.com'):777 with created_instances(Message.objects) as message_set:778 inforequest.send_received_email_notification(email)779 msg = message_set.get()780 self.assertEqual(msg.type, Message.TYPES.OUTBOUND)...
tests.py
Source:tests.py
...41 works correctly. Lookups for a particular content type -- by model, ID42 or natural key -- should hit the database only on the first lookup.43 """44 # At this point, a lookup for a ContentType should hit the DB45 with self.assertNumQueries(1):46 ContentType.objects.get_for_model(ContentType)47 # A second hit, though, won't hit the DB, nor will a lookup by ID48 # or natural key49 with self.assertNumQueries(0):50 ct = ContentType.objects.get_for_model(ContentType)51 with self.assertNumQueries(0):52 ContentType.objects.get_for_id(ct.id)53 with self.assertNumQueries(0):54 ContentType.objects.get_by_natural_key('contenttypes',55 'contenttype')56 # Once we clear the cache, another lookup will again hit the DB57 ContentType.objects.clear_cache()58 with self.assertNumQueries(1):59 ContentType.objects.get_for_model(ContentType)60 # The same should happen with a lookup by natural key61 ContentType.objects.clear_cache()62 with self.assertNumQueries(1):63 ContentType.objects.get_by_natural_key('contenttypes',64 'contenttype')65 # And a second hit shouldn't hit the DB66 with self.assertNumQueries(0):67 ContentType.objects.get_by_natural_key('contenttypes',68 'contenttype')69 def test_get_for_models_empty_cache(self):70 # Empty cache.71 with self.assertNumQueries(1):72 cts = ContentType.objects.get_for_models(ContentType, FooWithUrl)73 self.assertEqual(cts, {74 ContentType: ContentType.objects.get_for_model(ContentType),75 FooWithUrl: ContentType.objects.get_for_model(FooWithUrl),76 })77 def test_get_for_models_partial_cache(self):78 # Partial cache79 ContentType.objects.get_for_model(ContentType)80 with self.assertNumQueries(1):81 cts = ContentType.objects.get_for_models(ContentType, FooWithUrl)82 self.assertEqual(cts, {83 ContentType: ContentType.objects.get_for_model(ContentType),84 FooWithUrl: ContentType.objects.get_for_model(FooWithUrl),85 })86 def test_get_for_models_full_cache(self):87 # Full cache88 ContentType.objects.get_for_model(ContentType)89 ContentType.objects.get_for_model(FooWithUrl)90 with self.assertNumQueries(0):91 cts = ContentType.objects.get_for_models(ContentType, FooWithUrl)92 self.assertEqual(cts, {93 ContentType: ContentType.objects.get_for_model(ContentType),94 FooWithUrl: ContentType.objects.get_for_model(FooWithUrl),95 })96 @override_settings(ALLOWED_HOSTS=['example.com'])97 def test_shortcut_view(self):98 """99 Check that the shortcut view (used for the admin "view on site"100 functionality) returns a complete URL regardless of whether the sites101 framework is installed102 """103 request = HttpRequest()104 request.META = {...
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!