|
29 | 29 | from .google_imports import memcache
|
30 | 30 | from .google_imports import namespace_manager
|
31 | 31 | from .google_imports import users
|
32 |
| -from .google_test_imports import datastore_stub_util |
33 | 32 | from .google_test_imports import real_unittest
|
34 | 33 | from .google_test_imports import unittest
|
35 | 34 |
|
@@ -5210,66 +5209,56 @@ def testRejectOldPickles(self):
|
5210 | 5209 |
|
5211 | 5210 | class IndexTests(test_utils.NDBTest):
|
5212 | 5211 |
|
5213 |
| - def create_index(self): |
5214 |
| - ci = datastore_stub_util.datastore_pb.CompositeIndex() |
5215 |
| - ci.set_app_id(os.environ['APPLICATION_ID']) |
5216 |
| - ci.set_id(0) |
5217 |
| - ci.set_state(ci.WRITE_ONLY) |
5218 |
| - index = ci.mutable_definition() |
5219 |
| - index.set_ancestor(0) |
5220 |
| - index.set_entity_type('Kind') |
5221 |
| - property = index.add_property() |
5222 |
| - property.set_name('property1') |
5223 |
| - property.set_direction(property.DESCENDING) |
5224 |
| - property = index.add_property() |
5225 |
| - property.set_name('property2') |
5226 |
| - property.set_direction(property.ASCENDING) |
5227 |
| - stub = self.testbed.get_stub('datastore_v3') |
5228 |
| - stub.CreateIndex(ci) |
| 5212 | + def generate_index(self): |
| 5213 | + """Run a query to trigger index generation. |
| 5214 | +
|
| 5215 | + Note, index generation is idempotent. Running same query multiple times does |
| 5216 | + not change existing index. Hence we don't need to clear indexes between |
| 5217 | + tests. |
| 5218 | + """ |
| 5219 | + |
| 5220 | + # pylint: disable=unused-variable |
| 5221 | + class Kind(model.Model): |
| 5222 | + property1 = model.TextProperty() |
| 5223 | + property2 = model.TextProperty() |
| 5224 | + # pylint: enable=unused-variable |
| 5225 | + |
| 5226 | + qry = query.gql('SELECT * FROM Kind ORDER BY property1 DESC, property2') |
| 5227 | + qry.fetch() |
5229 | 5228 |
|
5230 | 5229 | def testGetIndexes(self):
|
5231 | 5230 | self.assertEqual([], model.get_indexes())
|
5232 | 5231 |
|
5233 |
| - self.create_index() |
| 5232 | + self.generate_index() |
5234 | 5233 |
|
5235 | 5234 | self.assertEqual(
|
5236 |
| - [model.IndexState( |
5237 |
| - definition=model.Index(kind='Kind', |
5238 |
| - properties=[ |
5239 |
| - model.IndexProperty(name='property1', |
5240 |
| - direction='desc'), |
5241 |
| - model.IndexProperty(name='property2', |
5242 |
| - direction='asc'), |
5243 |
| - ], |
5244 |
| - ancestor=False), |
5245 |
| - state='building', |
5246 |
| - id=1, |
5247 |
| - ), |
5248 |
| - ], |
5249 |
| - model.get_indexes()) |
| 5235 | + model.Index(kind='Kind', |
| 5236 | + properties=[ |
| 5237 | + model.IndexProperty(name='property1', |
| 5238 | + direction='desc'), |
| 5239 | + model.IndexProperty(name='property2', |
| 5240 | + direction='asc'), |
| 5241 | + ], |
| 5242 | + ancestor=False), |
| 5243 | + model.get_indexes()[0].definition) |
5250 | 5244 |
|
5251 | 5245 | def testGetIndexesAsync(self):
|
5252 | 5246 | fut = model.get_indexes_async()
|
5253 | 5247 | self.assertTrue(isinstance(fut, tasklets.Future))
|
5254 | 5248 | self.assertEqual([], fut.get_result())
|
5255 | 5249 |
|
5256 |
| - self.create_index() |
| 5250 | + self.generate_index() |
5257 | 5251 |
|
5258 | 5252 | self.assertEqual(
|
5259 |
| - [model.IndexState( |
5260 |
| - definition=model.Index(kind='Kind', |
5261 |
| - properties=[ |
5262 |
| - model.IndexProperty(name='property1', |
5263 |
| - direction='desc'), |
5264 |
| - model.IndexProperty(name='property2', |
5265 |
| - direction='asc'), |
5266 |
| - ], |
5267 |
| - ancestor=False), |
5268 |
| - state='building', |
5269 |
| - id=1, |
5270 |
| - ), |
5271 |
| - ], |
5272 |
| - model.get_indexes_async().get_result()) |
| 5253 | + model.Index(kind='Kind', |
| 5254 | + properties=[ |
| 5255 | + model.IndexProperty(name='property1', |
| 5256 | + direction='desc'), |
| 5257 | + model.IndexProperty(name='property2', |
| 5258 | + direction='asc'), |
| 5259 | + ], |
| 5260 | + ancestor=False), |
| 5261 | + model.get_indexes_async().get_result()[0].definition) |
5273 | 5262 |
|
5274 | 5263 |
|
5275 | 5264 | class CacheTests(test_utils.NDBTest):
|
|
0 commit comments