Example #1
0
def mock_sublime_view(regions=None, substr=lambda sel: None):
    view = Mock()
    view.settings = Mock(return_value=mock_sublime_settings({"tab_size": 4}))

    view.sel = Mock(return_value=regions)
    view.substr = substr
    view.replace = Mock()
    return view
    def test_configured_init(self, handler):
        token = "azertyuiop123456789"
        crawler = Mock()
        crawler.settings = {"LOGENTRIES_TOKEN": token}

        extension = LogentriesExtension.from_crawler(crawler)

        handler.assert_called_once_with(token)
        extension.handler
Example #3
0
    def test_celeryd(self, workercommand):
        from pyramid_celery.commands.celeryd import main

        worker = Mock()
        run = Mock()

        worker.run = run
        workercommand.return_value = worker

        settings = {"CELERY_ALWAYS_EAGER": True}
        registry = Mock()
        registry.settings = settings

        main()
Example #4
0
    def test_celery_quoted_values(self):
        from pyramid_celery import Celery

        settings = {"BROKER_URL": '"redis://localhost:6379/0"', "BROKER_TRANSPORT_OPTIONS": '{"foo": "bar"}'}

        registry = Mock()
        registry.settings = settings

        env = {"registry": registry}

        celery = Celery(env)
        new_settings = celery.loader.read_configuration()

        assert new_settings["BROKER_URL"] == "redis://localhost:6379/0"
    def test_from_crawler_not_configured(self):
        # asserts that from_crawler will raise NotConfigured the
        # constructor raises NotConfigured exception
        crawler = Mock()

        for conn_sett, table_name, insert_options in self.init_mocks_iter():
            crawler.settings = self.get_pipeline_settings(conn_sett, table_name, insert_options)

            with self.pipeline_cls_patcher as pipeline_cls, self.driver_patcher as driver_klass:
                pipeline_cls.side_effect = NotConfigured

                self.assertRaises(NotConfigured, RethinkDBPipeline.from_crawler, crawler)

                driver_klass.assert_called_once_with(conn_sett)
                pipeline_cls.assert_called_once_with(driver_klass.return_value, table_name, insert_options)
Example #6
0
    def test_celery(self):
        from pyramid_celery import Celery

        settings = {"CELERY_ALWAYS_EAGER": True}
        registry = Mock()
        registry.settings = settings

        env = {"registry": registry}

        celery = Celery(env)
        new_settings = celery.loader.read_configuration()
        reduced_args = celery.__reduce_args__()

        assert reduced_args[0] == env
        assert settings == new_settings
        assert celery.env == env
    def test_from_crawler_configured(self):
        # asserts that from_crawler will return a pipeline instance if the
        # constructor returns None, as expected

        crawler = Mock()

        comb_iter = self.init_mocks_iter()
        for conn_sett, table_name, insert_options in comb_iter:
            crawler.settings = self.get_pipeline_settings(conn_sett, table_name, insert_options)

            with self.pipeline_cls_patcher as pipeline_cls, self.driver_patcher as driver_klass:
                pipeline_cls.return_value = None

                pipeline = RethinkDBPipeline.from_crawler(crawler)
                self.assertIsInstance(pipeline, RethinkDBPipeline)

                driver_klass.assert_called_once_with(conn_sett)
                pipeline_cls.assert_called_once_with(driver_klass.return_value, table_name, insert_options)
def apprequest(dbsession, _registry):
    from ringo.lib.cache import Cache

    request = testing.DummyRequest()
    request.cache_item_modul = Cache()
    request.cache_item_list = Cache()

    user = Mock()
    user.news = []
    user.settings = {"searches": {"foo": "bar"}}

    request.user = user

    request.accept_language = Mock(return_value="en")
    request.translate = lambda x: x
    request.db = dbsession
    request.context = Mock()
    request.session.get_csrf_token = lambda: "xxx"
    return request
Example #9
0
    def test_celery(self):
        from pyramid_celery import Celery

        settings = {
            "CELERY_ALWAYS_EAGER": "true",
            "CELERYD_CONCURRENCY": "1",
            "BROKER_URL": '"redis:://localhost:6379/0"',
            "BROKER_TRANSPORT_OPTIONS": '{"foo": "bar"}',
            "ADMINS": '(("Foo Bar", "foo@bar"), ("Baz Qux", "baz@qux"))',
            "CELERYD_ETA_SCHEDULER_PRECISION": "0.1",
            "CASSANDRA_SERVERS": '["foo", "bar"]',
            "CELERY_ANNOTATIONS": "[1, 2, 3]",  # any
            "CELERY_ROUTERS": "some.string",  # also any
            "SOME_KEY": "SOME VALUE",
            "CELERY_IMPORTS": '("myapp.tasks", )',
        }

        registry = Mock()
        registry.settings = settings

        env = {"registry": registry}

        celery = Celery(env)
        new_settings = celery.loader.read_configuration()
        reduced_args = celery.__reduce_args__()

        assert reduced_args[0] == env
        assert settings == new_settings
        assert celery.env == env

        # Check conversions
        assert new_settings["CELERY_ALWAYS_EAGER"] == True
        assert new_settings["CELERYD_CONCURRENCY"] == 1
        assert new_settings["ADMINS"] == (("Foo Bar", "foo@bar"), ("Baz Qux", "baz@qux"))
        assert new_settings["BROKER_TRANSPORT_OPTIONS"] == {"foo": "bar"}
        assert new_settings["CELERYD_ETA_SCHEDULER_PRECISION"] > 0.09
        assert new_settings["CELERYD_ETA_SCHEDULER_PRECISION"] < 0.11
        assert new_settings["CASSANDRA_SERVERS"] == ["foo", "bar"]
        assert new_settings["CELERY_ANNOTATIONS"] == [1, 2, 3]
        assert new_settings["CELERY_ROUTERS"] == "some.string"
        assert new_settings["SOME_KEY"] == settings["SOME_KEY"]
        assert new_settings["CELERY_IMPORTS"] == ("myapp.tasks",)
Example #10
0
    def test_celeryd(self, bootstrap, workercommand, celery):
        from pyramid_celery.celeryd import main

        worker = Mock()
        run = Mock()

        worker.run = run
        workercommand.return_value = worker

        settings = {"CELERY_ALWAYS_EAGER": True}
        registry = Mock()
        registry.settings = settings

        env = {"registry": registry}

        bootstrap.return_value = env

        main(["", "config.ini"])

        workercommand.assert_called_with(app=celery(env))
        bootstrap.assert_called_with("config.ini")
        run.assert_called_once_with()
    def test_unconfigured_init(self):
        crawler = Mock()
        crawler.settings = {"LOGENTRIES_TOKEN": None}

        with self.assertRaises(NotConfigured):
            self.extension = LogentriesExtension.from_crawler(crawler)
from mock import Mock

logging.basicConfig(level=10)
logger = logging.getLogger(__name__)

parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(parentdir)
sys.path.append(os.path.join(parentdir, "src"))

logger.debug("parentdir: %s" % parentdir)

from installation_process import InstallationProcess

# set needed config options
settings = dict()
settings["data"] = os.path.join(parentdir, "data")

# create mock object to test just one method and not the __init__
mobject = Mock(InstallationProcess)

mobject.settings = settings
mobject.dest_dir = "/tmp"
mobject.arch = "x86_64"

mobject.write_file = InstallationProcess.write_file.__get__(mobject)

InstallationProcess.create_pacman_conf_file(mobject)

logger.debug("Done")

assert os.path.isfile("/tmp/pacman.conf")