Skip to content
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
1 change: 0 additions & 1 deletion dynamic_initial_data/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# flake8: noqa
from .version import __version__
from .base import BaseInitialData

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the reason for removing this? I'm open to removing it, but it's a pretty big change that will affect a lot of dependencies

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see my commit message? minervaproject@1647e68

Having something imported in a init.py file will cause the message "was imported before its application was loaded"

default_app_config = 'dynamic_initial_data.apps.DynamicInitialDataConfig'
9 changes: 4 additions & 5 deletions dynamic_initial_data/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from django.apps import apps
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django.db.transaction import atomic
from django.utils.module_loading import import_by_path
from django.utils.module_loading import import_string

from dynamic_initial_data.exceptions import InitialDataCircularDependency, InitialDataMissingApp
from dynamic_initial_data.models import RegisteredForDeletionReceipt
Expand Down Expand Up @@ -89,7 +88,7 @@ def load_app(self, app):
return self.loaded_apps.get(app)

self.loaded_apps[app] = None
initial_data_class = import_by_path(self.get_class_path(app))
initial_data_class = import_string(self.get_class_path(app))
if issubclass(initial_data_class, BaseInitialData):
self.log('Loaded app {0}'.format(app))
self.loaded_apps[app] = initial_data_class
Expand All @@ -113,7 +112,7 @@ def update_app(self, app):
# load the initial data class
try:
initial_data_class = self.load_app(app)
except ImproperlyConfigured:
except ImportError:
self.log('Could not load {0}'.format(app))
return

Expand Down Expand Up @@ -212,7 +211,7 @@ def get_dependency_call_list(self, app, call_list=None):
# load the initial data class for the app
try:
initial_data_class = self.load_app(app)
except ImproperlyConfigured:
except ImportError:
raise InitialDataMissingApp(dep=app)

dependencies = initial_data_class.dependencies
Expand Down
4 changes: 2 additions & 2 deletions dynamic_initial_data/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from django.contrib.contenttypes import generic
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.db import models
from manager_utils import ManagerUtilsManager
Expand All @@ -12,7 +12,7 @@ class RegisteredForDeletionReceipt(models.Model):
# The model object that was registered
model_obj_type = models.ForeignKey(ContentType)
model_obj_id = models.PositiveIntegerField()
model_obj = generic.GenericForeignKey('model_obj_type', 'model_obj_id', for_concrete_model=False)
model_obj = GenericForeignKey('model_obj_type', 'model_obj_id', for_concrete_model=False)

# The time at which it was registered for deletion
register_time = models.DateTimeField()
Expand Down
6 changes: 3 additions & 3 deletions dynamic_initial_data/tests/base_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,14 +222,14 @@ def test_verbose_option(self):
# cover the branch that prints if verbose is true
initial_data_manager.log('test')

@patch('dynamic_initial_data.base.import_by_path', return_value=MockInitialData)
@patch('dynamic_initial_data.base.import_string', return_value=MockInitialData)
def test_load_app_exists(self, import_patch):
"""
Tests the load_app method on an app that exists
"""
self.assertEqual(MockInitialData, InitialDataUpdater().load_app('fake'))

@patch('dynamic_initial_data.base.import_by_path', return_value=MockInitialData)
@patch('dynamic_initial_data.base.import_string', return_value=MockInitialData)
def test_load_app_cached(self, import_patch):
"""
Tests that the cache is hit since import is only called once.
Expand All @@ -240,7 +240,7 @@ def test_load_app_cached(self, import_patch):
initial_data_updater.load_app('fake')
self.assertEquals(import_patch.call_count, 1)

@patch('dynamic_initial_data.base.import_by_path', return_value=MockClass)
@patch('dynamic_initial_data.base.import_string', return_value=MockClass)
def test_load_app_doesnt_exist(self, import_patch):
"""
Tests the load_app method on an app that doesnt exist
Expand Down
3 changes: 1 addition & 2 deletions dynamic_initial_data/tests/integration_tests.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from django.test import TestCase
from mock import patch

from dynamic_initial_data import BaseInitialData
from dynamic_initial_data.base import InitialDataUpdater
from dynamic_initial_data.base import BaseInitialData, InitialDataUpdater
from dynamic_initial_data.models import RegisteredForDeletionReceipt
from dynamic_initial_data.tests.models import Account

Expand Down