Exemplo n.º 1
0
    def test_configimport_script(self, mock_open):
        from toddler.decorators import _reset_already_run
        from toddler import setup
        _reset_already_run(setup)
        argv = ['--config', 'test.xml', "--type", "crawl", "--mongo-url",
                "mongodb://localhost/test"]

        import io
        def fopen(*args, **kwargs):
            return io.StringIO(self.example_xml)

        mock_open.side_effect = fopen

        from toddler.tools.configimport import main
        from toddler.models import Host

        main(*argv)

        host = Host.objects(host="www.lesiteimmo.com").first()
        """:type: Host"""
        self.assertEqual(host.host, "www.lesiteimmo.com")
        self.assertGreater(len(host.config['crawlConfig']), 0)

        self.pattern_asserts(host.config['crawlConfig'])
Exemplo n.º 2
0
    def test_setup(self):

        with tempfile.NamedTemporaryFile("w", suffix=".yaml", delete=False)\
                as tmp_file:

            tmp_file.write("test: 123")
            tmp_file.close()
            argv = ['-c', '{}'.format(tmp_file.name)]
            decorators._reset_already_run(setup)
            setup(argv)

            self.assertEqual(config.config.test, 123)
            os.unlink(tmp_file.name)

            self.assertRaises(SystemError, setup, argv)
            self.assertTrue(decorators.has_been_run(setup))

        config.config = Dict()

        decorators._reset_already_run(setup)

        # reset the already run
        with tempfile.NamedTemporaryFile("w", suffix=".json", delete=False) \
                as tmp_file:

            tmp_file.write('{"test": 123}')
            tmp_file.close()
            argv = ['-c', tmp_file.name]

            setup(argv)

            self.assertEqual(config.config.test, 123)

            os.unlink(tmp_file.name)

        decorators._reset_already_run(setup)

        argv = ['-m', "mongodb://localhost"]

        with mock.patch("toddler.models.connect") as connect:

            def mock_connect(host=None):
                self.assertEqual(host, "mongodb://localhost")
            connect.side_effect = mock_connect
            setup(argv)

            self.assertTrue(connect.called)
Exemplo n.º 3
0
    def tearDown(self):

        decorators._reset_already_run(setup)
Exemplo n.º 4
0
    def tearDown(self):

        _reset_already_run(setup)
Exemplo n.º 5
0
    def setUp(self):

        _reset_already_run(setup)

        setup(['-m', 'mongodb://localhost/aladdin'])