Skip to content

Commit

Permalink
[hotfix] fix the logging fix that broke the build (#1940)
Browse files Browse the repository at this point in the history
* [hotfix] fix the logging fix that broke the build

* Fixing tests
  • Loading branch information
mistercrunch authored Jan 11, 2017
1 parent 5d94d70 commit 2d866e3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 12 deletions.
5 changes: 4 additions & 1 deletion superset/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2586,6 +2586,8 @@ def wrapper(*args, **kwargs):
except:
pass
value = f(*args, **kwargs)

sesh = db.session()
log = cls(
action=f.__name__,
json=params,
Expand All @@ -2595,7 +2597,8 @@ def wrapper(*args, **kwargs):
datetime.now() - start_dttm).total_seconds() * 1000,
referrer=request.referrer[:1000] if request.referrer else None,
user_id=user_id)
db.session.flush()
sesh.add(log)
sesh.commit()
return value
return wrapper

Expand Down
14 changes: 9 additions & 5 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,20 @@ def test_slice_endpoint(self):
'/superset/slice/{}/?standalone=true'.format(slc.id))
assert 'List Roles' not in resp

def test_endpoints_for_a_slice(self):
def test_slice_json_endpoint(self):
self.login(username='admin')
slc = self.get_slice("Girls", db.session)

resp = self.get_resp(slc.viz.csv_endpoint)
assert 'Jennifer,' in resp

resp = self.get_resp(slc.viz.json_endpoint)
assert '"Jennifer"' in resp

def test_slice_csv_endpoint(self):
self.login(username='admin')
slc = self.get_slice("Girls", db.session)

resp = self.get_resp(slc.viz.csv_endpoint)
assert 'Jennifer,' in resp

def test_admin_only_permissions(self):
def assert_admin_permission_in(role_name, assert_func):
role = sm.find_role(role_name)
Expand Down Expand Up @@ -466,14 +470,14 @@ def test_templated_sql_json(self):

def test_table_metadata(self):
maindb = self.get_main_database(db.session)
backend = maindb.backend
data = self.get_json_resp(
"/superset/table/{}/ab_user/null/".format(maindb.id))
self.assertEqual(data['name'], 'ab_user')
assert len(data['columns']) > 5
assert data.get('selectStar').startswith('SELECT')

# Engine specific tests
backend = maindb.backend
if backend in ('mysql', 'postgresql'):
self.assertEqual(data.get('primaryKey').get('type'), 'pk')
self.assertEqual(
Expand Down
12 changes: 6 additions & 6 deletions tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,19 +133,19 @@ def test_search_query_on_user(self):
self.login('admin')

# Test search queries on user Id
user = appbuilder.sm.find_user('admin')
user_id = appbuilder.sm.find_user('admin').id
data = self.get_json_resp(
'/superset/search_queries?user_id={}'.format(user.id))
'/superset/search_queries?user_id={}'.format(user_id))
self.assertEquals(2, len(data))
user_ids = {k['userId'] for k in data}
self.assertEquals(set([user.id]), user_ids)
self.assertEquals(set([user_id]), user_ids)

user = appbuilder.sm.find_user('gamma_sqllab')
user_id = appbuilder.sm.find_user('gamma_sqllab').id
resp = self.get_resp(
'/superset/search_queries?user_id={}'.format(user.id))
'/superset/search_queries?user_id={}'.format(user_id))
data = json.loads(resp)
self.assertEquals(1, len(data))
self.assertEquals(data[0]['userId'] , user.id)
self.assertEquals(data[0]['userId'] , user_id)

def test_search_query_on_status(self):
self.run_some_queries()
Expand Down

0 comments on commit 2d866e3

Please sign in to comment.