Skip to content

Commit

Permalink
Merge pull request #741 from CDLUC3/develop
Browse files Browse the repository at this point in the history
Merge Develop to main for Python 311 upgrade
  • Loading branch information
jsjiang authored Sep 19, 2024
2 parents 3f48526 + 2e7dbfc commit 643af62
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions tests/test_api_util.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# 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=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),
('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

55 changes: 55 additions & 0 deletions tests/test_form_objects.py
Original file line number Diff line number Diff line change
@@ -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




0 comments on commit 643af62

Please sign in to comment.