forked from scraperwiki/dumptruck-web
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_metadata.py
52 lines (49 loc) · 1.3 KB
/
test_metadata.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
# run with nosetests
# Test the metadata API
from nose.tools import *
def testMeta1():
endpoint = "/sql/meta/"
result = get_json_from_query()
# Returns something like:
"""
{
"table": {
"first_table_name": {
"type": "table",
"column_names": ["column1", "column2"]
},
"a_view": {
"type": "view",
"column_names": ["blah blah", "blah"]
},
},
"database_type": "sqlite"
}
# With future expansion for columns that are typed:
"columns": [{"name":"column1","type":"Number"}]
# and tables with unique keys.
"unique_keys": ["col1", "col2"}
"""
assert result
assert result['database_type']
assert result['table']
assert result['table']['test1']
assert_equal(result['table']['test1']['type'], 'table')
column_names = result['table']['test1']['column_names']
assert column_names
assert "column1" in column_names
assert "column2" in column_names
def get_json_from_query():
return {
"table": {
"test1": {
"type": "table",
"column_names": ["column1", "column2"]
},
"another_table": {
"column_names": ["blah blah", "blah"]
},
},
"database_type": "sqlite"
}