Skip to content

Commit

Permalink
Create database index for samples
Browse files Browse the repository at this point in the history
  • Loading branch information
justjasongreen committed Jul 28, 2016
1 parent 58d5283 commit 74a2c70
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions predictive_punter/provider.py
Expand Up @@ -6,6 +6,17 @@
class Provider(racing_data.Provider):
"""Extend the racing_data Provider class with additional functionality specific to predictive analytics"""

@property
def database_indexes(self):
"""Return a dictionary of required database indexes for each entity type"""

database_indexes = super().database_indexes
database_indexes[Sample] = [
[('runner_id', 1)]
]

return database_indexes

def get_runner_by_sample(self, sample):
"""Get the runner associated with the specified sample"""

Expand Down
17 changes: 17 additions & 0 deletions tests/provider/indexes_test.py
@@ -0,0 +1,17 @@
import predictive_punter


def test_indexes(provider):
"""The provider should create all necessary database indexes during initialisation"""

expected_indexes = {
predictive_punter.Sample: [
[('runner_id', 1)]
]
}

for entity_type in expected_indexes:
collection = provider.get_database_collection(entity_type)
index_keys = [index['key'] for index in collection.index_information().values()]
for expected_index in expected_indexes[entity_type]:
assert expected_index in index_keys

0 comments on commit 74a2c70

Please sign in to comment.