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

Update to django 3.2 #423

Merged
merged 7 commits into from
Jul 14, 2022
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
38 changes: 27 additions & 11 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions pykeg/backend/backends_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ def test_keg_management(self):
new_keg = self.backend.start_keg(METER_NAME, beverage=beverage)
tap = models.KegTap.get_from_meter_name(METER_NAME)
self.assertIsNotNone(new_keg)
self.assertNotEquals(new_keg, keg)
self.assertNotEqual(new_keg, keg)
self.assertTrue(tap.is_active())
self.assertTrue(new_keg.is_on_tap())

Expand All @@ -240,7 +240,7 @@ def test_keg_management(self):
)
self.assertEqual(new_keg_2.type.producer, keg.type.producer)
self.assertEqual(new_keg_2.type.style, keg.type.style)
self.assertNotEquals(new_keg_2.type, keg.type)
self.assertNotEqual(new_keg_2.type, keg.type)

# New brewer, identical beer name == new beer type.
tap = models.KegTap.get_from_meter_name(METER_NAME)
Expand All @@ -252,9 +252,9 @@ def test_keg_management(self):
producer_name="Other Brewer",
style_name=FAKE_BEER_STYLE,
)
self.assertNotEquals(new_keg_3.type.producer, keg.type.producer)
self.assertNotEqual(new_keg_3.type.producer, keg.type.producer)
self.assertEqual(new_keg_3.type.name, keg.type.name)
self.assertNotEquals(new_keg_3.type, keg.type)
self.assertNotEqual(new_keg_3.type, keg.type)

def test_meters(self):
tap = models.KegTap.objects.all()[0]
Expand Down Expand Up @@ -289,17 +289,17 @@ def test_urls(self):
producer_name=FAKE_BREWER_NAME,
style_name=FAKE_BEER_STYLE,
)
self.assertEqual("http://example.com:8000/kegs/{}".format(keg.id), keg.full_url())
self.assertEqual("http://example.com:8000/kegs/{}/".format(keg.id), keg.full_url())

drink = self.backend.record_drink(METER_NAME, ticks=1, volume_ml=100, photo="foo")
self.assertEqual("http://example.com:8000/d/{}".format(drink.id), drink.short_url())
self.assertEqual("http://example.com:8000/d/{}/".format(drink.id), drink.short_url())
self.assertEqual(
"http://example.com:8000/s/{}".format(drink.session.id), drink.session.short_url()
"http://example.com:8000/s/{}/".format(drink.session.id), drink.session.short_url()
)

start = drink.session.start_time
datepart = "{}/{}/{}".format(start.year, start.month, start.day)
self.assertEqual(
"http://example.com:8000/sessions/{}/{}".format(datepart, drink.session.id),
"http://example.com:8000/sessions/{}/{}/".format(datepart, drink.session.id),
drink.session.full_url(),
)
22 changes: 11 additions & 11 deletions pykeg/backend/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,24 @@

from django.dispatch import Signal

user_created = Signal(providing_args=["user"])
user_created = Signal()

tap_created = Signal(providing_args=["tap"])
tap_created = Signal()

auth_token_created = Signal(providing_args=["token"])
auth_token_created = Signal()

drink_recorded = Signal(providing_args=["drink"])
drink_recorded = Signal()

drink_canceled = Signal(providing_args=["drink"])
drink_canceled = Signal()

drink_assigned = Signal(providing_args=["drink", "previous_user"])
drink_assigned = Signal()

drink_adjusted = Signal(providing_args=["drink", "previous_volume"])
drink_adjusted = Signal()

temperature_recorded = Signal(providing_args=["record"])
temperature_recorded = Signal()

keg_created = Signal(providing_args=["keg"])
keg_created = Signal()

keg_attached = Signal(providing_args=["keg", "tap"])
keg_attached = Signal()

keg_ended = Signal(providing_args=["keg"])
keg_ended = Signal()
2 changes: 1 addition & 1 deletion pykeg/core/fields.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.db import models
from django.utils.translation import ugettext as _
from django.utils.translation import gettext as _

# CountryField
# Source: http://www.djangosnippets.org/snippets/1281/
Expand Down
6 changes: 3 additions & 3 deletions pykeg/core/management/commands/upgrade.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import sys
from builtins import str
from distutils.version import StrictVersion

from django.contrib.staticfiles.management.commands import collectstatic
from django.core.management.base import BaseCommand
from django.core.management.commands import migrate
from packaging.version import Version

from pykeg.core import models
from pykeg.core.management.commands import regen_stats
Expand All @@ -14,7 +14,7 @@
# v0.9.35 - migrations rebased to 0001
# v1.1.1 - last release with South-based migrations
# v1.2.0 - first Django 1.7 migrations
MINIMUM_INSTALLED_VERSION = StrictVersion("1.1.1")
MINIMUM_INSTALLED_VERSION = Version("1.1.1")


def run(cmd, args=[]):
Expand Down Expand Up @@ -104,5 +104,5 @@ def handle(self, *args, **options):
print("Upgrade complete!")

def do_version_upgrades(self, installed_version):
if installed_version.version < (1, 2, 0):
if installed_version.release < (1, 2, 0):
print("Upgrading from v1.1.x")
6 changes: 3 additions & 3 deletions pykeg/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import re
import urllib.parse
from builtins import object, str
from distutils.version import StrictVersion
from uuid import uuid4

