Skip to content

Commit

Permalink
Merge pull request #62 from ambitioninc/develop
Browse files Browse the repository at this point in the history
2.2.0
  • Loading branch information
somewes authored Jun 28, 2023
2 parents f51eb06 + 90b4eec commit 3546864
Show file tree
Hide file tree
Showing 18 changed files with 236 additions and 174 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# copied from django-cte
name: dynamic_initial_data tests
on:
push:
branches: [master]
pull_request:
branches: [master,develop]

jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python: ['3.7', '3.8', '3.9']
# Time to switch to pytest or nose2??
# nosetests is broken on 3.10
# AttributeError: module 'collections' has no attribute 'Callable'
# https://github.com/nose-devs/nose/issues/1099
django:
- 'Django~=3.2.0'
- 'Django~=4.0.0'
- 'Django~=4.1.0'
- 'Django~=4.2.0'
experimental: [false]
exclude:
- python: '3.7'
django: 'Django~=4.0.0'
- python: '3.7'
django: 'Django~=4.1.0'
- python: '3.7'
django: 'Django~=4.2.0'
services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python }}
- name: Setup
run: |
python --version
pip install --upgrade pip wheel
pip install -r requirements/requirements.txt
pip install -r requirements/requirements-testing.txt
pip install "${{ matrix.django }}"
pip freeze
- name: Run tests
env:
DB_SETTINGS: >-
{
"ENGINE":"django.db.backends.postgresql_psycopg2",
"NAME":"dynamic_initial_data",
"USER":"postgres",
"PASSWORD":"postgres",
"HOST":"localhost",
"PORT":"5432"
}
run: |
coverage run manage.py test dynamic_initial_data
coverage report --fail-under=99
continue-on-error: ${{ matrix.experimental }}
- name: Check style
run: flake8 dynamic_initial_data
42 changes: 0 additions & 42 deletions .travis.yml

This file was deleted.

1 change: 0 additions & 1 deletion dynamic_initial_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# flake8: noqa
from .version import __version__

default_app_config = 'dynamic_initial_data.apps.DynamicInitialDataConfig'
7 changes: 7 additions & 0 deletions dynamic_initial_data/docs/release_notes.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Release Notes
=============

v2.2.0
------
* Add support for django 3.2, 4.0, 4.1, 4.2
* Add support for python 3.8, 3.9
* Remove support for django 2.0, 2.1, 2.2, 3.0, 3.1
* Remove support for python 3.6

v2.1.0
------
* Python 3.7
Expand Down
1 change: 0 additions & 1 deletion dynamic_initial_data/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db import models, migrations
import django.db.models.deletion
Expand Down
84 changes: 42 additions & 42 deletions dynamic_initial_data/tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from django.test.utils import override_settings
from django_dynamic_fixture import G
from freezegun import freeze_time
from mock import patch
from unittest.mock import patch

from dynamic_initial_data.base import BaseInitialData, InitialDataUpdater
from dynamic_initial_data.exceptions import InitialDataMissingApp, InitialDataCircularDependency
Expand All @@ -31,7 +31,7 @@ def test_register_for_deletion_one_arg(self):
initial_data = BaseInitialData()
account = G(Account)
initial_data.register_for_deletion(account)
self.assertEquals(initial_data.get_model_objs_registered_for_deletion(), [account])
self.assertEqual(initial_data.get_model_objs_registered_for_deletion(), [account])

