示例#1
0
    def test_add_domains(self):
        s = Stockton("add-domains")

        # a file with different domains
        proxy_domains = testdata.create_files({
            "foo2.com.txt": [
                "[email protected]                [email protected]",
                "[email protected]                [email protected]",
                "",
            ],
        })
        with self.assertRaises(RuntimeError):
            r = s.run("--proxy-domains={}".format(proxy_domains))

        # 2 files with the same domain
        proxy_domains = testdata.create_files({
            "foo2.com.txt": [
                "[email protected]                [email protected]",
                "",
            ],
            "bar2.com": [
                "[email protected]                [email protected]",
                "",
            ],
        })
        with self.assertRaises(RuntimeError):
            r = s.run("--proxy-domains={}".format(proxy_domains))

        proxy_domains = testdata.create_files({
            "foo.com.txt": [
                "[email protected]                [email protected]",
                "[email protected]                [email protected]",
                "[email protected]              [email protected]",
                "",
            ],
            "bar.com": [
                "[email protected]                [email protected]",
                "[email protected]                [email protected]",
                "[email protected]              [email protected]",
                "",
            ],
            "che.org.txt": [
                "@che.org                   [email protected]",
                "",
            ],
        })

        r = s.run("--proxy-domains={} --smtp-password=1234".format(proxy_domains))
        self.assertTrue("Adding domain foo.com" in r)
        self.assertTrue("Adding domain bar.com" in r)
        self.assertTrue("Adding domain che.org" in r)
示例#2
0
    def test_copy_into(self):
        # directory into directory
        source_d = testdata.create_files({
            "foo.txt": testdata.get_words(),
            "bar/che.txt": testdata.get_words(),
        })
        d = testdata.create_dir()
        d.copy_into(source_d)
        self.assertTrue("foo.txt" in d)
        self.assertTrue("bar/che.txt" in d)

        source_f = testdata.create_file("foo.txt", testdata.get_words())

        # file into directory
        d = testdata.create_dir()
        d.copy_into(source_f)
        self.assertTrue(source_f.basename in d)
        dest_f = d.get_file(source_f.basename)
        self.assertEqual(source_f.contents(), dest_f.contents())

        # file into file
        dest_f = testdata.create_file("foo.txt", testdata.get_words())
        self.assertNotEqual(source_f.contents(), dest_f.contents())
        dest_f.copy_into(source_f)
        self.assertEqual(source_f.contents(), dest_f.contents())
        self.assertTrue(source_f.contents() in dest_f.contents())
示例#3
0
文件: __init__.py 项目: Jaymon/bang
    def get_dirs(cls, input_files):
        # TODO -- switch these to use the skeleton templates
        d = {
            'template/aux.html': "{{ aux.title }}\n{{ aux.html }}\n",
            'template/post.html': "{{ post.title }}\n{{ post.html }}\n{{ post.modified.strftime('%Y-%m-%d') }}\n",
            'template/posts.html': "\n".join([
                "{% for post in posts %}",
                "{% include 'post.html' %}",
                "<hr>",
                "{% endfor %}",
                "",
            ])
        }
        d.update(input_files)

        output_dir = Directory(testdata.create_dir())
        project_dir = Directory(testdata.create_dir())

        testdata.create_files(d, tmpdir=str(project_dir))
        return project_dir, output_dir
示例#4
0
    def test_add_domain_proxy_file_no_smtp(self):

        # to make sure this works completely, we completely remove postfix
        p = Postfix()
        p.reset()

        s = Stockton("add-domain")
        proxy_domains = testdata.create_files({
            "foo.com": "\n".join([
                "[email protected]                [email protected]",
                "[email protected]                [email protected]",
                "[email protected]              [email protected]",
                "",
            ]),
            "bar.com": "\n".join([
                "[email protected]                [email protected]",
                "[email protected]                [email protected]",
                "[email protected]              [email protected]",
                "",
            ]),
        })

        for f in proxy_domains:
            r = s.run("{} --proxy-file={}".format(f.name, f))

        contents = "\n".join([
            "@foo.com                   [email protected]",
            "",
        ])
        f = testdata.create_file("foo.com", contents)

        r = s.run("{} --proxy-file={}".format(f.name, f))
        foo = Filepath("/etc/postfix/virtual/addresses/foo.com")
        self.assertEqual(contents, foo.contents())

        # Let's check structure because I was having a lot of problems with getting
        # the structure...

        # domains file should have 2 domains in it
        domains_f = Filepath("/etc/postfix/virtual/domains")
        self.assertEqual(2, domains_f.lc())
        self.assertTrue(domains_f.contains("^foo\.com$"))

        m = Main(prototype_path=Main.dest_path)
        # we can't guarrantee foo, bar order so we match one line at a time
        self.assertTrue(re.search("^hash:[/a-z]+?(bar|foo)\.com,", m["virtual_alias_maps"].val, re.M))
        self.assertTrue(re.search("^\s+hash:[/a-z]+?(bar|foo)\.com$", m["virtual_alias_maps"].val, re.M))
示例#5
0
    def test_copy_to(self):
        """https://github.com/Jaymon/testdata/issues/30"""
        source_d = testdata.create_files({
            "foo.txt": testdata.get_words(),
            "bar/che.txt": testdata.get_words(),
        })
        dest_d = testdata.create_dir()

        source_d.copy_to(dest_d)
        self.assertTrue("foo.txt" in dest_d)
        self.assertTrue("bar/che.txt" in dest_d)

        source_f = testdata.create_file("foo.txt", testdata.get_words())
        dest_f = testdata.get_file()
        self.assertFalse(dest_f.exists())
        source_f.copy_to(dest_f)
        self.assertEqual(source_f.contents(), dest_f.contents())
示例#6
0
    def test_install_proxy_domains(self):
        s = Stockton("install")
        proxy_domains = testdata.create_files({
            "pd1.com.txt": [
                "[email protected]                [email protected]",
                "",
            ],
            "pd2.com": [
                "[email protected]                [email protected]",
                "",
            ],
        })

        r = s.run("--mailserver={} --proxy-domains={} --smtp-password=1234".format(
            "mail.example.com",
            proxy_domains
        ))
示例#7
0
    def __init__(self, files, port=8765):
        base_path = testdata.create_files(files)
        self.hostname = "http://127.0.0.1:{}".format(port)

        httpd = HTTPServer(base_path, ("", port), WebHandler)
        self.httpd = httpd

        # TODO -- move all this to start() method
        def target():
            try:
                httpd.serve_forever()
            except Exception as e:
                raise

        th = testdata.Thread(target=target)
        th.daemon = True
        th.start()
        self.thread = th
示例#8
0
    def test_create_files(self):
        ts = {
            "foo/1.txt": testdata.get_words(),
            "foo/2.txt": testdata.get_words(),
            "/bar/3.txt": testdata.get_words(),
            "/bar/che/4.txt": testdata.get_words(),
        }

        path = testdata.create_files(ts)
        self.assertEqual(list(path.files()), list(path))

        count = 0
        for f in path:
            for rp, v in ts.items():
                if rp in f:
                    count += 1
                    self.assertEqual(v, f.contents())

        self.assertLess(0, count)