pax_global_header00006660000000000000000000000064141512176460014521gustar00rootroot0000000000000052 comment=bae85fa332834a69fdbd2cf291a5b2595e6999af django-swappable-models-1.3.0/000077500000000000000000000000001415121764600162215ustar00rootroot00000000000000django-swappable-models-1.3.0/.github/000077500000000000000000000000001415121764600175615ustar00rootroot00000000000000django-swappable-models-1.3.0/.github/workflows/000077500000000000000000000000001415121764600216165ustar00rootroot00000000000000django-swappable-models-1.3.0/.github/workflows/ci.yml000066400000000000000000000015741415121764600227430ustar00rootroot00000000000000name: Django Swappable Models Build on: push: branches: - master pull_request: branches: - master jobs: build: name: Python==${{ matrix.python-version }} runs-on: ubuntu-latest strategy: fail-fast: false matrix: python-version: [3.7, 3.8, 3.9] steps: - uses: actions/checkout@v2 with: ref: ${{ github.event.pull_request.head.sha }} - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | pip install -U "pip==20.2.4" wheel setuptools pip install tox tox-gh-actions pip install openwisp-utils[qa]@https://github.com/openwisp/openwisp-utils/tarball/master - name: QA checks run: ./run-qa-checks - name: Test run: tox django-swappable-models-1.3.0/.gitignore000066400000000000000000000001021415121764600202020ustar00rootroot00000000000000*.pyc *.egg-info *.egg *.sw? build dist README.rst /.eggs/ /.tox/ django-swappable-models-1.3.0/CHANGES.rst000066400000000000000000000045231415121764600200270ustar00rootroot00000000000000Changelog ========= Verson 1.3.0 [2021-11-29] ------------------------- - [change] Allow possibility to point swappable dependency to specific migration number (instead of only to ``__latest__``) Version 1.2.0 [2021-11-12] -------------------------- - [feature] Add possibility to point swappable dependency to ``__latest__`` - [change] Added support for Python 3.9 - [change] Added support for Django 3.2 and Django 4.0a1 - [change] Dropped support for old Django versions (<2.2) - [change] Dropped support for old Python versions (<3.7) - [feature] Added optional ``require_ready`` argument to ``load_model`` function Version 1.1.2 [2020-01-15] -------------------------- - [deps] Verified support for python 3.8 - [deps] Added support for Django 3.0 and Django Rest Framework 3.11 Version 1.1.1 [2019-07-23] -------------------------- - [deps] Drop python<3.3 support - [deps] Added support for python 3.7 - [deps] Django 2 support added Version 1.1.0 [2017-05-11] -------------------------- - [test] Added tests for swapper.split - `#13 `_ [fix] Handle contrib apps and apps with dot in app_label. Version 1.0.0 [2016-08-26] -------------------------- - [docs] Improved usuability docs - `86e238 `_: [deps] Compatibility with django 1.10 added Version 0.3.0 [2015-11-17] -------------------------- - `#9 `_ [deps] Added support for django 1.9 Version 0.2.2 [2015-06-16] -------------------------- - [deps] Added support for django~=1.6.0 - [deps] Added support for Python 3.3 - [docs] Fix model reference in README - [docs] Notes for load_model initialization (`for more info see #2 `_) Version 0.2.1 [2014-11-18] -------------------------- - [docs] Added examples for migration scripts - [docs] Documented use of Functions - [fix] Fixed Lookup Error in load_model Version 0.2.0 [2014-09-13] -------------------------- - [deps] Added support for Django 1.7 - [feature] Added `swapper.dependency` function. - [tests] Added tests Version 0.1.1 [2014-01-09] -------------------------- - [docs] Added References Version 0.1.0 [2014-01-09] -------------------------- - Added base functions for swapping models django-swappable-models-1.3.0/LICENSE000066400000000000000000000021301415121764600172220ustar00rootroot00000000000000Copyright (c) 2021, OpenWISP Copyright (c) 2014-2017, S. Andrew Sheppard, http://wq.io/ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. django-swappable-models-1.3.0/README.md000066400000000000000000000265741415121764600175160ustar00rootroot00000000000000Swapper ======= [![Dependency monitoring](https://img.shields.io/librariesio/release/github/openwisp/django-swappable-models)](https://libraries.io/github/openwisp/django-swappable-models) #### Django Swappable Models - No longer only for auth.User! Swapper is an unofficial API for the [undocumented] but very powerful Django feature: swappable models. Swapper facilitates implementing arbitrary swappable models in your own reusable apps. [![Latest PyPI Release](https://img.shields.io/pypi/v/swapper.svg)](https://pypi.org/project/swapper) [![Release Notes](https://img.shields.io/github/release/openwisp/django-swappable-models.svg )](https://github.com/wq/django-swappable-models/releases) [![License](https://img.shields.io/pypi/l/swapper.svg)](https://github.com/openwisp/django-swappable-models/blob/master/LICENSE) [![GitHub Stars](https://img.shields.io/github/stars/openwisp/django-swappable-models.svg)](https://github.com/openwisp/django-swappable-models/stargazers) [![GitHub Forks](https://img.shields.io/github/forks/openwisp/django-swappable-models.svg)](https://github.com/openwisp/django-swappable-models/network) [![GitHub Issues](https://img.shields.io/github/issues/openwisp/django-swappable-models.svg)](https://github.com/openwisp/django-swappable-models/issues) [![Build Status](https://github.com/openwisp/django-swappable-models/actions/workflows/ci.yml/badge.svg)](https://github.com/openwisp/django-swappable-models/actions/workflows/ci.yml) [![Python Support](https://img.shields.io/pypi/pyversions/swapper.svg)](https://pypi.org/project/swapper) [![Django Support](https://img.shields.io/pypi/djversions/swapper.svg)](https://pypi.org/project/swapper) ## Motivation Suppose your reusable app has two related tables: ```python from django.db import models class Parent(models.Model): name = models.TextField() class Child(models.Model): name = models.TextField() parent = models.ForeignKey(Parent) ``` Suppose further that you want to allow the user to subclass either or both of these models and supplement them with their own additional fields. You could use Abstract classes (e.g. `BaseParent` and `BaseChild`) for this, but then you would either need to: 1. Avoid putting the foreign key on `BaseChild` and tell the user they need to do it. 2. Put the foreign key on `BaseChild`, but make `Parent` a concrete model that can't be swapped 3. Use swappable models, together with `ForeignKeys` that read the swappable settings. This third approach is taken by Django to facilitate [swapping the auth.User model]. The `auth.User` swappable code was implemented in a generic way that allows it to be used for any model. Although this capability is currently [undocumented] while any remaining issues are being sorted out, it has proven to be very stable and useful in our experience. Swapper is essentially a simple API wrapper around this existing functionality. Note that Swapper is primarily a tool for library authors; users of your reusable app generally should not need to know about Swapper in order to use it. (See the notes on [End User Documentation](#end-user-documentation) below.) ### Real-World Examples Swapper is used extensively in several OpenWISP packages to facilitate customization and extension. Notable examples include: * [openwisp-users] * [openwisp-controller] * [openwisp-radius] The use of swapper in these packages promotes [Software Reusability][reusability], one of the core values of the OpenWISP project. ## Creating a Reusable App First, make sure you have `swapper` installed. If you are publishing your reusable app as a Python package, be sure to add `swapper` to your project's dependencies (e.g. `setup.py`) to ensure that users of your app don't have errors integrating it. ```bash pip3 install swapper ``` Extending the above example, you might create two abstract base classes and corresponding default implementations: ```python # reusableapp/models.py from django.db import models import swapper class BaseParent(models.Model): # minimal base implementation ... class Meta: abstract = True class Parent(BaseParent): # default (swappable) implementation ... class Meta: swappable = swapper.swappable_setting('reusableapp', 'Parent') class BaseChild(models.Model): parent = models.ForeignKey(swapper.get_model_name('reusableapp', 'Parent')) # minimal base implementation ... class Meta: abstract = True class Child(BaseChild): # default (swappable) implementation ... class Meta: swappable = swapper.swappable_setting('reusableapp', 'Child') ``` ### Loading Swapped Models In your reusable views and other functions, always use the swapper instead of importing swappable models directly. This is because you might not know whether the user of your app is using your default implementation or their own version. ```python # reusableapp/views.py # Might work, might not # from .models import Parent import swapper Parent = swapper.load_model("reusableapp", "Parent") Child = swapper.load_model("reusableapp", "Child") def view(request, *args, **kwargs): qs = Parent.objects.all() # ... ``` > Note: `swapper.load_model()` is the general equivalent of [get_user_model()] and subject to the same constraints: e.g. it should not be used until after the model system has fully initialized. ### Migration Scripts Swapper can also be used in migration scripts to facilitate dependency ordering and foreign key references. To use this feature in your library, generate a migration script with `makemigrations` and make the following changes. In general, users of your library should not need to make any similar changes to their own migration scripts. The one exception is if you have multiple levels of swappable models with foreign keys pointing to each other. ```diff # reusableapp/migrations/0001_initial.py from django.db import models, migrations < from django.conf import settings > import swapper class Migration(migrations.Migration): dependencies = [ < migrations.swappable_dependency(settings.REUSABLEAPP_PARENT_MODEL), > swapper.dependency('reusableapp', 'Parent') ] operations = [ migrations.CreateModel( name='Child', fields=[ ('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')), ], options={ < 'swappable': 'REUSABLEAPP_CHILD_MODEL', > 'swappable': swapper.swappable_setting('reusableapp', 'Child'), }, bases=(models.Model,), ), migrations.CreateModel( name='Parent', fields=[ ('id', models.AutoField(auto_created=True, serialize=False, primary_key=True, verbose_name='ID')), ], options={ < 'swappable': 'REUSABLEAPP_PARENT_MODEL', > 'swappable': swapper.swappable_setting('reusableapp', 'Parent'), }, bases=(models.Model,), ), migrations.AddField( model_name='child', name='parent', < field=models.ForeignKey(to=settings.REUSABLEAPP_PARENT_MODEL), > field=models.ForeignKey(to=swapper.get_model_name('reusableapp', 'Parent')), preserve_default=True, ), ] ``` ## End User Documentation With the above setup, the user of your app can override one or both models in their own app. You might provide them with an example like this: ```python # myapp/models.py from reusableapp.models import BaseParent class Parent(BaseParent): # custom implementation ... ``` Then, tell your users to update their settings to trigger the swap. ```python # myproject/settings.py REUSABLEAPP_PARENT_MODEL = "myapp.Parent" ``` The goal is to make this process just as easy for your end user as [swapping the auth.User model] is. As with `auth.User`, there are some important caveats that you may want to inform your users about. The biggest issue is that your users will probably need to define the swapped model settings **before creating any migrations** for their implementation of `myapp`. Due to key assumptions made within Django's migration infrastructure, it is difficult to start out with a default (non-swapped) model and then later to switch to a swapped implementation without doing some migration hacking. This is somewhat awkward - as your users will most likely want to try out your default implementation before deciding to customize it. Unfortunately, there isn't an easy workaround due to how the swappable setting is currently implemented in Django core. This will likely be addressed in future Django versions (see [#10] and [Django ticket #25313]). ## API Documentation Here is the full API for `swapper`, which you may find useful in creating your reusable app code. End users of your library should generally not need to reference this API. function | purpose ---------|-------- `swappable_setting(app_label, model)` | Generates a swappable setting name for the provided model (e.g. `"REUSABLEAPP_PARENT_MODEL"`) `is_swapped(app_label, model)` | Determines whether or not a given model has been swapped. (Returns the model name if swapped, otherwise `False`) `get_model_name(app_label, model)` | Gets the name of the model the swappable model has been swapped for (or the name of the original model if not swapped.) `get_model_names(app_label, models)` | Match a list of model names to their swapped versions. All of the models should be from the same app (though their swapped versions need not be). `load_model(app_label, model, required=True)` | Load the swapped model class for a swappable model (or the original model if it hasn't been swapped). If your code can function without the specified model, set `required = False`. `dependency(app_label, model, version=None)` | Generate a dependency tuple for use in migrations. Use `version` only when depending on the first migration of the target dependency doesn't work (eg: when a specific migration needs to be depended upon), we recommend avoid using `version='__latest__'` because it can have serious [drawbacks] when new migrations are added to the module which is being depended upon. `set_app_prefix(app_label, prefix)` | Set a custom prefix for swappable settings (the default is the upper case `app_label`). This can be useful if the app has a long name or is part of a larger framework. This should be set at the top of your models.py. `join(app_label, model)`, `split(model)` | Utilities for splitting and joining `"app.Model"` strings and `("app", "Model")` tuples. [undocumented]: https://code.djangoproject.com/ticket/19103 [swapping the auth.User model]: https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#auth-custom-user [openwisp-users]: https://github.com/openwisp/openwisp-users#extend-openwisp-users [openwisp-controller]: https://github.com/openwisp/openwisp-controller#extending-openwisp-controller [openwisp-radius]: https://openwisp-radius.readthedocs.io/en/latest/developer/how_to_extend.html [reusability]: https://openwisp.io/docs/general/values.html#software-reusability-means-long-term-sustainability [get_user_model()]: https://docs.djangoproject.com/en/4.0/topics/auth/customizing/#referencing-the-user-model [#10]: https://github.com/openwisp/django-swappable-models/issues/10 [Django ticket #25313]: https://code.djangoproject.com/ticket/25313 [drawbacks]: https://code.djangoproject.com/ticket/23071 django-swappable-models-1.3.0/run-qa-checks000077500000000000000000000000771415121764600206140ustar00rootroot00000000000000#!/bin/bash set -e openwisp-qa-check \ --skip-checkmigrations django-swappable-models-1.3.0/setup.cfg000066400000000000000000000004721415121764600200450ustar00rootroot00000000000000[bdist_wheel] universal=1 [flake8] max-line-length = 110 # W503: line break before or after operator # W504: line break after or after operator # W605: invalid escape sequence ignore = W605, W503, W504 [isort] multi_line_output=3 use_parentheses=True include_trailing_comma=True force_grid_wrap=0 line_length=88 django-swappable-models-1.3.0/setup.py000066400000000000000000000026551415121764600177430ustar00rootroot00000000000000from setuptools import setup LONG_DESCRIPTION = """ The unofficial Django swappable models API. """ def readme(): try: readme = open('README.md') except IOError: return LONG_DESCRIPTION else: return readme.read() setup( name='swapper', use_scm_version=True, author='S. Andrew Sheppard', author_email='andrew@wq.io', url='https://github.com/openwisp/django-swappable-models', license='MIT', packages=['swapper'], description=LONG_DESCRIPTION.strip(), long_description=readme(), long_description_content_type="text/markdown", classifiers=[ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'License :: OSI Approved :: MIT License', 'Natural Language :: English', 'Operating System :: OS Independent', 'Programming Language :: Python :: 3', 'Programming Language :: Python :: 3.7', 'Programming Language :: Python :: 3.8', 'Programming Language :: Python :: 3.9', 'Framework :: Django', 'Framework :: Django :: 2.0', 'Framework :: Django :: 2.1', 'Framework :: Django :: 2.2', 'Framework :: Django :: 3.0', 'Framework :: Django :: 3.1', 'Framework :: Django :: 3.2', 'Framework :: Django :: 4.0', ], tests_require=['django>=2.0'], test_suite='tests', setup_requires=['setuptools_scm'], ) django-swappable-models-1.3.0/swapper/000077500000000000000000000000001415121764600177025ustar00rootroot00000000000000django-swappable-models-1.3.0/swapper/__init__.py000066400000000000000000000052701415121764600220170ustar00rootroot00000000000000from django.apps import apps from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.db.migrations import swappable_dependency _prefixes = {} def swappable_setting(app_label, model): """ Returns the setting name to use for the given model (i.e. AUTH_USER_MODEL) """ prefix = _prefixes.get(app_label, app_label) setting = "{prefix}_{model}_MODEL".format( prefix=prefix.upper(), model=model.upper() ) # Ensure this attribute exists to avoid migration issues in Django 1.7 if not hasattr(settings, setting): setattr(settings, setting, join(app_label, model)) return setting def is_swapped(app_label, model): """ Returns the value of the swapped setting, or False if the model hasn't been swapped. """ default_model = join(app_label, model) setting = swappable_setting(app_label, model) value = getattr(settings, setting, default_model) if value != default_model: return value else: return False def get_model_name(app_label, model): """ Returns [app_label.model] unless the model has been swapped, in which case returns the swappable setting value. """ return is_swapped(app_label, model) or join(app_label, model) def dependency(app_label, model, version=None): """ Returns a Django 1.7+ style dependency tuple for inclusion in migration.dependencies[] """ dependencies = swappable_dependency(get_model_name(app_label, model)) if not version: return dependencies return dependencies[0], version def get_model_names(app_label, models): """ Map model names to their swapped equivalents for the given app """ return dict((model, get_model_name(app_label, model)) for model in models) def load_model(app_label, model, required=True, require_ready=True): """ Load the specified model class, or the class it was swapped out for. """ swapped = is_swapped(app_label, model) if swapped: app_label, model = split(swapped) try: cls = apps.get_model(app_label, model, require_ready=require_ready) except LookupError: cls = None if cls is None and required: raise ImproperlyConfigured( "Could not find {name}!".format(name=join(app_label, model)) ) return cls def set_app_prefix(app_label, prefix): """ Set a custom prefix to use for the given app (e.g. WQ) """ _prefixes[app_label] = prefix def join(app_label, model): return "{app_label}.{model}".format( app_label=app_label, model=model, ) def split(model): app_label, _, model = model.rpartition(".") return app_label, model django-swappable-models-1.3.0/tests/000077500000000000000000000000001415121764600173635ustar00rootroot00000000000000django-swappable-models-1.3.0/tests/__init__.py000066400000000000000000000011411415121764600214710ustar00rootroot00000000000000import os import django from django.core.management import call_command from django.test.utils import setup_test_environment os.environ.setdefault('DJANGO_SETTINGS_MODULE', "tests.settings") setup_test_environment() if hasattr(django, 'setup'): # Django 1.7+ django.setup() call_command('makemigrations', 'default_app', interactive=False) if os.environ["DJANGO_SETTINGS_MODULE"] == "tests.swap_settings": call_command('makemigrations', 'alt_app', interactive=False) call_command('migrate', interactive=False) else: # Django 1.6 call_command('syncdb', interactive=False) django-swappable-models-1.3.0/tests/alt_app/000077500000000000000000000000001415121764600210035ustar00rootroot00000000000000django-swappable-models-1.3.0/tests/alt_app/__init__.py000066400000000000000000000000001415121764600231020ustar00rootroot00000000000000django-swappable-models-1.3.0/tests/alt_app/models.py000066400000000000000000000002611415121764600226370ustar00rootroot00000000000000from django.db import models from tests.default_app.models import BaseType class Type(BaseType): code = models.SlugField() class Meta: app_label = 'alt_app' django-swappable-models-1.3.0/tests/default_app/000077500000000000000000000000001415121764600216475ustar00rootroot00000000000000django-swappable-models-1.3.0/tests/default_app/__init__.py000066400000000000000000000000001415121764600237460ustar00rootroot00000000000000django-swappable-models-1.3.0/tests/default_app/models.py000066400000000000000000000007601415121764600235070ustar00rootroot00000000000000from django.db import models import swapper class BaseType(models.Model): name = models.CharField(max_length=255) class Meta: abstract = True class Type(BaseType): class Meta: swappable = swapper.swappable_setting("default_app", "Type") class Item(models.Model): type = models.ForeignKey( swapper.get_model_name('default_app', "Type"), on_delete=models.CASCADE ) name = models.CharField(max_length=255) description = models.TextField() django-swappable-models-1.3.0/tests/settings.py000066400000000000000000000003031415121764600215710ustar00rootroot00000000000000SECRET_KEY = '1234' INSTALLED_APPS = ('tests.default_app',) MIDDLEWARE_CLASSES = tuple() DATABASES = { 'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}, } SWAP = False django-swappable-models-1.3.0/tests/swap_settings.py000066400000000000000000000004131415121764600226250ustar00rootroot00000000000000from . import settings DEFAULT_APP_TYPE_MODEL = "alt_app.Type" MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES DATABASES = settings.DATABASES INSTALLED_APPS = settings.INSTALLED_APPS INSTALLED_APPS += ('tests.alt_app',) SECRET_KEY = settings.SECRET_KEY SWAP = True django-swappable-models-1.3.0/tests/test_swapper.py000066400000000000000000000074431415121764600224650ustar00rootroot00000000000000import unittest from django.conf import settings from django.core.exceptions import ImproperlyConfigured from django.test import TestCase import swapper try: from django.db import migrations # noqa except ImportError: DJ17 = False else: DJ17 = True class SwapperTestCase(TestCase): # Tests that should work whether or not default_app.Type is swapped def test_fields(self): Type = swapper.load_model('default_app', 'Type') fields = dict((field.name, field) for field in Type._meta.fields) self.assertIn('name', fields) def test_create(self): Type = swapper.load_model('default_app', 'Type') Item = swapper.load_model('default_app', 'Item') Item.objects.create( type=Type.objects.create(name="Type 1"), name="Item 1", ) self.assertEqual(Item.objects.count(), 1) item = Item.objects.all()[0] self.assertEqual(item.type.name, "Type 1") def test_not_installed(self): Invalid = swapper.load_model("invalid_app", "Invalid", required=False) self.assertIsNone(Invalid) with self.assertRaises(ImproperlyConfigured): swapper.load_model("invalid_app", "Invalid", required=True) def test_non_contrib_app_split(self): self.assertEqual(swapper.split('alt_app.Type'), ('alt_app', 'Type')) def test_contrib_app_split(self): self.assertEqual( swapper.split('alt_app.contrib.named_things.NamedThing'), ('alt_app.contrib.named_things', 'NamedThing'), ) # Tests that only work if default_app.Type is swapped @unittest.skipUnless(settings.SWAP, "requires swapped models") def test_swap_setting(self): self.assertTrue(swapper.is_swapped("default_app", "Type")) self.assertEqual(swapper.get_model_name("default_app", "Type"), "alt_app.Type") @unittest.skipUnless(settings.SWAP, "requires swapped models") def test_swap_fields(self): Type = swapper.load_model('default_app', 'Type') fields = dict((field.name, field) for field in Type._meta.fields) self.assertIn('code', fields) @unittest.skipUnless(settings.SWAP, "requires swapped models") def test_swap_create(self): Type = swapper.load_model('default_app', 'Type') Item = swapper.load_model('default_app', 'Item') Item.objects.create( type=Type.objects.create( name="Type 1", code="type-1", ), name="Item 1", ) self.assertEqual(Item.objects.count(), 1) item = Item.objects.all()[0] self.assertEqual(item.type.code, "type-1") @unittest.skipUnless(settings.SWAP and DJ17, "requires swapped models & Django 1.7") def test_swap_dependency(self): self.assertEqual( swapper.dependency("default_app", "Type"), ("alt_app", "__first__") ) self.assertEqual( swapper.dependency("default_app", "Type", "__latest__"), ("alt_app", "__latest__"), ) self.assertEqual( swapper.dependency("default_app", "Type", "0001_custom_migration"), ("alt_app", "0001_custom_migration"), ) # Tests that only work if default_app.Type is *not* swapped @unittest.skipIf(settings.SWAP, "requires non-swapped models") def test_default_setting(self): self.assertFalse(swapper.is_swapped("default_app", "Type")) self.assertEqual( swapper.get_model_name("default_app", "Type"), "default_app.Type" ) @unittest.skipUnless( not settings.SWAP and DJ17, "requires non-swapped models & Django 1.7" ) def test_default_dependency(self): self.assertEqual( swapper.dependency("default_app", "Type"), ("default_app", "__first__"), ) django-swappable-models-1.3.0/tox.ini000066400000000000000000000014531415121764600175370ustar00rootroot00000000000000[tox] envlist = py{37,38}-django22-{noswap,swap} py{37,38}-django30-{noswap,swap} py{37,38,39}-django31-{noswap,swap} py{37,38,39}-django32-{noswap,swap} py{38,39}-django40-{noswap, swap} lint [gh-actions] python = 3.7: py37 3.8: py38, lint 3.9: py39, lint [testenv] commands = rm -rf tests/default_app/migrations/ tests/alt_app/migrations/ python setup.py test deps = django22: django~=2.2.0 django30: django~=3.0.0 django31: django~=3.1.0 django32: django~=3.2.0 django40: django~=4.0a1 setenv = noswap: DJANGO_SETTINGS_MODULE=tests.settings swap: DJANGO_SETTINGS_MODULE=tests.swap_settings whitelist_externals = rm [testenv:lint] commands = rm -rf tests/default_app/migrations/ tests/alt_app/migrations/ flake8 swapper tests