Пример #1
0
def test_raises_exception_if_app_has_already_been_forked():
    # We piggyback on another test which means a custom app is already in
    # the apps directory we use for the test suite. We just check that's still
    # the case here.
    assert exists(join(VALID_FOLDER_PATH, 'partner'))
    with pytest.raises(ValueError):
        customisation.fork_app('partner', VALID_FOLDER_PATH, 'partner')
Пример #2
0
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), app)

        native_migration_path = path.join(app).join('migrations')
        assert has_models == native_migration_path.check()
Пример #3
0
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), app)

        native_migration_path = path.join(app).join('migrations')
        assert has_models == native_migration_path.check()
Пример #4
0
def test_raises_exception_if_app_has_already_been_forked():
    # We piggyback on another test which means a custom app is already in
    # the apps directory we use for the test suite. We just check that's still
    # the case here.
    assert exists(join(VALID_FOLDER_PATH, 'partner'))
    with pytest.raises(ValueError):
        customisation.fork_app('partner', VALID_FOLDER_PATH, 'partner')
Пример #5
0
 def test_raises_exception_if_app_has_already_been_forked(self):
     # 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.
     self.assertIn('tests._site.apps.partner', settings.INSTALLED_APPS)
     with self.assertRaises(ValueError):
         customisation.fork_app('partner', VALID_FOLDER_PATH)
Пример #6
0
 def test_local_folder(self):
     tmpdir = tempfile.mkdtemp()
     os.chdir(tmpdir)
     customisation.fork_app('basket', '.', 'basket')
     sys.path.append(tmpdir)
     config_module = __import__('basket.apps', fromlist=['BasketConfig'])
     assert hasattr(config_module, 'BasketConfig')
     assert config_module.BasketConfig.name == 'basket'
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()
Пример #8
0
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('catalogue_dashboard', str(path), 'dashboard.catalogue')
    # Check __init__.py created (and supporting folders)

    path.join('dashboard').join('catalogue').join('__init__.py').ensure()
 def test_local_folder(self):
     tmpdir = tempfile.mkdtemp()
     os.chdir(tmpdir)
     customisation.fork_app('basket', '.', 'basket')
     sys.path.append(tmpdir)
     config_module = __import__('basket.apps', fromlist=['BasketConfig'])
     assert hasattr(config_module, 'BasketConfig')
     assert config_module.BasketConfig.name == 'basket'
 def test_absolute_target_path(self):
     tmpdir = tempfile.mkdtemp()
     customisation.fork_app('order', tmpdir, 'order')
     sys.path.append(tmpdir)
     config_module = __import__('order.apps', fromlist=['OrderConfig'])
     assert hasattr(config_module, 'OrderConfig')
     config_app_name = config_module.OrderConfig.name
     assert not config_app_name.startswith('.')
Пример #11
0
 def test_absolute_target_path(self):
     tmpdir = tempfile.mkdtemp()
     customisation.fork_app('order', tmpdir, 'order')
     sys.path.append(tmpdir)
     config_module = __import__('order.apps', fromlist=['OrderConfig'])
     assert hasattr(config_module, 'OrderConfig')
     config_app_name = config_module.OrderConfig.name
     assert not config_app_name.startswith('.')
Пример #12
0
 def test_handles_dashboard_app(self):
     # Dashboard apps are fiddly as they aren't identified by a single app
     # label.
     customisation.fork_app('dashboard.catalogue', self.tmp_folder)
     # Check __init__.py created (and supporting folders)
     init_path = os.path.join(self.tmp_folder,
                              'dashboard/catalogue/__init__.py')
     self.assertTrue(os.path.exists(init_path))
 def test_copies_in_migrations_when_needed(self):
     for app, has_models in [('order', True), ('search', False)]:
         customisation.fork_app(app, self.tmp_folder)
         native_migration_path = os.path.join(
             self.tmp_folder, app, 'migrations')
         self.assertEqual(has_models, os.path.exists(native_migration_path))
         south_migration_path = os.path.join(
             self.tmp_folder, app, 'south_migrations')
         self.assertEqual(has_models, os.path.exists(south_migration_path))
