Skip to content

Commit

Permalink
Merge pull request #27 from counsyl/20240827__remove_enum34_v2
Browse files Browse the repository at this point in the history
Remove enum34 from requirements.txt
  • Loading branch information
hrichards authored Aug 28, 2024
2 parents f506d03 + 716aac6 commit 3a764ae
Show file tree
Hide file tree
Showing 21 changed files with 1,383 additions and 1,114 deletions.
8 changes: 2 additions & 6 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:

services:
postgres:
image: postgres:9.6
image: postgres:12
env:
POSTGRES_USER: django
POSTGRES_PASSWORD: django
Expand All @@ -31,18 +31,14 @@ jobs:
strategy:
max-parallel: 4
matrix:
python-version: [3.6]
python-version: [3.6, 3.8, 3.9]

steps:
- uses: actions/checkout@v3
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install Dependencies
run: |
pip install virtualenv
npm i pg
- name: Run Tests
run: |
make test
Expand Down
3 changes: 3 additions & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
3.6
3.8
3.9
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
# 3.1.0

- No functional changes: added support targets and refactored tests and dependencies.

## Major

- Support Django 3.2 and 4.2.
- Add support for Python 3.8 and 3.9.
- Cope with psycopg2 bug: only 2.8 is supported through Django 2.2, but 2.9 is supported for higher Django versions.
- Parameterize test suite on USE_TZ to confirm Capone works for both True and False.
- Remove unneeded dependency `enum34`.
- Refactor to use `django.utils.timezone`.

## Minor

- Convert tests to Pytest style.
- Default in tests to USE_TZ == True.
- Remove remaining Python 2 compatibility shims.
- Unpin lots of test dependencies.

# 3.0.0

- Drop Django < 1.11 support.
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ VENDOR_SENTINEL:=.sentinel
venv: $(VENV_ACTIVATE)

$(VENV_ACTIVATE): requirements*.txt
test -f $@ || virtualenv --python=python3.6 $(VENV_DIR)
test -f $@ || python -m venv $(VENV_DIR)
$(WITH_VENV) pip install -r requirements-setup.txt
$(WITH_VENV) pip install -e .
$(WITH_VENV) pip install -r requirements-dev.txt
Expand Down
17 changes: 6 additions & 11 deletions capone/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@
from django.contrib.contenttypes.models import ContentType
from django.db import models
from django.db.models import Q
from django.utils.encoding import python_2_unicode_compatible
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

from capone.exceptions import TransactionBalanceException

Expand All @@ -20,7 +19,6 @@
NEGATIVE_DEBITS_HELP_TEXT = "Amount for this entry. Debits are negative, and credits are positive." # noqa: E501


@python_2_unicode_compatible
class TransactionRelatedObject(models.Model):
"""
A piece of evidence for a particular Transaction.
Expand Down Expand Up @@ -164,7 +162,6 @@ def filter_by_related_objects(
raise ValueError("Invalid match_type.")


@python_2_unicode_compatible
class TransactionType(models.Model):
"""
A user-defined "type" to group `Transactions`.
Expand Down Expand Up @@ -202,7 +199,6 @@ def get_or_create_manual_transaction_type_id():
return get_or_create_manual_transaction_type().id


@python_2_unicode_compatible
class Transaction(models.Model):
"""
The main model for representing a financial event in `capone`.
Expand Down Expand Up @@ -267,10 +263,11 @@ def validate(self):
Instead, the only check that makes sense is that the entries for the
transaction still balance.
"""
total = sum([entry.amount for entry in self.entries.all()])
if total != Decimal(0):
raise TransactionBalanceException(
"Credits do not equal debits. Mis-match of %s." % total)
if self.pk:
total = sum([entry.amount for entry in self.entries.all()])
if total != Decimal(0):
raise TransactionBalanceException(
"Credits do not equal debits. Mis-match of %s." % total)
return True

def save(self, **kwargs):
Expand All @@ -292,7 +289,6 @@ def summary(self):
}


@python_2_unicode_compatible
class Ledger(models.Model):
"""
A group of `LedgerEntries` all debiting or crediting the same resource.
Expand Down Expand Up @@ -368,7 +364,6 @@ def __str__(self):
amount=self.amount, ledger=self.ledger.name)


@python_2_unicode_compatible
class LedgerBalance(models.Model):
"""
A Denormalized balance for a related object in a ledger.
Expand Down
10 changes: 5 additions & 5 deletions capone/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from capone.tests.models import Order


class UserFactory(factory.DjangoModelFactory):
class UserFactory(factory.django.DjangoModelFactory):
"""
Factory for django.contrib.auth.get_user_model()
Expand All @@ -27,7 +27,7 @@ class Meta:
email = username = factory.Sequence(lambda n: "TransactionUser #%s" % n)


class LedgerFactory(factory.DjangoModelFactory):
class LedgerFactory(factory.django.DjangoModelFactory):
class Meta:
model = Ledger

Expand All @@ -36,22 +36,22 @@ class Meta:
number = factory.Sequence(lambda n: n)


class OrderFactory(factory.DjangoModelFactory):
class OrderFactory(factory.django.DjangoModelFactory):
class Meta:
model = Order

patient_name = factory.Sequence(lambda n: "Patient %s" % n)
barcode = factory.Sequence(lambda n: str(n))


class CreditCardTransactionFactory(factory.DjangoModelFactory):
class CreditCardTransactionFactory(factory.django.DjangoModelFactory):
class Meta:
model = CreditCardTransaction

cardholder_name = factory.Sequence(lambda n: "Cardholder %s" % n)


class TransactionTypeFactory(factory.DjangoModelFactory):
class TransactionTypeFactory(factory.django.DjangoModelFactory):
class Meta:
model = TransactionType

Expand Down
2 changes: 2 additions & 0 deletions capone/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,5 @@
'django.contrib.messages.middleware.MessageMiddleware',
)
SESSION_ENGINE = 'django.contrib.sessions.backends.db'

USE_TZ = True
Loading

0 comments on commit 3a764ae

Please sign in to comment.