cache_tests.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. """Unit tests for Superset with caching"""
  18. import json
  19. from superset import cache, db
  20. from superset.utils.core import QueryStatus
  21. from .base_tests import SupersetTestCase
  22. class CacheTests(SupersetTestCase):
  23. def __init__(self, *args, **kwargs):
  24. super(CacheTests, self).__init__(*args, **kwargs)
  25. def setUp(self):
  26. cache.clear()
  27. def tearDown(self):
  28. cache.clear()
  29. def test_cache_value(self):
  30. self.login(username="admin")
  31. slc = self.get_slice("Girls", db.session)
  32. json_endpoint = "/superset/explore_json/{}/{}/".format(
  33. slc.datasource_type, slc.datasource_id
  34. )
  35. resp = self.get_json_resp(
  36. json_endpoint, {"form_data": json.dumps(slc.viz.form_data)}
  37. )
  38. resp_from_cache = self.get_json_resp(
  39. json_endpoint, {"form_data": json.dumps(slc.viz.form_data)}
  40. )
  41. self.assertFalse(resp["is_cached"])
  42. self.assertTrue(resp_from_cache["is_cached"])
  43. self.assertEqual(resp_from_cache["status"], QueryStatus.SUCCESS)
  44. self.assertEqual(resp["data"], resp_from_cache["data"])
  45. self.assertEqual(resp["query"], resp_from_cache["query"])