Skip to content

Commit

Permalink
fork_app command: Also create admin.py
Browse files Browse the repository at this point in the history
Otherwise the ModelAdmins aren't discovered.
  • Loading branch information
maiksprenger committed May 22, 2014
1 parent baea09f commit 000df2c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 4 additions & 2 deletions oscar/core/customisation.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@ def fork_app(app_label, folder_path, logger=None):
os.mkdir(app_folder_path)

# Create minimum app files
logger.info("Creating __init__.py and models.py modules")
logger.info("Creating __init__.py, admin.py and models.py modules")
create_file(os.path.join(app_folder_path, '__init__.py'))
create_file(os.path.join(app_folder_path, 'admin.py'),
"from oscar.apps.%s.admin import * # noqa" % app_label)
create_file(
os.path.join(app_folder_path, 'models.py'),
"from oscar.apps.%s.models import *" % app_label)
"from oscar.apps.%s.models import * # noqa" % app_label)

# Migrations
source = os.path.join(
Expand Down
12 changes: 7 additions & 5 deletions tests/unit/core/customisation_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,15 @@ def test_creates_init_file(self):
filepath = os.path.join(self.tmp_folder, 'order', '__init__.py')
self.assertTrue(os.path.exists(filepath))

def test_creates_models_file(self):
def test_creates_models_and_admin_file(self):
customisation.fork_app('order', self.tmp_folder)
filepath = os.path.join(self.tmp_folder, 'order', 'models.py')
self.assertTrue(os.path.exists(filepath))
for module in ['models', 'admin']:
filepath = os.path.join(self.tmp_folder, 'order', '%s.py' % module)
self.assertTrue(os.path.exists(filepath))

contents = open(filepath).read()
self.assertTrue('from oscar.apps.order.models import *' in contents)
contents = open(filepath).read()
expected_string = 'from oscar.apps.order.%s import *' % module
self.assertTrue(expected_string in contents)

def test_copies_in_migrations(self):
customisation.fork_app('order', self.tmp_folder)
Expand Down

0 comments on commit 000df2c

Please sign in to comment.