Skip to content

Commit

Permalink
Added tests
Browse files Browse the repository at this point in the history
  • Loading branch information
vera-liu committed Mar 13, 2017
1 parent 1d0bcc1 commit 2042c72
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 3 deletions.
18 changes: 18 additions & 0 deletions superset/assets/spec/javascripts/sqllab/FaveQueries_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import React from 'react';
import Select from 'react-select';
import FaveQueries from '../../../javascripts/SqlLab/components/FaveQueries';
import { shallow } from 'enzyme';
import { describe, it } from 'mocha';
import { expect } from 'chai';
import sinon from 'sinon';

describe('QuerySearch', () => {
const mockedProps = {
actions: {},
};
it('is valid', () => {
expect(
React.isValidElement(<FaveQueries {...mockedProps} />)
).to.equal(true);
});
});
11 changes: 8 additions & 3 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,10 +1509,14 @@ def fave_dashboards(self, user_id):
return json_success(
json.dumps(payload, default=utils.json_int_dttm_ser))

@api
@has_access_api
@has_access
@expose("/fave_queries/", methods=['GET'])
def fave_queries(self):
if not g.user.get_id():
return Response(
json.dumps({'error': "Please login to access the queries."}),
status=403,
mimetype="application/json")
qry = (
db.session.query(
models.Query,
Expand All @@ -1526,9 +1530,10 @@ def fave_queries(self):
)
)
.order_by(
models.FavStar.dttm.desc()
models.FavStar.dttm.asc()
)
)

queries = [q.to_dict() for q in qry.all()]
payload = []
for q in queries:
Expand Down
21 changes: 21 additions & 0 deletions tests/sqllab_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,27 @@ def test_search_query_on_time(self):
self.assertLess(int(first_query_time), k['startDttm'])
self.assertLess(k['startDttm'], int(second_query_time))

def test_fave_queries(self):
self.logout()
self.run_some_queries()
# Favourite a query
self.login('admin')
query = db.session.query(models.Query).first()
client_id = query.client_id
url = '/superset/favstar/query/{}/select/'.format(client_id)
resp = self.get_json_resp(url)
self.assertEqual(resp['count'], 1)

self.login('admin')
data = self.get_json_resp('/superset/fave_queries/')
self.assertEqual(len(data), 1)
url = '/superset/favstar/query/{}/unselect/'.format(client_id)
resp = self.get_resp(url)

data = self.get_json_resp('/superset/fave_queries/')
self.assertEqual(len(data), 0)


def test_alias_duplicate(self):
self.run_sql(
"SELECT username as col, id as col, username FROM ab_user",
Expand Down

0 comments on commit 2042c72

Please sign in to comment.