Skip to content

Commit

Permalink
Merge pull request #1171 from rapidpro/prep-django5
Browse files Browse the repository at this point in the history
Prep and start testing on django 5.0
  • Loading branch information
norkans7 authored Apr 8, 2024
2 parents 5c8e861 + d263a37 commit 3f98111
Show file tree
Hide file tree
Showing 8 changed files with 167 additions and 179 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ on: [push, pull_request]
jobs:
test:
name: Test
strategy:
matrix:
python-version: ["3.10.x", "3.11.x"]
django-version: ["4.2.x", "5.0.x"]
env:
python-version: "3.10.x"
redis-version: "6.2"
pg-version: "15"
runs-on: ubuntu-22.04
Expand All @@ -28,7 +31,7 @@ jobs:
- name: Install Python
uses: actions/setup-python@v1
with:
python-version: ${{ env.python-version }}
python-version: ${{ matrix.python-version }}

- name: Install Poetry
uses: snok/install-poetry@v1
Expand All @@ -38,6 +41,7 @@ jobs:
- name: Initialize environment
run: |
poetry install --no-root
poetry add django==${{ matrix.django-version }}
sudo npm install -g coffee-script less
ln -s ${{ github.workspace }}/ureport/settings.py.postgres ${{ github.workspace }}/ureport/settings.py
Expand Down
308 changes: 146 additions & 162 deletions poetry.lock

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ readme = "README.md"

[tool.poetry.dependencies]
python = "^3.10"
Django = "^4.2.11"
smartmin = "^4.2.5"
rapidpro-dash = "^1.14.3"
Django = ">= 4.2.7, < 5.1"
smartmin = "^5.0.0"
rapidpro-dash = "^1.15.0"
colorama = "^0.4.3"
celery = "^5.1"
django-compressor = "^4.0"
Expand All @@ -18,7 +18,7 @@ django-digest = "^1.13"
django-rosetta = "^0.8.1"
django-storages = "^1.13.2"
django-rest-swagger = "^2.2.0"
djangorestframework = "3.14.0"
djangorestframework = "3.15.0"
dj-database-url = "^0.5.0"
Pillow = "^10.2.0"
gunicorn = "^20.1.0"
Expand Down
4 changes: 2 additions & 2 deletions ureport/backend/rapidpro.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import time
from collections import defaultdict
from datetime import timedelta
from datetime import timedelta, timezone as tzone

import requests
from django_redis import get_redis_connection
Expand Down Expand Up @@ -638,7 +638,7 @@ def pull_results(self, poll, modified_after, modified_before, progress_callback=
latest_synced_obj_time
):
latest_synced_obj_time = datetime_to_json_date(
temba_run.modified_on.replace(tzinfo=timezone.utc)
temba_run.modified_on.replace(tzinfo=tzone.utc)
)

contact_obj = contacts_map.get(temba_run.contact.uuid, None)
Expand Down
4 changes: 2 additions & 2 deletions ureport/polls/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
import uuid
from collections import defaultdict
from datetime import timedelta
from datetime import timedelta, timezone as tzone

import six
from django_redis import get_redis_connection
Expand Down Expand Up @@ -317,7 +317,7 @@ def pull_refresh_task(self):
now = timezone.now()
cache.set(
Poll.POLL_PULL_ALL_RESULTS_AFTER_DELETE_FLAG % (self.org_id, self.pk),
datetime_to_json_date(now.replace(tzinfo=timezone.utc)),
datetime_to_json_date(now.replace(tzinfo=tzone.utc)),
None,
)

Expand Down
6 changes: 3 additions & 3 deletions ureport/polls/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import uuid
import zoneinfo
from datetime import date, datetime, timedelta
from datetime import date, datetime, timedelta, timezone as tzone

import six
from mock import Mock, patch
Expand Down Expand Up @@ -130,7 +130,7 @@ def test_pull_refresh_task(self, mock_cache_set, mock_pull_refresh):
now = timezone.now()
mock_cache_set.assert_called_once_with(
Poll.POLL_PULL_ALL_RESULTS_AFTER_DELETE_FLAG % (poll1.org_id, poll1.pk),
datetime_to_json_date(now.replace(tzinfo=timezone.utc)),
datetime_to_json_date(now.replace(tzinfo=tzone.utc)),
None,
)

Expand Down Expand Up @@ -663,7 +663,7 @@ def test_poll_poll_date_view(self):
self.assertEqual(poll.org, self.uganda)
self.assertEqual(poll.title, "Poll 1")
self.assertEqual(
poll.poll_date.astimezone(self.uganda.timezone).replace(tzinfo=timezone.utc),
poll.poll_date.astimezone(self.uganda.timezone).replace(tzinfo=tzone.utc),
yesterday.replace(microsecond=0),
)

Expand Down
4 changes: 2 additions & 2 deletions ureport/utils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import time
import zoneinfo
from collections import defaultdict
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone as tzone
from itertools import chain, islice

import iso8601
Expand Down Expand Up @@ -57,7 +57,7 @@ def datetime_to_json_date(dt):
Formats a datetime as a string for inclusion in JSON
"""
# always output as UTC / Z and always include milliseconds
as_utc = dt.astimezone(timezone.utc)
as_utc = dt.astimezone(tzone.utc)
return as_utc.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"


Expand Down
4 changes: 2 additions & 2 deletions ureport/utils/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json
import zoneinfo
from datetime import datetime
from datetime import datetime, timezone as tzone

import mock
import redis
Expand Down Expand Up @@ -58,7 +58,7 @@ def clear_cache(self):
r.flushdb()

def test_datetime_to_json_date(self):
d1 = datetime(2014, 1, 2, 3, 4, 5, tzinfo=timezone.utc)
d1 = datetime(2014, 1, 2, 3, 4, 5, tzinfo=tzone.utc)
self.assertEqual(datetime_to_json_date(d1), "2014-01-02T03:04:05.000Z")
self.assertEqual(json_date_to_datetime("2014-01-02T03:04:05.000+00:00"), d1)
self.assertEqual(json_date_to_datetime("2014-01-02T03:04:05.000Z"), d1)
Expand Down

0 comments on commit 3f98111

Please sign in to comment.