Exemple #1
0
def _create_domain_test():
    tables = get_table_types()
    tables_dict = {}

    for table in tables:
        tables_dict[table.__name__] = table

    def _test_domain(self, klass):
        kwargs = {}
        args = []
        for column, name in orm_get_columns(klass):
            try:
                value = orm_get_unittest_value(klass, self, tables_dict, name, column)
            except ORMTestError as e:
                continue

            kwargs[name] = value

            args.append((name, column))

        # Sellable does not accept all arguments
        if klass.__name__ == 'Sellable':
            kwargs = {}
        # Payment needs a value argument
        elif klass.__name__ == 'Payment':
            kwargs['value'] = 123
        # TransferOrderItem needs a sellable that is also a storable
        elif klass.__name__ == 'TransferOrderItem':
            storable = self.create_storable()
            kwargs['sellable'] = storable.product.sellable
            kwargs['quantity'] = 1

        if 'id' in kwargs:
            del kwargs['id']
        # ReturnedSaleItem needs this
        if 'sale_item' in kwargs and 'sellable' in kwargs:
            kwargs['sellable'] = kwargs['sale_item'].sellable

        try:
            obj = klass(store=self.store, **kwargs)
        except Exception as e:
            self.fail(e)

        for name, col in args:
            try:
                value = orm_get_random(col)
            except ValueError:
                continue
            if value is not None:
                setattr(obj, name, value)

    namespace = dict(_test_domain=_test_domain)
    for table in tables:
        tname = table.__name__
        name = 'test' + str(tname)
        func = lambda self, t=table: self._test_domain(t)
        func.__name__ = name
        namespace[name] = func

    return type('TestDomain', (DomainTest, ), namespace)
Exemple #2
0
    def test(self, get_default_store):
        # FIXME: get_table_types need plugins to be installed to get the
        # plugin's tables. PluginManager.installed_plugins_names will use the
        # default store to get the installed plugins, so mock it to the tests'
        # store, create all the missing InstalledPlugin. Change this to a mock
        # on installed_plugins_names when we can use newer versions of
        # python-mock (which suports properly property mocking)
        get_default_store.return_value = self.store
        for p_name in self.get_oficial_plugins_names():
            if self.store.find(InstalledPlugin, plugin_name=p_name).is_empty():
                InstalledPlugin(store=self.store,
                                plugin_name=p_name, plugin_version=1)

        # Depending on the order this test is runned, the cache will be
        # already filled. Clear it so it imports again and get plugins too
        _tables_cache.clear()
        expected = set(t.__name__ for t in get_table_types())
        introspected = set(t.__name__ for t in _introspect_tables())

        # Tables in either expected or introspected but not both
        difference = expected ^ introspected
        if difference:
            self.fail("Missing tables: %s\n"
                      "Please add them to stoqlib.database.tables or to the "
                      "plugin's get_tables" % (', '.join(sorted(difference), )))
Exemple #3
0
    def test(self, get_default_store):
        # FIXME: get_table_types need plugins to be installed to get the
        # plugin's tables. PluginManager.installed_plugins_names will use the
        # default store to get the installed plugins, so mock it to the tests'
        # store, create all the missing InstalledPlugin. Change this to a mock
        # on installed_plugins_names when we can use newer versions of
        # python-mock (which suports properly property mocking)
        get_default_store.return_value = self.store
        for p_name in self.get_oficial_plugins_names():
            if self.store.find(InstalledPlugin, plugin_name=p_name).is_empty():
                InstalledPlugin(store=self.store,
                                plugin_name=p_name, plugin_version=1)

        # Depending on the order this test is runned, the cache will be
        # already filled. Clear it so it imports again and get plugins too
        _tables_cache.clear()
        expected = set(t.__name__ for t in get_table_types())
        introspected = set(t.__name__ for t in _introspect_tables())

        # Tables in either expected or introspected but not both
        difference = expected ^ introspected
        if difference:
            self.fail("Missing tables: %s\n"
                      "Please add them to stoqlib.database.tables or to the "
                      "plugin's get_tables" % (', '.join(sorted(difference), )))
Exemple #4
0
 def test(self):
     expected = set(get_table_types())
     introspected = set(_introspect_tables())
     if expected != introspected:
         candidate = expected.difference(introspected)
         if not candidate:
             candidate = introspected.difference(expected)
         tbls = sorted([t.__name__ for t in candidate])
         self.fail("Missing tables: %s.\nPlease add them to "
                   "stoqlib.database.tables" % (', '.join(tbls, )))
Exemple #5
0
 def test(self):
     expected = set(get_table_types())
     introspected = set(_introspect_tables())
     if expected != introspected:
         candidate = expected.difference(introspected)
         if not candidate:
             candidate = introspected.difference(expected)
         tbls = sorted([t.__name__ for t in candidate])
         self.fail("Missing tables: %s.\nPlease add them to "
                   "stoqlib.database.tables" % (', '.join(tbls, )))
