예제 #1
0
 def setup_method(self):
     utils.import_settings(True, boot_module="tests.testing_boot")
     self.ip = "127.0.0.1"
     utils.settings.data["receiver"]["listenhost"] = self.ip
     self.fake_mail_request = MailRequest("", None, None, "")
     self.fake_eml_file = "{ip}-salmon-user".format(ip=self.ip)
     self.file1 = "./rawspams/{}".format(self.eml_file1)
예제 #2
0
    def test_forward(self):
        utils.import_settings(False)

        import salmon.handlers.forward  # noqa
        salmon.handlers.forward.settings.relay = Mock()
        Router.deliver(create_message())

        self.assertEqual(salmon.handlers.forward.settings.relay.deliver.call_count, 1)
예제 #3
0
def prepare_testing_env():
    Path("./queue").mkdir(parents=True, exist_ok=True)
    Path("./queue/new").mkdir(parents=True, exist_ok=True)
    Path("./undeliverable").mkdir(parents=True, exist_ok=True)
    Path("./attachments").mkdir(parents=True, exist_ok=True)
    settings1 = Settings(username="******", password="******")
    push_into_db(settings1)
    utils.import_settings(True, boot_module="testing_boot")
예제 #4
0
def test_forward(smtp_mock):
    smtp_mock.return_value = Mock()

    utils.import_settings(False)

    import salmon.handlers.forward  # noqa
    Router.deliver(create_message())

    assert_equal(smtp_mock.return_value.sendmail.call_count, 1)
    assert_equal(smtp_mock.return_value.quit.call_count, 1)
예제 #5
0
def test_forward(smtp_mock):
    smtp_mock.return_value = Mock()

    utils.import_settings(False)

    import salmon.handlers.forward  # noqa
    Router.deliver(create_message())

    assert smtp_mock.return_value.sendmail.called
    assert smtp_mock.return_value.quit.called
예제 #6
0
    def test_import_settings(self):
        assert utils.settings is None

        settings = utils.import_settings(True, boot_module='config.testing')
        assert settings
        assert settings.receiver_config
        self.assertEqual(settings, utils.settings)

        with patch("salmon.utils.importlib.import_module") as import_mock:
            # just import settings module
            self.clear_settings()
            utils.import_settings(False)
            self.assertEqual(import_mock.call_count, 1)

            # import settings and boot
            self.clear_settings()
            import_mock.reset_mock()
            utils.import_settings(True)
            self.assertEqual(import_mock.call_count, 2)

            # settings has already been imported, return early
            import_mock.reset_mock()
            utils.import_settings(False)
            self.assertEqual(import_mock.call_count, 0)

            # boot module doesn't get cached on the module, so it import_module should be called
            import_mock.reset_mock()
            utils.import_settings(True)
            self.assertEqual(import_mock.call_count, 1)
예제 #7
0
def test_import_settings():
    assert utils.settings is None

    settings = utils.import_settings(True, boot_module='config.testing')
    assert settings
    assert settings.receiver_config
    assert settings == utils.settings

    with patch("salmon.utils.importlib.import_module") as import_mock:
        # just import settings module
        clear_settings()
        utils.import_settings(False)
        assert import_mock.call_count == 1, import_mock.call_count

        # import settings and boot
        clear_settings()
        import_mock.reset_mock()
        utils.import_settings(True)
        assert import_mock.call_count == 2, import_mock.call_count

        # settings has already been imported, return early
        import_mock.reset_mock()
        utils.import_settings(False)
        assert import_mock.call_count == 0, import_mock.call_count

        # boot module doesn't get cached on the module, so it import_module should be called
        import_mock.reset_mock()
        utils.import_settings(True)
        assert import_mock.call_count == 1, import_mock.call_count
예제 #8
0
def test_import_settings():
    assert utils.settings is None

    settings = utils.import_settings(True, boot_module='config.testing')
    assert settings
    assert settings.receiver_config
    assert settings == utils.settings

    with patch("salmon.utils.importlib.import_module") as import_mock:
        # just import settings module
        clear_settings()
        utils.import_settings(False)
        assert import_mock.call_count == 1, import_mock.call_count

        # import settings and boot
        clear_settings()
        import_mock.reset_mock()
        utils.import_settings(True)
        assert import_mock.call_count == 2, import_mock.call_count

        # settings has already been imported, return early
        import_mock.reset_mock()
        utils.import_settings(False)
        assert import_mock.call_count == 0, import_mock.call_count

        # boot module doesn't get cached on the module, so it import_module should be called
        import_mock.reset_mock()
        utils.import_settings(True)
        assert import_mock.call_count == 1, import_mock.call_count
예제 #9
0
def test_import_settings():
    loader = view.LOADER

    settings = utils.import_settings(True, from_dir="tests", boot_module="config.testing")
    assert settings
    assert settings.receiver_config

    view.LOADER = loader
    settings = utils.import_settings(False, from_dir="examples/osb")
    assert settings
    assert settings.receiver_config
예제 #10
0
def test_import_settings():
    loader = view.LOADER

    settings = utils.import_settings(True,
                                     from_dir='tests',
                                     boot_module='config.testing')
    assert settings
    assert settings.receiver_config

    view.LOADER = loader
    settings = utils.import_settings(False, from_dir='examples/osb')
    assert settings
    assert settings.receiver_config
