MCPcopy
hub / github.com/django/django / test_bad_class

Method test_bad_class

tests/get_object_or_404/tests.py:88–114  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

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."""

Callers

nothing calls this directly

Calls 3

get_object_or_404Function · 0.90
get_list_or_404Function · 0.90
assertRaisesMessageMethod · 0.80

Tested by

no test coverage detected