MCPcopy
hub / github.com/django/django / test_basic

Method test_basic

tests/db_functions/text/test_repeat.py:10–29  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

8
9class RepeatTests(TestCase):
10 def test_basic(self):
11 Author.objects.create(name="John", alias="xyz")
12 none_value = (
13 "" if connection.features.interprets_empty_strings_as_nulls else None
14 )
15 tests = (
16 (Repeat("name", 0), ""),
17 (Repeat("name", 2), "JohnJohn"),
18 (Repeat("name", Length("alias")), "JohnJohnJohn"),
19 (Repeat(Value("x"), 3), "xxx"),
20 (Repeat("name", None), none_value),
21 (Repeat(Value(None), 4), none_value),
22 (Repeat("goes_by", 1), none_value),
23 )
24 for function, repeated_text in tests:
25 with self.subTest(function=function):
26 authors = Author.objects.annotate(repeated_text=function)
27 self.assertQuerySetEqual(
28 authors, [repeated_text], lambda a: a.repeated_text, ordered=False
29 )
30
31 def test_negative_number(self):
32 with self.assertRaisesMessage(

Callers

nothing calls this directly

Calls 6

RepeatClass · 0.90
LengthClass · 0.90
ValueClass · 0.90
annotateMethod · 0.80
assertQuerySetEqualMethod · 0.80
createMethod · 0.45

Tested by

no test coverage detected