import pytz
Expand All @@ -24,9 +23,10 @@
from django.db.models.signals import post_save, pre_save
from django.urls import reverse, reverse_lazy
from django.utils import timezone
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _
from imagekit.models import ImageSpecField
from imagekit.processors import Adjust, resize
from packaging.version import Version

from pykeg.backend import get_kegbot_backend
from pykeg.core import colors, fields, kb_common, keg_sizes, managers
Expand Down Expand Up @@ -337,7 +337,7 @@ def get_installed_version(cls):
rows = cls.objects.filter(name="default").values("server_version")
if not rows:
return None
return StrictVersion(rows[0].get("server_version", "0.0.0"))
return Version(rows[0].get("server_version", "0.0.0"))

def get_stats(self):
return Stats.get_latest_for_view()
Expand Down
10 changes: 5 additions & 5 deletions pykeg/core/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@
import logging
import os
import pkgutil
import sys
import tempfile
from builtins import object, str
from collections import OrderedDict
from contextlib import closing
from distutils.version import StrictVersion
from importlib import metadata as importlib_metadata
from importlib.metadata import version
from threading import current_thread

import requests
from django.core.exceptions import ImproperlyConfigured
from packaging.version import Version
from redis.exceptions import RedisError

logger = logging.getLogger(__name__)
Expand All @@ -28,18 +28,18 @@

def get_version():
try:
return importlib_metadata.version("kegbot")
return version("kegbot")
except importlib_metadata.PackageNotFoundError:
return "0.0.0"


def get_version_object():
return StrictVersion(get_version())
return Version(get_version())


def must_upgrade(installed_version, new_version):
# Compare major and minor (only).
return installed_version.version[:2] < new_version.version[:2]
return installed_version.release[:2] < new_version.release[:2]


def should_upgrade(installed_verison, new_version):
Expand Down
10 changes: 5 additions & 5 deletions pykeg/core/util_test.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
"""Test for util module."""

from builtins import str
from distutils.version import StrictVersion

from django.test import TestCase
from packaging.version import Version

from pykeg.core import util

Expand All @@ -15,12 +15,12 @@ def test_get_version(self):
util.get_version_object()
except ValueError as e:
self.fail("Illegal version: " + str(e))
self.assertTrue(util.get_version_object().version >= (0, 9, 23))
self.assertTrue(util.get_version_object().release >= (0, 9, 23))

def test_must_upgrade(self):
v100 = StrictVersion("1.0.0")
v101 = StrictVersion("1.0.1")
v110 = StrictVersion("1.1.0")
v100 = Version("1.0.0")
v101 = Version("1.0.1")
v110 = Version("1.1.0")

self.assertTrue(util.should_upgrade(v100, v101))
self.assertFalse(util.should_upgrade(v100, v100))
Expand Down
16 changes: 8 additions & 8 deletions pykeg/notification/backends/email_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_keg_tapped(self):

expected_body_plain = """A new keg of Unknown by Unknown was just tapped on My Kegbot!

Track it here: http://localhost:1234/kegs/%s
Track it here: http://localhost:1234/kegs/%s/

You are receiving this e-mail because you have notifications enabled
on My Kegbot. To change your settings, visit http://localhost:1234/account.""" % (
Expand All @@ -65,7 +65,7 @@ def test_keg_tapped(self):
</p>

<p>
Track it <a href="http://localhost:1234/kegs/%s">here</a>.
Track it <a href="http://localhost:1234/kegs/%s/">here</a>.
</p>

<p>
Expand Down Expand Up @@ -104,7 +104,7 @@ def test_session_started(self):

expected_body_plain = """A new session was just kicked off on My Kegbot.

You can follow the session here: http://localhost:1234/s/%s
You can follow the session here: http://localhost:1234/s/%s/

You are receiving this e-mail because you have notifications enabled
on My Kegbot. To change your settings, visit http://localhost:1234/account.""" % (
Expand All @@ -118,7 +118,7 @@ def test_session_started(self):
</p>

<p>
You can follow the session <a href="http://localhost:1234/s/%s">here</a>.
You can follow the session <a href="http://localhost:1234/s/%s/">here</a>.
</p>

<p>
Expand Down Expand Up @@ -161,7 +161,7 @@ def test_keg_volume_low(self):

expected_body_plain = """Keg %s (Unknown by Unknown) is 15.0%% full.

See full statistics here: http://localhost:1234/kegs/%s
See full statistics here: http://localhost:1234/kegs/%s/

You are receiving this e-mail because you have notifications enabled
on My Kegbot. To change your settings, visit http://localhost:1234/account.""" % (
Expand All @@ -176,7 +176,7 @@ def test_keg_volume_low(self):
</p>

<p>
See full statistics <a href="http://localhost:1234/kegs/%s">here</a>.
See full statistics <a href="http://localhost:1234/kegs/%s/">here</a>.
</p>

<p>
Expand Down Expand Up @@ -215,7 +215,7 @@ def test_keg_ended(self):

expected_body_plain = """Keg %s of Unknown by Unknown was just finished on My Kegbot.

See final statistics here: http://localhost:1234/kegs/%s
See final statistics here: http://localhost:1234/kegs/%s/

You are receiving this e-mail because you have notifications enabled
on My Kegbot. To change your settings, visit http://localhost:1234/account.""" % (
Expand All @@ -231,7 +231,7 @@ def test_keg_ended(self):
</p>

<p>
See final statistics <a href="http://localhost:1234/kegs/%s">here</a>.
See final statistics <a href="http://localhost:1234/kegs/%s/">here</a>.
</p>

<p>
Expand Down
Loading