def test_copies_in_migrations_when_needed(tmpdir):
    path = tmpdir.mkdir('fork')
    for app, has_models in [('order', True), ('search', False)]:
        customisation.fork_app(app, str(path))

        native_migration_path = path.join(app).join('migrations')
        assert has_models == native_migration_path.check()
def test_raises_exception_if_app_has_already_been_forked():
    # We piggyback on another test which means a custom app is already in
    # the settings we use for the test suite. We just check that's still
    # the case here.
    assert 'tests._site.apps.partner' in settings.INSTALLED_APPS
    with pytest.raises(ValueError):
        customisation.fork_app('partner', VALID_FOLDER_PATH)
def test_handles_dashboard_app(tmpdir):
    # Dashboard apps are fiddly as they aren't identified by a single app
    # label.
    path = tmpdir.mkdir('fork')
    customisation.fork_app('dashboard.catalogue', str(path))
    # Check __init__.py created (and supporting folders)

    path.join('dashboard').join('catalogue').join('__init__.py').ensure()
def test_dashboard_app_config(tmpdir, monkeypatch):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('dashboard', str(path))

    path.join('__init__.py').write('')
    monkeypatch.syspath_prepend(str(tmpdir))

    config_module = __import__(
        '%s.dashboard.config' % path.basename, fromlist=['DashboardConfig']
    )

    assert hasattr(config_module, 'DashboardConfig')
def test_creates_models_and_admin_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path))
    for module, expected_string in [
        ('models', 'from wshop.apps.order.models import *'),
        ('admin', 'from wshop.apps.order.admin import *'),
        ('config', 'OrderConfig')
    ]:
        filepath = path.join('order').join('%s.py' % module)
        filepath.ensure()
        contents = filepath.read()
        assert expected_string in contents
Example #6
0
    def handle(self, *args, **options):
        # Use a stdout logger
        logger = logging.getLogger(__name__)
        stream = logging.StreamHandler(self.stdout)
        logger.addHandler(stream)
        logger.setLevel(logging.DEBUG)

        app_label, folder_path = options['app_label'], options['target_path']
        try:
            customisation.fork_app(app_label, folder_path, logger)
        except Exception as e:
            raise CommandError(six.text_type(e))
def test_creates_init_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path))

    path.join('order').join('__init__.py').ensure()
def test_creates_new_folder(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path))
    path.join('order').ensure_dir()
def test_raises_exception_for_nonexistant_app_label():
    with pytest.raises(ValueError):
        customisation.fork_app('sillytown', 'somefolder')