예제 #11
0
def routes(modules, test, path):
    """
    Prints out valuable information about an application's routing configuration
    after everything is loaded and ready to go.  Helps debug problems with
    messages not getting to your handlers.  Path has the search paths you want
    separated by a ':' character, and it's added to the sys.path.

    MODULE should be a configureation module and can be given multiple times.
    """
    sys.path += path.split(':')
    test_case_matches = []

    utils.import_settings(False)

    for module in modules:
        try:
            import_module(module)
        except ImportError:
            raise click.ClickException("Module '%s' could not be imported. Did you forget to use the --path option?"
                                       % str(module))

    if not routing.Router.REGISTERED:
        raise click.ClickException("Modules '%s' imported, but no function registered." % str(modules))

    click.echo("Routing ORDER: %s" % routing.Router.ORDER)
    click.echo("Routing TABLE:\n---")
    for format in routing.Router.REGISTERED:
        click.echo("%r: " % str(format), nl=False)
        regex, functions = routing.Router.REGISTERED[format]
        for func in functions:
            click.echo("%s.%s " % (func.__module__, func.__name__), nl=False)
            if test:
                match = regex.match(test)
                if match:
                    test_case_matches.append((str(format), func, match))

        click.echo("\n---")

    if test_case_matches:
        click.echo("\nTEST address %r matches:" % str(test))
        for format, func, match in test_case_matches:
            click.echo("  %r %s.%s" % (format, func.__module__, func.__name__))
            click.echo("  -  %r" % ({str(k): str(v) for k, v in match.groupdict().items()}))
    elif test:
        click.echo("\nTEST address %r didn't match anything." % str(test))
        # don't raise a ClickException because that prepends "ERROR" to the
        # output and this isn't always an error
        sys.exit(1)
예제 #12
0
def start(pid, force, chdir, boot, chroot, uid, gid, umask, debug, daemon):
    """
    Runs a salmon server out of the current directory
    """
    utils.start_server(pid, force, chroot, chdir, uid, gid, umask,
                       lambda: utils.import_settings(True, boot_module=boot),
                       debug, daemon)
예제 #13
0
def _import_router_modules(modules, path):
    sys.path += path.split(':')

    utils.import_settings(False)

    for module in modules:
        try:
            import_module(module)
        except ImportError:
            raise click.ClickException(
                "Module '%s' could not be imported. Did you forget to use the --path option?"
                % str(module))

    if not routing.Router.REGISTERED:
        raise click.ClickException(
            "Modules '%s' imported, but no function registered." %
            str(modules))
예제 #14
0
def start_command(pid='./run/smtp.pid', FORCE=False, chroot=False, chdir=".",
                  boot="config.boot", uid=False, gid=False, umask=False, debug=False):
    """
    Runs a salmon server out of the current directory:

    salmon start -pid ./run/smtp.pid -FORCE False -chroot False -chdir "." \\
            -umask False -uid False -gid False -boot config.boot
    """
    loader = lambda: utils.import_settings(True, from_dir=os.getcwd(), boot_module=boot)
    utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader, debug)
예제 #15
0
 def command(pid,
             force,
             chdir,
             boot,
             chroot=False,
             uid=False,
             gid=False,
             umask=False,
             debug=False,
             daemon=True):
     loader = lambda: utils.import_settings(True, boot_module=boot)
     utils.start_server(pid, force, chroot, chdir, uid, gid, umask, loader,
                        debug, daemon)
예제 #16
0
def start_command(pid='./run/smtp.pid',
                  FORCE=False,
                  chroot=False,
                  chdir=".",
                  boot="config.boot",
                  uid=False,
                  gid=False,
                  umask=False,
                  debug=False):
    """
    Runs a salmon server out of the current directory:

    salmon start -pid ./run/smtp.pid -FORCE False -chroot False -chdir "." \\
            -umask False -uid False -gid False -boot config.boot
    """
    loader = lambda: utils.import_settings(
        True, from_dir=os.getcwd(), boot_module=boot)
    utils.start_server(pid, FORCE, chroot, chdir, uid, gid, umask, loader,
                       debug)
예제 #17
0
 def setup_class(cls):
     Path("./queue").mkdir(parents=True, exist_ok=True)
     Path("./queue/new").mkdir(parents=True, exist_ok=True)
     Path("./undeliverable").mkdir(parents=True, exist_ok=True)
     Path("./attachments").mkdir(parents=True, exist_ok=True)
     utils.import_settings(True, boot_module="tests.testing_boot")
예제 #18
0
def test_import_settings():
    settings = utils.import_settings(True,
                                     from_dir='tests',
                                     boot_module='config.testing')
    assert settings
    assert settings.receiver_config
예제 #19
0
파일: commands.py 프로젝트: DrDub/salmon
 def command(pid, force, chdir, boot, chroot=False, uid=False, gid=False, umask=False, debug=False, daemon=True):
     loader = lambda: utils.import_settings(True, from_dir=os.getcwd(), boot_module=boot)
     utils.start_server(pid, force, chroot, chdir, uid, gid, umask, loader, debug, daemon)
예제 #20
0
파일: utils_tests.py 프로젝트: DrDub/salmon
def test_import_settings():
    settings = utils.import_settings(True, from_dir='tests', boot_module='config.testing')
    assert settings
    assert settings.receiver_config
예제 #21
0
 def command(pid, force, chdir, boot, chroot=False, uid=False, gid=False, umask=False, debug=False, daemon=True):
     utils.start_server(pid, force, chroot, chdir, uid, gid, umask,
                        lambda: utils.import_settings(True, boot_module=boot), debug, daemon)