Example #1
0
def runtests():
    try:
        runner = NoseTestSuiteRunner()
    except NameError:
        runner = DjangoTestSuiteRunner()
    failures = runner.run_tests(['bscom_tests'])
    sys.exit(failures)
Example #2
0
def runtests():
    try:
        runner = NoseTestSuiteRunner()
    except NameError:
        runner = DjangoTestSuiteRunner()
    failures = runner.run_tests(['hancom_tests'])
    sys.exit(failures)
Example #3
0
def runtests(*test_args, **kwargs):

    if not test_args:
        test_args = ['tests']
    kwargs.setdefault('interactive', False)
    test_runner = NoseTestSuiteRunner(**kwargs)

    failures = test_runner.run_tests(test_args)
    sys.exit(failures)
Example #4
0
 def plugin(self):
     if self._plugin == None:
         from django_nose.runner import NoseTestSuiteRunner
         from django_nose.plugin import DjangoSetUpPlugin
         runner = NoseTestSuiteRunner()
         self._plugin = DjangoSetUpPlugin(runner)
     return self._plugin
Example #5
0
import coverage
import django
from django_nose.runner import NoseTestSuiteRunner

import os
import sys

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "accounts.test.settings")

    cov = coverage.coverage(
        source=['accounts'],
        omit=['*/migrations/*', '*/test/*'],
    )
    cov.erase()
    cov.start()

    django.setup()
    test_runner = NoseTestSuiteRunner()

    failures = test_runner.run_tests(['accounts'])

    cov.stop()
    cov.save()
    cov.report()

    if failures:
        sys.exit(failures)
Example #6
0
 def setUp(self):
     """Initialize the runner."""
     self.runner = NoseTestSuiteRunner()
Example #7
0
class GetModelsForConnectionTests(TestCase):

    """Test runner._get_models_for_connection."""

    tables = ['test_table%d' % i for i in range(5)]

    def _connection_mock(self, tables):
        class FakeIntrospection(object):
            def get_table_list(*args, **kwargs):
                return tables

        class FakeConnection(object):
            introspection = FakeIntrospection()

            def cursor(self):
                return None

        return FakeConnection()

    def _model_mock(self, db_table):
        class FakeModel(object):
            _meta = type('meta', (object,), {'db_table': db_table})()

        return FakeModel()

    @contextmanager
    def _cache_mock(self, tables=[]):
        def get_models(*args, **kwargs):
            return [self._model_mock(t) for t in tables]

        old = apps.get_models
        apps.get_models = get_models
        yield
        apps.get_models = old

    def setUp(self):
        """Initialize the runner."""
        self.runner = NoseTestSuiteRunner()

    def test_no_models(self):
        """For a DB with no tables, return nothing."""
        connection = self._connection_mock([])
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_wrong_models(self):
        """If no tables exists for models, return nothing."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_some_models(self):
        """If some of the models are in the DB, return matching models."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables[1:3]):
            result_tables = [
                m._meta.db_table for m in
                self.runner._get_models_for_connection(connection)]
        self.assertEqual(result_tables, self.tables[1:3])

    def test_all_models(self):
        """If all the models have in the DB, return them all."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables):
            result_tables = [
                m._meta.db_table for m in
                self.runner._get_models_for_connection(connection)]
        self.assertEqual(result_tables, self.tables)
Example #8
0
 def setUp(self):
     self.runner = NoseTestSuiteRunner()
Example #9
0
class GetModelsForConnectionTests(TestCase):
    tables = ['test_table%d' % i for i in range(5)]

    def _connection_mock(self, tables):
        class FakeIntrospection(object):
            def get_table_list(*args, **kwargs):
                return tables

        class FakeConnection(object):
            introspection = FakeIntrospection()
            cursor = lambda x: None

        return FakeConnection()

    def _model_mock(self, db_table):
        class FakeModel(object):
            _meta = type('meta', (object, ), {'db_table': db_table})()

        return FakeModel()

    @contextmanager
    def _cache_mock(self, tables=[]):
        def get_models(*args, **kwargs):
            return [self._model_mock(t) for t in tables]

        old = apps.get_models
        apps.get_models = get_models
        yield
        apps.get_models = old

    def setUp(self):
        self.runner = NoseTestSuiteRunner()

    def test_no_models(self):
        """For a DB with no tables, return nothing."""
        connection = self._connection_mock([])
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_wrong_models(self):
        """If no tables exists for models, return nothing."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(['table1', 'table2']):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_some_models(self):
        """If some of the models has appropriate table in the DB, return matching models."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables[1:3]):
            result_tables = [
                m._meta.db_table
                for m in self.runner._get_models_for_connection(connection)
            ]
        self.assertEqual(result_tables, self.tables[1:3])

    def test_all_models(self):
        """If all the models have appropriate tables in the DB, return them all."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables):
            result_tables = [
                m._meta.db_table
                for m in self.runner._get_models_for_connection(connection)
            ]
        self.assertEqual(result_tables, self.tables)
Example #10
0
def nose():
    from django_nose.runner import NoseTestSuiteRunner
    test_runner = NoseTestSuiteRunner(verbosity=1)
    failures = test_runner.run_tests(['-s', 'tests', '--with-yanc'])
    return failures
Example #11
0
 def setUp(self):
     """Initialize the runner."""
     self.runner = NoseTestSuiteRunner()
Example #12
0
 def setUp(self):
     self.runner = NoseTestSuiteRunner()
Example #13
0
def runtests():
    runner = DjangoTestSuiteRunner()
    runner = NoseTestSuiteRunner()
    failures = runner.run_tests(['tests'])
    sys.exit(failures)
Example #14
0
class GetModelsForConnectionTests(TestCase):
    """Test runner._get_models_for_connection."""

    tables = ["test_table%d" % i for i in range(5)]

    def _connection_mock(self, tables):
        class FakeIntrospection(object):
            def get_table_list(*args, **kwargs):
                return tables

        class FakeConnection(object):
            introspection = FakeIntrospection()

            def cursor(self):
                return None

        return FakeConnection()

    def _model_mock(self, db_table):
        class FakeModel(object):
            _meta = type("meta", (object, ), {"db_table": db_table})()

        return FakeModel()

    @contextmanager
    def _cache_mock(self, tables=[]):
        def get_models(*args, **kwargs):
            return [self._model_mock(t) for t in tables]

        old = apps.get_models
        apps.get_models = get_models
        yield
        apps.get_models = old

    def setUp(self):
        """Initialize the runner."""
        self.runner = NoseTestSuiteRunner()

    def test_no_models(self):
        """For a DB with no tables, return nothing."""
        connection = self._connection_mock([])
        with self._cache_mock(["table1", "table2"]):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    def test_wrong_models(self):
        """If no tables exists for models, return nothing."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(["table1", "table2"]):
            self.assertEqual(
                self.runner._get_models_for_connection(connection), [])

    @attr("special")
    def test_some_models(self):
        """If some of the models are in the DB, return matching models."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables[1:3]):
            result_tables = [
                m._meta.db_table
                for m in self.runner._get_models_for_connection(connection)
            ]
        self.assertEqual(result_tables, self.tables[1:3])

    def test_all_models(self):
        """If all the models have in the DB, return them all."""
        connection = self._connection_mock(self.tables)
        with self._cache_mock(self.tables):
            result_tables = [
                m._meta.db_table
                for m in self.runner._get_models_for_connection(connection)
            ]
        self.assertEqual(result_tables, self.tables)