Exemple #6
0
def _create_domain_test():
    tables = get_table_types()
    tables_dict = {}

    for table in tables:
        tables_dict[table.__name__] = table

    def _test_domain(self, klass):
        kwargs = {}
        args = []
        for column, name in orm_get_columns(klass):
            try:
                value = orm_get_unittest_value(klass, self, tables_dict, name, column)
            except ORMTestError, e:
                continue

            kwargs[name] = value

            args.append((name, column))

        # Sellable does not accept all arguments
        if klass.__name__ == 'Sellable':
            kwargs = {}

        # Payment needs a value argument
        if klass.__name__ == 'Payment':
            kwargs['value'] = 123

        if 'id' in kwargs:
            del kwargs['id']
        # ReturnedSaleItem needs this
        if 'sale_item' in kwargs and 'sellable' in kwargs:
            kwargs['sellable'] = kwargs['sale_item'].sellable

        try:
            obj = klass(store=self.store, **kwargs)
        except Exception as e:
            self.fail(e)

        if hasattr(klass, 'te_id') and not obj.te:
            self.fail('Object should have a transaction entry')

        for name, col in args:
            try:
                value = orm_get_random(col)
            except ValueError:
                continue
            if value is not None:
                setattr(obj, name, value)
Exemple #7
0
    def populate_namespace(self, bare):
        for table in get_table_types():
            self.ns[table.__name__] = table

        self.ns["store"] = self.store
        self.ns["sysparam"] = api.sysparam
        self.ns["api"] = api

        if not bare:
            self.ns["branch"] = api.get_current_branch(self.store)
            self.ns["station"] = api.get_current_station(self.store)
            self.ns["now"] = datetime.datetime.now
            self.ns["today"] = datetime.date.today

            for name in ("stoqlib.database.runtime", "stoqlib.lib.interfaces", "stoqlib.domain.interfaces"):
                mod = __import__(name, {}, {}, " ")
                self.ns.update(mod.__dict__)
Exemple #8
0
    def populate_namespace(self, bare):
        for table in get_table_types():
            self.ns[table.__name__] = table

        self.ns['store'] = self.store
        self.ns['sysparam'] = api.sysparam
        self.ns['api'] = api

        if not bare:
            self.ns['branch'] = api.get_current_branch(self.store)
            self.ns['station'] = api.get_current_station(self.store)
            self.ns['now'] = datetime.datetime.now
            self.ns['today'] = datetime.date.today

            for name in ('stoqlib.database.runtime', 'stoqlib.lib.interfaces',
                         'stoqlib.domain.interfaces'):
                mod = __import__(name, {}, {}, ' ')
                self.ns.update(mod.__dict__)
Exemple #9
0
    def populate_namespace(self, bare):
        for table in get_table_types():
            self.ns[table.__name__] = table

        self.ns['store'] = self.store
        self.ns['sysparam'] = api.sysparam
        self.ns['api'] = api

        if not bare:
            self.ns['branch'] = api.get_current_branch(self.store)
            self.ns['station'] = api.get_current_station(self.store)
            self.ns['now'] = datetime.datetime.now
            self.ns['today'] = datetime.date.today

            for name in ('stoqlib.database.runtime',
                         'stoqlib.lib.interfaces',
                         'stoqlib.domain.interfaces'):
                mod = __import__(name, {}, {}, ' ')
                self.ns.update(mod.__dict__)
Exemple #10
0
def _create_domain_test():
    tables = get_table_types()
    tables_dict = {}

    for table in tables:
        tables_dict[table.__name__] = table

    def _test_domain(self, klass):
        kwargs = {}
        args = []
        for column, name in orm_get_columns(klass):
            try:
                value = orm_get_unittest_value(klass, self, tables_dict, name,
                                               column)
            except ORMTestError as e:
                continue

            kwargs[name] = value

            args.append((name, column))

        # Sellable does not accept all arguments
        if klass.__name__ == 'Sellable':
            kwargs = {}
        # Payment needs a value argument
        elif klass.__name__ == 'Payment':
            kwargs['value'] = 123
        # TransferOrderItem needs a sellable that is also a storable
        elif klass.__name__ == 'TransferOrderItem':
            storable = self.create_storable()
            kwargs['sellable'] = storable.product.sellable
            kwargs['quantity'] = 1

        if 'id' in kwargs:
            del kwargs['id']
        # ReturnedSaleItem needs this
        if 'sale_item' in kwargs and 'sellable' in kwargs:
            kwargs['sellable'] = kwargs['sale_item'].sellable

        try:
            obj = klass(store=self.store, **kwargs)
        except Exception as e:
            self.fail(e)

        for name, col in args:
            try:
                value = orm_get_random(col)
            except ValueError:
                continue
            if value is not None:
                setattr(obj, name, value)

    namespace = dict(_test_domain=_test_domain)
    for table in tables:
        tname = table.__name__
        name = 'test' + str(tname)
        func = lambda self, t=table: self._test_domain(t)
        func.__name__ = name
        namespace[name] = func

    return type('TestDomain', (DomainTest, ), namespace)