示例#1
0
文件: test.py 项目: zeth/magpy
    def handle(self, *args, **kwargs):
        """
        Run the unit tests for all the test labels in the provided list.
        Labels must be of the form:
         - app,TestClass,test_method
            Run a single specific test method
         - app,TestClass
            Run all the test methods in a given class
         - app
            Search for doctests and unittests in the named application.

        When looking for tests, the test runner will look in the models and
        tests modules for the application.

        A list of 'extra' tests may also be provided; these tests
        will be added to the test suite.

        Returns the number of tests that failed.
        """

        if args:
            labels = args
        else:
            database = Database()
            labels = database.get_app_list()

        suite = self.get_suite(labels)

        verbosity = int(kwargs['verbosity'])
        failures = unittest.TextTestRunner(verbosity=verbosity).run(suite)
        if failures:
            sys.exit(bool(failures))
示例#2
0
    def handle(self, *args, **kwargs):
        print(args)
        database = Database()
        pkl_file = open(args[0], 'rb')
        instances = pickle.load(pkl_file)
        collection = database.get_collection(args[1])
        for instance in instances:
            collection.insert(instance)
            print("Added", instance['_id'])

        pkl_file.close()
示例#3
0
文件: test_magjs.py 项目: zeth/magpy
    def setUp(self):  # pylint: disable=C0103
        """Open a database connection."""
        super(TestEmbedModificationValidationB, self).setUp()

        # Create a new test model
        instance_loader = InstanceLoader(database='test', validation=False)
        instance_loader.add_instances(six.itervalues(EMBEDDED_MODELS_B))
        # Kill any test existing instances
        database = Database(database_name='test')
        self.collection = database.get_collection('article')
        self.collection.remove()
        # Add the test article
        self.collection.insert(TEST_ARTICLE_B)
示例#4
0
文件: instances.py 项目: zeth/magpy
    def __init__(self,
                 handle_none=False,
                 validation=True,
                 database=None,
                 embedded=False):
        """Startup the loader."""
        self.handle_none = handle_none
        self.skip_validation = not validation
        database_type = None
        if embedded:
            database_type = 'ainodb'
        else:
            database_type = None

        self.database = Database(database_name=database,
                                 database_type=database_type)
示例#5
0
文件: list_urls.py 项目: zeth/magpy
 def handle(self, *args, **kwargs):
     """Get the Urls."""
     database = Database()
     apps = database.get_app_list()
     urls = URLS
     if apps:
         for app in apps:
             url_path = '%s.urls' % app
             try:
                 url_module = importlib.import_module(url_path)
             except:
                 pass
             else:
                 urls.extend(getattr(url_module, 'URLS', []))
     for url in urls:
         print(url)
示例#6
0
文件: test_embed.py 项目: zeth/magpy
    def setUp(self):  # pylint: disable=C0103
        """Open a database connection and load the models."""
        super(MagEmbedTestCase, self).setUp()

        # Create test models
        EMBEDDED_MODELS['article']['_permissions'] = {
            'create': True,
            'read': True,
            'update': True,
            'delete': True,
        }

        instance_loader = InstanceLoader(database='test', validation=False)
        instance_loader.add_instances(tuple(six.itervalues(EMBEDDED_MODELS)))

        # Kill any test existing instances
        database = Database(database_name='test')
        collection = database.get_collection('article')
        collection.remove()
示例#7
0
    def handle(self, *args, **options):
        """Collect the static files of an application."""
        database = Database()

        # 0. Get the target directory
        target = database.get_setting('static', 'root')
        if not target:
            raise CommandError(
                u'No static root setting. Set static root with:\n'
                u'mag.py add_setting static root <directory-name>\n'
                u'E.g.\n'
                u'mag.py add_setting static root /var/www/static')

        # 1. Get the list of applications
        apps = database.get_app_list()
        if apps:
            apps.append('magpy')
        else:
            apps = ['magpy']

        # 2. Build a dictionary of static file names
        static_files = []
        for app in apps:
            print("Looking for static files in ", app)
            path = self.get_path(app)
            if path:
                static_files.extend(
                    self.get_filenames(path, target, app, options["appify"]))

        # 3. Check if the timestamps on the static files are newer than the
        # the saved files, and cut out any that are not
        if options['check_time']:
            static_files = filter(self.check_newer, static_files)

        # 4. Copy the files
        for source, target in static_files:
            # Make sure the target directory exist
            target_dir = os.path.dirname(target)
            if not os.path.exists(target_dir):
                os.makedirs(target_dir)
            # Copy the file
            print("Copying %s to %s" % (source, target))
            copy(source, target)
示例#8
0
 def handle(self, *args, **kwargs):
     database = Database()
     for arg in args:
         database.add_app(arg)
示例#9
0
 def __init__(self):
     """Load URLs."""
     self.apps = []
     self.database = Database()
示例#10
0
文件: add_setting.py 项目: zeth/magpy
 def handle(self, *args, **kwargs):
     database = Database()
     if len(args) != 3:
         raise CommandError
     database.add_setting(args[0], args[1], args[2])
示例#11
0
 def handle(self, *args, **kwargs):
     database = Database()
     if len(args) != 2:
         raise CommandError
     database.remove_setting(args[0], args[1])