(self)
| 86 | ) |
| 87 | |
| 88 | def test_bad_class(self): |
| 89 | # Given an argument klass that is not a Model, Manager, or Queryset |
| 90 | # raises a helpful ValueError message |
| 91 | msg = ( |
| 92 | "First argument to get_object_or_404() must be a Model, Manager, or " |
| 93 | "QuerySet, not 'str'." |
| 94 | ) |
| 95 | with self.assertRaisesMessage(ValueError, msg): |
| 96 | get_object_or_404("Article", title__icontains="Run") |
| 97 | |
| 98 | class CustomClass: |
| 99 | pass |
| 100 | |
| 101 | msg = ( |
| 102 | "First argument to get_object_or_404() must be a Model, Manager, or " |
| 103 | "QuerySet, not 'CustomClass'." |
| 104 | ) |
| 105 | with self.assertRaisesMessage(ValueError, msg): |
| 106 | get_object_or_404(CustomClass, title__icontains="Run") |
| 107 | |
| 108 | # Works for lists too |
| 109 | msg = ( |
| 110 | "First argument to get_list_or_404() must be a Model, Manager, or " |
| 111 | "QuerySet, not 'list'." |
| 112 | ) |
| 113 | with self.assertRaisesMessage(ValueError, msg): |
| 114 | get_list_or_404([Article], title__icontains="Run") |
| 115 | |
| 116 | def test_get_object_or_404_queryset_attribute_error(self): |
| 117 | """AttributeError raised by QuerySet.get() isn't hidden.""" |
nothing calls this directly
no test coverage detected