0003-visualization-add-warehouse-slug-support-38596.patch
bijoe/schemas.py | ||
---|---|---|
395 | 395 | |
396 | 396 | |
397 | 397 |
class Warehouse(Base): |
398 |
__slots__ = ['name', 'label', 'pg_dsn', 'search_path', 'cubes', 'path'] |
|
398 |
__slots__ = ['name', 'slug', 'label', 'pg_dsn', 'search_path', 'cubes', 'path']
|
|
399 | 399 |
__types__ = { |
400 | 400 |
'name': str, |
401 |
'slug': str, |
|
401 | 402 |
'label': unicode, |
402 | 403 |
'pg_dsn': str, |
403 | 404 |
'search_path': [str], |
... | ... | |
406 | 407 |
} |
407 | 408 | |
408 | 409 |
path = None |
410 |
slug = None |
|
409 | 411 | |
410 | 412 |
def check(self): |
411 | 413 |
names = collections.Counter(cube.name for cube in self.cubes) |
bijoe/visualization/utils.py | ||
---|---|---|
61 | 61 |
def to_json(self): |
62 | 62 |
return { |
63 | 63 |
'warehouse': self.cube.engine.warehouse.name, |
64 |
'warehouse_slug': self.cube.engine.warehouse.slug, |
|
64 | 65 |
'cube': self.cube.name, |
65 | 66 |
'representation': self.representation, |
66 | 67 |
'measure': self.measure and self.measure.name, |
... | ... | |
80 | 81 |
if not warehouses: |
81 | 82 |
warehouses = get_warehouses() |
82 | 83 |
for warehouse in warehouses: |
83 |
if d['warehouse'] == warehouse.name: |
|
84 |
if warehouse.slug and 'warehouse_slug' in d: |
|
85 |
if d['warehouse_slug'] == warehouse.slug: |
|
86 |
break |
|
87 |
elif d['warehouse'] == warehouse.name: # legacy |
|
84 | 88 |
break |
85 | 89 |
else: |
86 | 90 |
raise Http404('warehouse %s not found' % d['warehouse']) |
tests/fixtures/schema1/01_schema.json | ||
---|---|---|
241 | 241 |
], |
242 | 242 |
"label": "test schema1", |
243 | 243 |
"name": "schema1", |
244 |
"slug": "schema1_slug", |
|
244 | 245 |
"pg_dsn": "fixme", |
245 | 246 |
"search_path": [ |
246 | 247 |
"schema1" |
tests/test_views.py | ||
---|---|---|
40 | 40 |
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save() |
41 | 41 |
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save() |
42 | 42 |
Visualization(name='test', parameters={'warehouse': 'schema1', 'cube': 'test'}).save() |
43 |
Visualization(name='test', parameters={'warehouse_slug': 'schema1_slug', 'cube': 'test'}).save() |
|
43 | 44 |
login(app, admin) |
44 | 45 |
resp = app.get(reverse('visualizations-json')) |
45 |
assert set([x['slug'] for x in resp.json]) == set(['test', 'test-2', 'test-3']) |
|
46 |
assert set([x['slug'] for x in resp.json]) == set(['test', 'test-2', 'test-3', 'test-4'])
|
|
46 | 47 | |
47 | 48 | |
48 | 49 |
def test_visualization_json_api(schema1, app, admin): |
... | ... | |
110 | 111 | |
111 | 112 |
response = app.get('/') |
112 | 113 |
assert response.pyquery('ul li a.disabled').text() == visualization.name |
114 | ||
115 | ||
116 |
def test_visualization_creation_view(schema1, app, admin): |
|
117 |
login(app, admin) |
|
118 |
response = app.get('/').follow() |
|
119 |
response = response.click('Facts 1') |
|
120 |
form = response.form |
|
121 |
form.set('representation', 'table') |
|
122 |
form.set('measure', 'simple_count') |
|
123 |
response = form.submit('visualize') |
|
124 |
response = response.click(href='save') |
|
125 |
response.form['name'] = 'test' |
|
126 |
response.form.submit() |
|
127 | ||
128 |
visu = Visualization.objects.get(name='test') |
|
129 |
assert visu.parameters['warehouse_slug'] == 'schema1_slug' |
|
113 |
- |