def test_bad_load(self):
     import aplt.runner as runner
     runner.run_scenario({
         "WEBSOCKET_URL": AUTOPUSH_SERVER,
         "SCENARIO_FUNCTION": "aplt.scenaribasic",
         "SCENARIO_ARGS": "",
     }, run=False)
Exemple #2
0
 def test_bad_load(self):
     import aplt.runner as runner
     runner.run_scenario([
         "--log_output=none",
         "--websocket_url={}".format(AUTOPUSH_SERVER),
         "aplt.scenaribasic",
     ], run=False)
    def test_basic_with_vapid_str_args(self):
        """Test common format for command line arguments

        Command line tests should escape commas in the keyword args,
        e.g.

        ```
        ARGS='{"vapid_private_key":"MHc..."\\,"vapid_claims":{...}}'
        aplt_testplan $HOST "aplt.scenarios:basic,1,1,0,$ARGS"
        ```

        """
        import aplt.runner as runner
        from aplt.tests.test_vapid import T_PRIVATE
        claims = {"aud": "https://example.com",
                  "sub": "mailto:[email protected]",
                  "exp": int(time.time()) + 86400}
        args = {"vapid_private_key": T_PRIVATE,
                "vapid_claims": claims}
        jclaims = json.dumps(args).replace(",", "\\,")
        h = runner.run_scenario({
            "WEBSOCKET_URL": AUTOPUSH_SERVER,
            "SCENARIO_FUNCTION": "aplt.scenarios:basic",
            "SCENARIO_ARGS": [jclaims],
        }, run=False)
        d = Deferred()
        reactor.callLater(0, self._check_testplan_done, h, d)
        return d
Exemple #4
0
    def test_basic_topic_runner(self):
        """Test the "basic with topic" scenario.

        This can be called via pytest using
        `bin/pytest aplt/tests/__init__.py::TestIntegration::test_basic_runner`

        Use `check_log` to examine the produced log file for whatever values
        you need.

        """  # pragma noqa
        import aplt.runner as runner
        h = runner.run_scenario([
            "--log_format=json",
            "--log_output=buffer",  # send the output to a string buffer
            "--websocket_url={}".format(AUTOPUSH_SERVER),
            "aplt.scenarios:basic_topic",
        ], run=False)

        def check_log(success):
            """Check the captured output log for whatever content your
            looking for

            """
            dump = h.logging.dump()
            assert len(dump) > 0
            # Additional checks here...

        d = Deferred()
        reactor.callLater(0, self._check_testplan_done, h, d)
        d.addCallback(check_log)
        return d
Exemple #5
0
    def test_basic_with_vapid_str_args(self):
        """Test common format for command line arguments

        Command line tests should escape commas in the keyword args,
        e.g.

        ```
        ARGS='{"vapid_private_key":"MHc..."\\,"vapid_claims":{...}}'
        aplt_testplan $HOST "aplt.scenarios:basic,1,1,0,$ARGS"
        ```

        """
        import aplt.runner as runner
        claims = {"aud": "https://example.com",
                  "sub": "mailto:[email protected]",
                  "exp": int(time.time()) + 86400}
        args = {"vapid_private_key": T_PRIVATE,
                "vapid_claims": claims}
        jclaims = json.dumps(args).replace(",", "\\,")
        h = runner.run_scenario([
            "--log_output=none",
            "--websocket_url={}".format(AUTOPUSH_SERVER),
            "aplt.scenarios:basic",
            jclaims,
        ], run=False)
        d = Deferred()
        reactor.callLater(0, self._check_testplan_done, h, d)
        return d
Exemple #6
0
 def test_spawn_testplan(self):
     import aplt.runner as runner
     h = runner.run_scenario([
         "--websocket_url={}".format(AUTOPUSH_SERVER),
         "aplt.scenarios:_test_spawn",
     ], run=False)
     d = Deferred()
     reactor.callLater(3, self._check_testplan_done, h, d)
     return d
 def test_basic_runner(self):
     import aplt.runner as runner
     h = runner.run_scenario({
         "WEBSOCKET_URL": AUTOPUSH_SERVER,
         "SCENARIO_FUNCTION": "aplt.scenarios:basic",
         "SCENARIO_ARGS": [],
     }, run=False)
     d = Deferred()
     reactor.callLater(0, self._check_testplan_done, h, d)
     return d