Пример #14
0
    def test_creates_models_and_admin_file(self):
        customisation.fork_app('order', self.tmp_folder)
        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()
            expected_string = 'from oscar.apps.order.%s import *' % module
            self.assertTrue(expected_string in contents)
Пример #15
0
 def test_copies_in_migrations_when_needed(self):
     for app, has_models in [('order', True), ('search', False)]:
         customisation.fork_app(app, self.tmp_folder)
         native_migration_path = os.path.join(self.tmp_folder, app,
                                              'migrations')
         self.assertEqual(has_models, os.path.exists(native_migration_path))
         south_migration_path = os.path.join(self.tmp_folder, app,
                                             'south_migrations')
         self.assertEqual(has_models, os.path.exists(south_migration_path))
Пример #16
0
def test_dashboard_app_config(tmpdir, monkeypatch):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('dashboard', str(path), 'dashboard')

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

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

    assert hasattr(config_module, 'DashboardConfig')
Пример #17
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))
Пример #18
0
def test_creates_models_and_admin_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')
    for module, expected_string in [
        ('models', 'from oscar.apps.order.models import *'),
        ('admin', 'from oscar.apps.order.admin import *'),
        ('apps', 'OrderConfig')
    ]:
        filepath = path.join('order').join('%s.py' % module)
        filepath.ensure()
        contents = filepath.read()
        assert expected_string in contents
Пример #19
0
def test_dashboard_app_config(tmpdir, monkeypatch):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('dashboard', str(path), 'dashboard')

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

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

    assert hasattr(config_module, 'DashboardConfig')
Пример #20
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))
Пример #21
0
def test_creates_models_and_admin_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')
    for module, expected_string in [
        ('models', 'from oscar.apps.order.models import *'),
        ('admin', 'from oscar.apps.order.admin import *'),
        ('apps', 'OrderConfig')
    ]:
        filepath = path.join('order').join('%s.py' % module)
        filepath.ensure()
        contents = filepath.read()
        assert expected_string in contents
Пример #22
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 = options['app_label']
        target_path = options['target_path']
        new_app_subpackage = options['new_app_subpackage']
        try:
            customisation.fork_app(app_label, target_path, new_app_subpackage, logger)
        except Exception as e:
            raise CommandError(str(e))
Пример #23
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 = options['app_label']
        target_path = options['target_path']
        new_app_subpackage = options['new_app_subpackage']
        try:
            customisation.fork_app(app_label, target_path, new_app_subpackage,
                                   logger)
        except Exception as e:
            raise CommandError(str(e))
Пример #24
0
    def test_fork_third_party(self):
        tmpdir = tempfile.mkdtemp()
        installed_apps = list(settings.INSTALLED_APPS)
        installed_apps.append('thirdparty_package.apps.myapp')
        with override_settings(INSTALLED_APPS=installed_apps):
            customisation.fork_app('myapp', tmpdir, 'custom_myapp')
            forked_app_dir = join(tmpdir, 'custom_myapp')
            assert exists(forked_app_dir)
            assert exists(join(forked_app_dir, 'apps.py'))
            sys.path.append(tmpdir)

            config_module = __import__('custom_myapp.apps',
                                       fromlist=['CustomMyAppConfig'])
            assert hasattr(config_module, 'MyAppConfig')
            assert config_module.MyAppConfig.name.endswith('.custom_myapp')
