From 9d5b665d2a6cfa0531eb30a4bf993fa99921a482 Mon Sep 17 00:00:00 2001 From: jsjiang Date: Fri, 13 Sep 2024 12:35:58 -0700 Subject: [PATCH 1/4] unit test deprecated cgi function --- tests/test_api_util.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 tests/test_api_util.py diff --git a/tests/test_api_util.py b/tests/test_api_util.py new file mode 100644 index 00000000..956e0434 --- /dev/null +++ b/tests/test_api_util.py @@ -0,0 +1,27 @@ +# Copyright©2021, Regents of the University of California +# http://creativecommons.org/licenses/BSD + +import pytest + +from django.test import RequestFactory +import impl.api as api + +@pytest.fixture +def factory(): + return RequestFactory() + +@pytest.mark.parametrize("val,expected",[ + ('text/plain', True), + ('text/plain; charset=utf-8', True), + ('text/plain; charset=US-ASCII', False), + ('text/html', False), + ('text/xml; charset=utf-8', False), + ('application/json', False), + ('application/javascript', False), + ('application/x-www-form-urlencoded', False), +]) +def test_content_type_1(factory, val, expected): + request = factory.post('/shoulder/ark:/99999/fk4', content_type=val) + ret = api.is_text_plain_utf8(request) + assert ret == expected + \ No newline at end of file From 43bc319e678c1da31c98c96f2006260e99c4c772 Mon Sep 17 00:00:00 2001 From: jsjiang Date: Fri, 13 Sep 2024 12:52:57 -0700 Subject: [PATCH 2/4] add test cases to cover mimetype='' --- tests/test_api_util.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/test_api_util.py b/tests/test_api_util.py index 956e0434..8a520788 100644 --- a/tests/test_api_util.py +++ b/tests/test_api_util.py @@ -13,7 +13,13 @@ def factory(): @pytest.mark.parametrize("val,expected",[ ('text/plain', True), ('text/plain; charset=utf-8', True), + ('text/plain; charset=UTF-8', True), + ('TEXT/PLAIN; charset=utf-8', False), ('text/plain; charset=US-ASCII', False), + ('; charset=utf-8', True), # mimetype='' + ('; charset=US-ASCII', False), # mimetype='' + ('charset=utf-8', False), + ('charset=US-ASCII', False), ('text/html', False), ('text/xml; charset=utf-8', False), ('application/json', False), From 73462eaba5d6f8f5865f8bbc409082c2d4f04980 Mon Sep 17 00:00:00 2001 From: jsjiang Date: Mon, 16 Sep 2024 08:30:09 -0700 Subject: [PATCH 3/4] upgrade github action python version to 3.11 --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 5dd2ebd7..81fa9630 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -17,7 +17,7 @@ jobs: - name: Set up Python uses: actions/setup-python@v5 with: - python-version: '3.8' + python-version: '3.11' architecture: 'x64' - name: Start MySQL service From 0dcb2f7e906b178549d19ff450d545bc9f2961ca Mon Sep 17 00:00:00 2001 From: jsjiang Date: Mon, 16 Sep 2024 12:00:24 -0700 Subject: [PATCH 4/4] test regex in form_objects --- tests/test_form_objects.py | 55 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test_form_objects.py diff --git a/tests/test_form_objects.py b/tests/test_form_objects.py new file mode 100644 index 00000000..d4b88a11 --- /dev/null +++ b/tests/test_form_objects.py @@ -0,0 +1,55 @@ +import pytest +import re + +import impl.form_objects as form_objects + + +@pytest.mark.parametrize("string,expected",[ + ('2000', '2000'), + ('200', None), + ('2', None), + ('x', None), + ('yyyy', None), + ('', None), + (':unac', ':unac'), + (':unal', ':unal'), + (':unap', ':unap'), + (':unas', ':unas'), + (':unav', ':unav'), + (':unkn', ':unkn'), + (':none', ':none'), + (':tba', ':tba'), + (':tba', ':tba'), + (':tba', ':tba'), +]) +def test_regex_year(string, expected): + pattern = form_objects.REGEX_4DIGITYEAR + match = re.search(pattern, string) + if match: + assert match.group() == expected + +# REGEX_GEOPOINT = '-?(\d+(\.\d*)?|\.\d+)$' +@pytest.mark.parametrize("string,expected",[ + ('-123.456', '-123.456'), + ('123.456', '123.456'), + ('1.', '1.'), + ('-1.', '-1.'), + ('12.', '12.'), + ('.1', '.1'), + ('-.1', '-.1'), + ('.456', '.456'), + ('-.456', '-.456'), + ('.', None), + ('x', None), + ('yyyy', None), + ('', None), +]) +def test_regex_geopoint(string, expected): + pattern = form_objects.REGEX_GEOPOINT + match = re.search(pattern, string) + if match: + assert match.group() == expected + + + +