Exemple #8
0
 def test_expect_notifications(self):
     import aplt.runner as runner
     h = runner.run_scenario([
         "aplt.scenarios:_expect_notifications",
         AUTOPUSH_SERVER,
         "--log_output=none",
     ], run=False)
     d = Deferred()
     reactor.callLater(0, self._check_testplan_done, h, d)
     return d
Exemple #9
0
 def test_notification_forever(self):
     import aplt.runner as runner
     h = runner.run_scenario([
         "--log_output=none",
         "--websocket_url={}".format(AUTOPUSH_SERVER),
         "aplt.scenarios:notification_forever",
         '0', '1',
     ], run=False)
     d = Deferred()
     reactor.callLater(0, self._check_testplan_done, h, d)
     return d
Exemple #10
0
 def test_basic_with_vapid(self):
     import aplt.runner as runner
     h = runner.run_scenario([
         "--log_output=none",
         "--websocket_url={}".format(AUTOPUSH_SERVER),
         "aplt.scenarios:basic",
         """vapid_claims={"sub": "mailto:[email protected]"}""",
     ], run=False)
     d = Deferred()
     reactor.callLater(0, self._check_testplan_done, h, d)
     return d
Exemple #11
0
    def test_reconnect_forever(self):
        import aplt.runner as runner

        h = runner.run_scenario([
            "--log_output=none",
            "--websocket_url={}".format(AUTOPUSH_SERVER),
            "aplt.scenarios:reconnect_forever",
            '0', '1',  # args are broken into a list by parser.
        ], run=False)
        d = Deferred()
        reactor.callLater(0, self._check_testplan_done, h, d)
        return d
 def test_basic_with_vapid(self):
     import aplt.runner as runner
     from aplt.tests.test_vapid import T_PRIVATE
     claims = {"aud": "https://example.com",
               "sub": "mailto:[email protected]",
               "exp": int(time.time()) + 86400}
     h = runner.run_scenario({
         "WEBSOCKET_URL": AUTOPUSH_SERVER,
         "SCENARIO_FUNCTION": "aplt.scenarios:basic",
         "SCENARIO_ARGS": [{"vapid_private_key": T_PRIVATE,
                            "vapid_claims": claims}],
     }, run=False)
     d = Deferred()
     reactor.callLater(0, self._check_testplan_done, h, d)
     return d
    def test_exception_restart(self):
        import aplt.runner as runner
        import aplt.scenarios as scenarios
        scenarios._RESTARTS = 0
        h = runner.run_scenario({
            "WEBSOCKET_URL": AUTOPUSH_SERVER,
            "SCENARIO_FUNCTION": "aplt.scenarios:_explode",
            "SCENARIO_ARGS": [],
        }, run=False)
        f = Deferred()
        d = Deferred()
        eq_(scenarios._RESTARTS, 0)

        def check_restarts(result):
            self.flushLoggedErrors()
            eq_(scenarios._RESTARTS, 3)
            f.callback(True)
        d.addBoth(check_restarts)
        reactor.callLater(0, self._check_testplan_done, h, d)
        return f
Exemple #14
0
    def test_exception_restart(self):
        import aplt.runner as runner
        import aplt.scenarios as scenarios
        # give the client time to finish disconnecting.
        import time
        time.sleep(1)
        scenarios._RESTARTS = 0
        h = runner.run_scenario([
            "--log_output=none",
            "--websocket_url={}".format(AUTOPUSH_SERVER),
            "aplt.scenarios:_explode",
        ], run=False)
        f = Deferred()
        d = Deferred()
        eq_(scenarios._RESTARTS, 0)

        def check_restarts(result):
            self.flushLoggedErrors()
            eq_(scenarios._RESTARTS, 3)
            f.callback(True)
        d.addBoth(check_restarts)
        reactor.callLater(0, self._check_testplan_done, h, d)
        return f