Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Apr 18, 2018
1 parent 386abd0 commit 98b372f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,12 @@ def grains(self):
return self.db_engine_spec.time_grains

def grains_dict(self):
return {grain.duration: grain for grain in self.grains()}
"""Allowing to lookup grain by either label or duration
For backward compatibility"""
d = {grain.duration: grain for grain in self.grains()}
d.update({grain.label: grain for grain in self.grains()})
return d

def get_extra(self):
extra = {}
Expand Down
8 changes: 8 additions & 0 deletions tests/model_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,11 @@ def test_select_star(self):
FROM bart_lines
LIMIT 100""".format(**locals()))
assert sql.startswith(expected)

def test_grains_dict(self):
uri = 'mysql://root@localhost'
database = Database(sqlalchemy_uri=uri)
d = database.grains_dict()
self.assertEquals(d.get('day').function, 'DATE({col})')
self.assertEquals(d.get('P1D').function, 'DATE({col})')
self.assertEquals(d.get('Time Column').function, '{col}')

0 comments on commit 98b372f

Please sign in to comment.