Skip to content

Commit

Permalink
added cache-policy test (#4355)
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrey Zhavoronkov authored Feb 18, 2022
1 parent 9950118 commit 6f1d122
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/rest_api/test_0005_chache_policy.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Copyright (C) 2022 Intel Corporation
#
# SPDX-License-Identifier: MIT

from http import HTTPStatus
import re
from .utils.config import server_get

class TestCachePolicy:

@staticmethod
def _get_js_bundle_url(response):
match = re.search(r'<script type="text/javascript" src="(/assets/cvat-ui.\w+.min.js)"></script>', response)
if match:
return match.group(1)

def _test_cache_policy_enabled(self, response):
assert response.status_code == HTTPStatus.OK
assert 'public' in response.headers['Cache-Control'] and 'max-age' in response.headers['Cache-Control']

def _test_cache_policy_disabled(self, response):
assert response.status_code == HTTPStatus.OK
assert 'no-cache' in response.headers['Cache-Control']

def test_index_not_cached(self, find_users):
user = find_users(privilege='user')[0]['username']
index_page_response = server_get(user, '/')

self._test_cache_policy_disabled(index_page_response)

def test_asset_cached(self, find_users):
user = find_users(privilege='user')[0]['username']
index_page_response = server_get(user, '/')
js_asset_url = self._get_js_bundle_url(index_page_response.content.decode('utf-8'))
js_asset_response = server_get(user, js_asset_url)

self._test_cache_policy_enabled(js_asset_response)

0 comments on commit 6f1d122

Please sign in to comment.