Пример #1
0
    def test_merge(self):
        obj = Configuration()
        configs = [
            RESOURCES_DIR + "yaml/test.yml",
            RESOURCES_DIR + "json/merge1.json",
            RESOURCES_DIR + "json/merge2.json",
        ]
        obj.load(configs)
        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        with open(fname) as fh:
            ROOT_LOGGER.debug("JSON:\n%s", fh.read())
        jmeter = obj['modules']['jmeter']
        classval = jmeter['class']
        self.assertEquals("bzt.modules.jmeter.JMeterExecutor", classval)
        self.assertEquals("value", obj['key'])
        self.assertEquals(6, len(obj["list-append"]))
        self.assertEquals(2, len(obj["list-replace"]))
        self.assertEquals(2, len(obj["list-replace-notexistent"]))
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertFalse("properties" in jmeter)

        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        checker = Configuration()
        checker.load([fname])
        token = checker["list-complex"][1][0]['token']
        self.assertNotEquals('test', token)
        token_orig = obj["list-complex"][1][0]['token']
        self.assertEquals('test', token_orig)
Пример #2
0
    def test_merge(self):
        obj = Configuration()
        configs = [
            RESOURCES_DIR + "yaml/test.yml",
            RESOURCES_DIR + "json/merge1.json",
            RESOURCES_DIR + "json/merge2.json",
        ]
        obj.load(configs)
        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        with open(fname) as fh:
            ROOT_LOGGER.debug("JSON:\n%s", fh.read())
        jmeter = obj['modules']['jmeter']
        classval = jmeter['class']
        self.assertEquals("bzt.modules.jmeter.JMeterExecutor", classval)
        self.assertEquals("value", obj['key'])
        self.assertEquals(6, len(obj["list-append"]))
        self.assertEquals(2, len(obj["list-replace"]))
        self.assertEquals(2, len(obj["list-replace-notexistent"]))
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertIsInstance(obj["list-complex"][1][0], BetterDict)
        self.assertFalse("properties" in jmeter)

        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        checker = Configuration()
        checker.load([fname])
        token = checker["list-complex"][1][0]['token']
        self.assertNotEquals('test', token)
        token_orig = obj["list-complex"][1][0]['token']
        self.assertEquals('test', token_orig)
    def test_download_404(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(
            TaurusNetworkError,
            lambda: obj.download_file('http://localhost:8000/404', tmpfile))
Пример #4
0
 def test_tabs(self):
     obj = Configuration()
     obj.tab_replacement_spaces = 4
     obj.load([RESOURCES_DIR + "yaml/tabs-issue.yml"])
     fname = temp_file()
     obj.dump(fname, Configuration.YAML)
     self.assertFilesEqual(RESOURCES_DIR + "yaml/tabs-issue-spaces.yml", fname)
Пример #5
0
    def test_decode(self):
        old_string = "Тест.Эхо"
        gen_file_name = temp_file()

        mod_str = old_string + '\n'
        if PY2:
            mod_str = bytearray(mod_str).decode('utf-8')  # convert to utf-8 on py2 for writing...

        with open(gen_file_name, 'wb') as fd:  # use target system encoding for writing
            fd.write(mod_str.encode(self.obj.SYS_ENCODING))  # important on win where it's not 'utf-8'

        try:
            self.configure(gen_file_name)
            self.assertEqual('utf-8', self.obj.cp)
            lines = list(self.obj.get_lines(True))
            self.assertEqual(self.obj.SYS_ENCODING, self.obj.cp)  # on win self.obj.cp must be changed during of
            self.assertEqual(1, len(lines))  # reading (see MockFileReader)
            new_string = lines[0].rstrip()
            if PY2:
                new_string = new_string.encode('utf-8')
            self.assertEqual(old_string, new_string)
        finally:
            if self.obj.fds:
                self.obj.fds.close()

            os.remove(gen_file_name)
Пример #6
0
 def test_tabs(self):
     obj = Configuration()
     obj.tab_replacement_spaces = 4
     obj.load([RESOURCES_DIR + "yaml/tabs-issue.yml"])
     fname = temp_file()
     obj.dump(fname, Configuration.YAML)
     self.assertFilesEqual(RESOURCES_DIR + "yaml/tabs-issue-spaces.yml", fname)
    def test_download_fail(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(
            TaurusNetworkError,
            lambda: obj.download_file('http://non.existent.com/', tmpfile))
Пример #8
0
def local_paths_config():
    """ to fix relative paths """
    dirname = os.path.dirname(__file__)
    fname = temp_file()
    settings = {
        "modules": {
            "jmeter": {
                "path": RESOURCES_DIR + "jmeter/jmeter-loader" + EXE_SUFFIX,
            },
            "grinder": {
                "path": RESOURCES_DIR + "grinder/fake_grinder.jar",
            },
            "gatling": {
                "path": RESOURCES_DIR + "gatling/gatling2" + EXE_SUFFIX,
            },
            "junit": {
                "path": dirname + "/../build/selenium/tools/junit/junit.jar",
                "selenium-server": dirname + "/../build/selenium/selenium-server.jar"
            }
        }
    }
    jstring = json.dumps(settings)
    with open(fname, 'w') as fds:
        fds.write(jstring)
    return fname
Пример #9
0
def local_paths_config():
    """ to fix relative paths """
    dirname = os.path.dirname(__file__)
    fname = temp_file()
    settings = {
        "modules": {
            "jmeter": {
                "path": RESOURCES_DIR + "jmeter/jmeter-loader" + EXE_SUFFIX,
            },
            "grinder": {
                "path": RESOURCES_DIR + "grinder/fake_grinder.jar",
            },
            "gatling": {
                "path": RESOURCES_DIR + "gatling/gatling3" + EXE_SUFFIX,
            },
            "junit": {
                "path":
                dirname + "/../build/selenium/tools/junit/junit.jar",
                "selenium-server":
                dirname + "/../build/selenium/selenium-server.jar"
            }
        }
    }
    jstring = json.dumps(settings)
    with open(fname, 'w') as fds:
        fds.write(jstring)
    return fname
    def test_decode(self):
        old_string = "Тест.Эхо"
        gen_file_name = temp_file()

        mod_str = old_string + '\n'

        with open(gen_file_name,
                  'wb') as fd:  # use target system encoding for writing
            fd.write(mod_str.encode(self.obj.SYS_ENCODING)
                     )  # important on win where it's not 'utf-8'

        try:
            self.configure(gen_file_name)
            self.assertEqual('utf-8', self.obj.cp)
            lines = list(self.obj.get_lines(True))
            self.assertEqual(
                self.obj.SYS_ENCODING,
                self.obj.cp)  # on win self.obj.cp must be changed during of
            self.assertEqual(1, len(lines))  # reading (see MockFileReader)
            new_string = lines[0].rstrip()
            self.assertEqual(old_string, new_string)
        finally:
            if self.obj.fds:
                self.obj.fds.close()

            os.remove(gen_file_name)
Пример #11
0
 def test_save(self):
     obj = Configuration()
     obj.merge({"str": "text", "uc": six.u("ucstring")})
     fname = temp_file()
     obj.dump(fname, Configuration.YAML)
     with open(fname) as fh:
         written = fh.read()
         ROOT_LOGGER.debug("YAML:\n%s", written)
         self.assertNotIn("unicode", written)
Пример #12
0
    def test_load(self):
        obj = Configuration()
        configs = [
            BASE_CONFIG, RESOURCES_DIR + "json/jmx.json",
            RESOURCES_DIR + "json/concurrency.json"
        ]
        obj.load(configs)
        ROOT_LOGGER.debug("config:\n%s", obj)

        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        with open(fname) as fh:
            ROOT_LOGGER.debug("JSON:\n%s", fh.read())

        fname = temp_file()
        obj.dump(fname, Configuration.YAML)
        with open(fname) as fh:
            ROOT_LOGGER.debug("YAML:\n%s", fh.read())
Пример #13
0
    def test_export_clean_jmx(self):
        tmp_jmx_name = temp_file()
        open(tmp_jmx_name, 'w+').close()    # touch file

        self.configure(RESOURCES_DIR + "yaml/converter/disabled.jmx", dump_jmx=tmp_jmx_name)
        self.sniff_log(self.obj.log)
        self.obj.process()
        self.assertIn("Loading jmx file", self.log_recorder.info_buff.getvalue())
        self.assertIn("already exists and will be overwritten", self.log_recorder.warn_buff.getvalue())
Пример #14
0
    def test_load(self):
        obj = Configuration()
        configs = [
            BASE_CONFIG,
            RESOURCES_DIR + "json/jmx.json",
            RESOURCES_DIR + "json/concurrency.json"
        ]
        obj.load(configs)
        ROOT_LOGGER.debug("config:\n%s", obj)

        fname = temp_file()
        obj.dump(fname, Configuration.JSON)
        with open(fname) as fh:
            ROOT_LOGGER.debug("JSON:\n%s", fh.read())

        fname = temp_file()
        obj.dump(fname, Configuration.YAML)
        with open(fname) as fh:
            ROOT_LOGGER.debug("YAML:\n%s", fh.read())
Пример #15
0
 def test_save(self):
     obj = Configuration()
     obj.merge({
         "str": "text",
         "uc": six.u("ucstring")
     })
     fname = temp_file()
     obj.dump(fname, Configuration.YAML)
     with open(fname) as fh:
         written = fh.read()
         ROOT_LOGGER.debug("YAML:\n%s", written)
         self.assertNotIn("unicode", written)
Пример #16
0
    def test_download_file(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        obj.download_file('http://localhost:8000/', tmpfile)

        self.assertTrue(os.path.exists(tmpfile))

        with open(tmpfile) as fds:
            contents = fds.read()

        self.assertGreaterEqual(len(contents), 0)
    def test_download_file(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        obj.download_file('http://localhost:8000/', tmpfile)

        self.assertTrue(os.path.exists(tmpfile))

        with open(tmpfile) as fds:
            contents = fds.read()

        self.assertGreaterEqual(len(contents), 0)
Пример #18
0
    def setUp(self):
        super(TestScenarioBuilder, self).setUp()
        executor = MockJMeterExecutor()
        executor.engine = EngineEmul()
        executor.configure(load={"scenario": "SB"})
        executor.engine.config.merge({"scenarios": {"SB": {}}})
        executor.settings['protocol-handlers'] = {
            'http': HTTPProtocolHandler.__module__ + '.' + HTTPProtocolHandler.__name__
        }

        self.obj = JMeterScenarioBuilder(executor)

        self.jmx = temp_file()
Пример #19
0
    def test_include_controllers(self):
        """ check whether known controller included into unknown one is parsed properly """
        with open(RESOURCES_DIR + "jmeter/jmx/all_controllers.jmx") as f:
            content = f.read()

        # make IfControllers unknown
        content = content.replace("IfController", "FiController", sys.maxsize)

        wrong_jmx = temp_file(suffix=".jmx")
        try:
            with open(wrong_jmx, "a") as _file:
                _file.write(content)

            self.configure(wrong_jmx)
            self.obj.process()
            yml = yaml.full_load(open(self.obj.dst_file).read())
            requests = yml.get("scenarios").get("Thread Group").get("requests")
            self.assertTrue(any(request.get("while") == "${WC}" for request in requests))
        finally:
            if os.path.exists(wrong_jmx):
                os.remove(wrong_jmx)
Пример #20
0
    def test_long_buf(self):
        """ subprocess (tast) became blocked and blocks parent (shellexec)
        if exchange buffer (PIPE) is full because of wait() """
        file_name = temp_file()
        if is_windows():
            task = "type "
            buf_len = 2 ** 10 * 4  # 4K
        else:
            task = "tail "
            buf_len = 2 ** 10 * 64  # 64K
        task += file_name
        buf = '*' * (buf_len + 1)
        with open(file_name, "w+") as _file:
            _file.write(buf)

        self.obj.parameters.merge({"prepare": [task]})
        self.obj.prepare()
        self.obj.startup()
        self.obj.shutdown()
        out = self.log_recorder.debug_buff.getvalue()
        self.assertIn(buf, out)
Пример #21
0
    def test_long_buf(self):
        """ subprocess (tast) became blocked and blocks parent (shellexec)
        if exchange buffer (PIPE) is full because of wait() """
        file_name = temp_file()
        if is_windows():
            task = "type "
            buf_len = 2**10 * 4  # 4K
        else:
            task = "tail "
            buf_len = 2**10 * 64  # 64K
        task += file_name
        buf = '*' * (buf_len + 1)
        with open(file_name, "w+") as _file:
            _file.write(buf)

        self.obj.parameters.merge({"prepare": [task]})
        self.obj.prepare()
        self.obj.startup()
        self.obj.shutdown()
        out = self.log_recorder.debug_buff.getvalue()
        self.assertIn(buf, out)
Пример #22
0
 def test_background_task_output(self):
     temp = temp_file()
     try:
         with open(temp, "at") as temp_f:
             temp_f.write("*" * (2 ** 16 + 1))
         if is_windows():
             cmd = "type"
         else:
             cmd = "cat"
         command1 = "%s %s" % (cmd, temp)
         command2 = "sleep 1"
         task = {"command": command1, "background": True}
         blocking_task = {"command": command2, "background": False}
         self.obj.parameters.merge({"prepare": [task, blocking_task]})
         self.obj.prepare()
         self.obj.check()
         self.obj.shutdown()
         out = self.log_recorder.debug_buff.getvalue()
         self.assertIn("code 0: %s" % command1, out)
         self.assertIn("code 0: %s" % command2, out)
     finally:
         os.remove(temp)
Пример #23
0
 def test_background_task_output(self):
     temp = temp_file()
     try:
         with open(temp, "at") as temp_f:
             temp_f.write("*" * (2**16 + 1))
         if is_windows():
             cmd = "type"
         else:
             cmd = "cat"
         command1 = "%s %s" % (cmd, temp)
         command2 = "sleep 1"
         task = {"command": command1, "background": True}
         blocking_task = {"command": command2, "background": False}
         self.obj.parameters.merge({"prepare": [task, blocking_task]})
         self.obj.prepare()
         self.obj.check()
         self.obj.shutdown()
         out = self.log_recorder.debug_buff.getvalue()
         self.assertIn("code 0: %s" % command1, out)
         self.assertIn("code 0: %s" % command2, out)
     finally:
         os.remove(temp)
 def dump_config(self):
     """ test """
     fname = temp_file()
     self.config.dump(fname, Configuration.JSON)
     with open(fname) as fh:
         ROOT_LOGGER.debug("JSON:\n%s", fh.read())
Пример #25
0
 def dump_config(self):
     """ test """
     fname = temp_file()
     self.config.dump(fname, Configuration.JSON)
     with open(fname) as fh:
         ROOT_LOGGER.debug("JSON:\n%s", fh.read())
Пример #26
0
    def test_download_404(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(TaurusNetworkError, lambda: obj.download_file('http://localhost:8000/404', tmpfile))
Пример #27
0
    def test_download_fail(self):
        obj = HTTPClient()
        tmpfile = temp_file()

        self.assertRaises(TaurusNetworkError, lambda: obj.download_file('http://non.existent.com/', tmpfile))