def test_register_for_deletion_multiple_args(self):
"""
Expand All @@ -41,7 +41,7 @@ def test_register_for_deletion_multiple_args(self):
account1 = G(Account)
account2 = G(Account)
initial_data.register_for_deletion(account1, account2)
self.assertEquals(initial_data.get_model_objs_registered_for_deletion(), [account1, account2])
self.assertEqual(initial_data.get_model_objs_registered_for_deletion(), [account1, account2])


class TestInvalidDeletions(TransactionTestCase):
Expand All @@ -59,10 +59,10 @@ def test_cant_delete_obj_in_receipt(self):
RegisteredForDeletionReceipt.objects.create(model_obj=account, register_time=datetime(2013, 4, 5))
initial_data_updater.model_objs_registered_for_deletion = []

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 2)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 2)
with transaction.atomic():
initial_data_updater.handle_deletions()
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)


class TestHandleDeletions(TestCase):
Expand All @@ -86,13 +86,13 @@ def test_create_one_obj(self):
account = G(Account)
self.initial_data_updater.model_objs_registered_for_deletion = [account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
receipt = RegisteredForDeletionReceipt.objects.get()
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

def test_create_dup_objs(self):
"""
Expand All @@ -101,13 +101,13 @@ def test_create_dup_objs(self):
account = G(Account)
self.initial_data_updater.model_objs_registered_for_deletion = [account, account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
receipt = RegisteredForDeletionReceipt.objects.get()
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

def test_create_dup_proxy_objs(self):
"""
Expand All @@ -117,22 +117,22 @@ def test_create_dup_proxy_objs(self):
proxy_account = ProxyAccount.objects.get(id=account.id)
self.initial_data_updater.model_objs_registered_for_deletion = [account, account, proxy_account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 2)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 2)

receipt = RegisteredForDeletionReceipt.objects.get(model_obj_type=ContentType.objects.get_for_model(account))
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

receipt = RegisteredForDeletionReceipt.objects.get(
model_obj_type=ContentType.objects.get_for_model(proxy_account, for_concrete_model=False))
self.assertEquals(
self.assertEqual(
receipt.model_obj_type, ContentType.objects.get_for_model(ProxyAccount, for_concrete_model=False))
self.assertEquals(receipt.model_obj_id, proxy_account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_id, proxy_account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

def test_create_delete_one_obj(self):
"""
Expand All @@ -141,21 +141,21 @@ def test_create_delete_one_obj(self):
account = G(Account)
self.initial_data_updater.model_objs_registered_for_deletion = [account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
receipt = RegisteredForDeletionReceipt.objects.get()
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

# Now, don't register the object for deletion and run it again at a different time
self.initial_data_updater.model_objs_registered_for_deletion = []
with freeze_time('2013-04-12 05:00:00'):
self.initial_data_updater.handle_deletions()
# The object should be deleted, along with its receipt
self.assertEquals(Account.objects.count(), 0)
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(Account.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)

def test_create_update_one_obj(self):
"""
Expand All @@ -164,21 +164,21 @@ def test_create_update_one_obj(self):
account = G(Account)
self.initial_data_updater.model_objs_registered_for_deletion = [account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
receipt = RegisteredForDeletionReceipt.objects.get()
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

# Run the deletion handler again at a different time. It should not delete the object
with freeze_time('2013-04-12 05:00:00'):
self.initial_data_updater.handle_deletions()
# The object should not be deleted, along with its receipt
self.assertEquals(Account.objects.count(), 1)
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 1)
self.assertEquals(RegisteredForDeletionReceipt.objects.get().register_time, datetime(2013, 4, 12, 5))
self.assertEqual(Account.objects.count(), 1)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 1)
self.assertEqual(RegisteredForDeletionReceipt.objects.get().register_time, datetime(2013, 4, 12, 5))

def test_delete_already_deleted_obj(self):
"""
Expand All @@ -187,25 +187,25 @@ def test_delete_already_deleted_obj(self):
account = G(Account)
self.initial_data_updater.model_objs_registered_for_deletion = [account]

self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)
with freeze_time('2013-04-12'):
self.initial_data_updater.handle_deletions()
receipt = RegisteredForDeletionReceipt.objects.get()
self.assertEquals(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEquals(receipt.model_obj_id, account.id)
self.assertEquals(receipt.register_time, datetime(2013, 4, 12))
self.assertEqual(receipt.model_obj_type, ContentType.objects.get_for_model(Account))
self.assertEqual(receipt.model_obj_id, account.id)
self.assertEqual(receipt.register_time, datetime(2013, 4, 12))

# Delete the model object. The receipt should still exist
account.delete()
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 1)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 1)

# Now, don't register the object for deletion and run it again at a different time
self.initial_data_updater.model_objs_registered_for_deletion = []
with freeze_time('2013-04-12 05:00:00'):
self.initial_data_updater.handle_deletions()
# The object should be deleted, along with its receipt
self.assertEquals(Account.objects.count(), 0)
self.assertEquals(RegisteredForDeletionReceipt.objects.count(), 0)
self.assertEqual(Account.objects.count(), 0)
self.assertEqual(RegisteredForDeletionReceipt.objects.count(), 0)


class InitialDataUpdaterTest(TestCase):
Expand Down Expand Up @@ -238,7 +238,7 @@ def test_load_app_cached(self, import_patch):
initial_data_updater.load_app('fake')
initial_data_updater.load_app('fake')
initial_data_updater.load_app('fake')
self.assertEquals(import_patch.call_count, 1)
self.assertEqual(import_patch.call_count, 1)

@patch('dynamic_initial_data.base.import_string', return_value=MockClass)
def test_load_app_doesnt_exist(self, import_patch):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from fake import BadPath

assert(BadPath) # pragma: no cover
assert BadPath # pragma: no cover
Loading

0 comments on commit 3546864

Please sign in to comment.