Skip to content

Commit

Permalink
Merge pull request #180 from ttngu207/master
Browse files Browse the repository at this point in the history
handle epoch time in _filter_to_restriction
  • Loading branch information
ethho authored Nov 15, 2024
2 parents 963e321 + c6bf9c4 commit 0ae8ed9
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
docker-compose.y*ml
.coverage
*.egg-info
.idea/
dist
build
docs/_build
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@

Observes [Semantic Versioning](https://semver.org/spec/v2.0.0.html) standard and [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) convention.

## [0.8.13] - 11/15/2024

### Fixed

- Handle attribute value passed as epoch time in `_filter_to_restriction`

## [0.8.12] - 2024-10-03

### Fixed
Expand Down
7 changes: 7 additions & 0 deletions pharus/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,16 @@ def _filter_to_restriction(attribute_filter: dict, attribute_type: str) -> str:
else:
operation = attribute_filter["operation"]

if (
re.match(r"^datetime.*$", attribute_type)
or re.match(r"timestamp", attribute_type)
) and str(attribute_filter["value"]).isnumeric():
attribute_filter["value"] = f"FROM_UNIXTIME({attribute_filter['value']})"

if (
isinstance(attribute_filter["value"], str)
and not attribute_filter["value"].isnumeric()
and not attribute_filter["value"].startswith("FROM_UNIXTIME")
):
value = (
f"X'{attribute_filter['value'].replace('-', '')}'"
Expand Down
2 changes: 1 addition & 1 deletion pharus/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ def api_version() -> str:
Content-Type: application/json
{
"version": "0.8.12"
"version": "0.8.13"
}
```
Expand Down
2 changes: 1 addition & 1 deletion pharus/version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""Package metadata."""

__version__ = "0.8.12"
__version__ = "0.8.13"
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@

with open(path.join(here, "requirements.txt")) as f:
requirements = [
"{pkg} @ {target}#egg={pkg}".format(
pkg=re.search(r"/([A-Za-z0-9\-]+)\.git", r).group(1), target=r
(
"{pkg} @ {target}#egg={pkg}".format(
pkg=re.search(r"/([A-Za-z0-9\-]+)\.git", r).group(1), target=r
)
if "+" in r
else r
)
if "+" in r
else r
for r in f.read().splitlines()
if "#" not in r
]
Expand Down
4 changes: 4 additions & 0 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,10 @@ class Student(dj.Lookup):
for i in range(100)
]

Student.insert1(
(110, "Unix Time", "123-45-6789", "2022-05-06 12:11:10", 2000.0, None, 0)
)

yield Student
Student.drop()

Expand Down
15 changes: 15 additions & 0 deletions tests/test_filter.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ def test_filters(token, client, Student):
assert REST_records[0][6] == 0


def test_filters_from_unixtime(token, client, Student):
# unix time 1651839070: "2022-05-06 12:11:10"
restriction = [
dict(attributeName="student_enroll_date", operation="=", value=1651839070),
]
encoded_restriction = b64encode(dumps(restriction).encode("utf-8")).decode("utf-8")
q = dict(limit=10, page=1, order="student_id ASC", restriction=encoded_restriction)
REST_records = client.get(
f'/schema/{Student.database}/table/{"Student"}/record?{urlencode(q)}',
headers=dict(Authorization=f"Bearer {token}"),
).json["records"]
assert len(REST_records) == 1
assert REST_records[0][1] == "Unix Time"


def test_uuid_filter(token, client, Computer):
"""Verify UUID can be properly restricted."""
restriction = [
Expand Down

0 comments on commit 0ae8ed9

Please sign in to comment.