MCPcopy Index your code
hub / github.com/piccolo-orm/piccolo / test_complex_where_clause

Method test_complex_where_clause

tests/table/test_objects.py:132–158  ·  view source on GitHub ↗

Make sure `get_or_create` works with complex where clauses.

(self)

Source from the content-addressed store, hash-verified

130 self.assertEqual(instance.popularity, 100)
131
132 def test_complex_where_clause(self):
133 """
134 Make sure `get_or_create` works with complex where clauses.
135 """
136 self.insert_rows()
137
138 # When the row already exists in the db:
139 instance = (
140 Band.objects()
141 .get_or_create(
142 (Band.name == "Pythonistas") & (Band.popularity == 1000)
143 )
144 .run_sync()
145 )
146 self.assertIsInstance(instance, Band)
147 self.assertEqual(instance._was_created, False)
148
149 # When the row doesn't exist in the db:
150 instance = (
151 Band.objects()
152 .get_or_create(
153 (Band.name == "Pythonistas2") & (Band.popularity == 2000)
154 )
155 .run_sync()
156 )
157 self.assertIsInstance(instance, Band)
158 self.assertEqual(instance._was_created, True)
159
160 def test_very_complex_where_clause(self):
161 """

Callers

nothing calls this directly

Calls 5

get_or_createMethod · 0.80
objectsMethod · 0.80
assertEqualMethod · 0.80
insert_rowsMethod · 0.45
run_syncMethod · 0.45

Tested by

no test coverage detected