Пример #25
0
def test_creates_init_file(tmpdir, monkeypatch):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')

    path.join('order').join('__init__.py').ensure()

    monkeypatch.syspath_prepend(str(tmpdir))

    config_module = __import__('fork.order.apps', fromlist=['OrderConfig'])
    delete_from_import_cache('fork.order.apps')

    expected_string = "default_app_config = '{}.apps.OrderConfig".format(
        config_module.OrderConfig.name)
    contents = path.join('order').join('__init__.py').read()
    assert expected_string in contents
    def test_fork_third_party(self):
        tmpdir = tempfile.mkdtemp()
        installed_apps = list(settings.INSTALLED_APPS)
        installed_apps.append('thirdparty_package.apps.myapp')
        with override_settings(INSTALLED_APPS=installed_apps):
            customisation.fork_app('myapp', tmpdir, 'custom_myapp')
            forked_app_dir = join(tmpdir, 'custom_myapp')
            assert exists(forked_app_dir)
            assert exists(join(forked_app_dir, 'apps.py'))
            sys.path.append(tmpdir)

            config_module = __import__('custom_myapp.apps', fromlist=['CustomMyAppConfig'])
            assert hasattr(config_module, 'MyAppConfig')
            assert config_module.MyAppConfig.name.endswith('.custom_myapp')
            assert config_module.MyAppConfig.label == 'myapp'
Пример #27
0
    def handle(self, *args, **options):
        # Check that the app hasn't already been forked
        if len(args) < 2:
            raise CommandError(
                "You must specify an app label and a folder to create "
                "the new app in")

        # Use a stdout logger
        logger = logging.getLogger(__name__)
        stream = logging.StreamHandler(self.stdout)
        logger.addHandler(stream)
        logger.setLevel(logging.DEBUG)

        app_label, folder_path = args[:2]
        try:
            customisation.fork_app(app_label, folder_path, logger)
        except Exception as e:
            raise CommandError(e)
Пример #28
0
    def handle(self, *args, **options):
        # Check that the app hasn't already been forked
        if len(args) < 2:
            raise CommandError(
                "You must specify an app label and a folder to create "
                "the new app in")

        # Use a stdout logger
        logger = logging.getLogger(__name__)
        stream = logging.StreamHandler(self.stdout)
        logger.addHandler(stream)
        logger.setLevel(logging.DEBUG)

        app_label, folder_path = args[:2]
        try:
            customisation.fork_app(app_label, folder_path, logger)
        except Exception as e:
            raise CommandError(six.text_type(e))
Пример #29
0
def test_raises_exception_for_nonexistant_app_label():
    with pytest.raises(ValueError):
        customisation.fork_app('sillytown', 'somefolder', 'sillytown')
Пример #30
0
 def test_creates_init_file(self):
     customisation.fork_app('order', self.tmp_folder)
     filepath = os.path.join(self.tmp_folder, 'order', '__init__.py')
     self.assertTrue(os.path.exists(filepath))
Пример #31
0
 def test_creates_new_folder(self):
     customisation.fork_app('order', self.tmp_folder)
     new_folder_path = os.path.join(self.tmp_folder, 'order')
     self.assertTrue(os.path.exists(new_folder_path))
Пример #32
0
 def test_raises_exception_for_nonexistant_app_label(self):
     with self.assertRaises(ValueError):
         customisation.fork_app('sillytown', 'somefolder')
Пример #33
0
def test_creates_new_folder(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')
    path.join('order').ensure_dir()
Пример #34
0
def test_creates_init_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')

    path.join('order').join('__init__.py').ensure()
Пример #35
0
def test_creates_init_file(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')

    path.join('order').join('__init__.py').ensure()
Пример #36
0
def test_creates_new_folder(tmpdir):
    path = tmpdir.mkdir('fork')
    customisation.fork_app('order', str(path), 'order')
    path.join('order').ensure_dir()
Пример #37
0
def test_raises_exception_for_nonexistant_app_label():
    with pytest.raises(ValueError):
        customisation.fork_app('sillytown', 'somefolder', 'sillytown')
 def test_raises_exception_for_nonexistant_folder(self):
     assert not os.path.exists('does_not_exist')
     with self.assertRaises(ValueError):
         customisation.fork_app('order', 'does_not_exist')
Пример #39
0
 def test_raises_exception_for_nonexistant_folder(self):
     assert not os.path.exists('does_not_exist')
     with self.assertRaises(ValueError):
         customisation.fork_app('order', 'does_not_exist')