Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

468 python 311 upgrade #735

Merged
merged 6 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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