Ejemplo n.º 1
0
    def test_provider_start_timeout(self):
        """Test that the start method raises a TimeoutError.

        Approval criteria:
            - The start method shall raise TimeoutError if the timeout is reached.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request which will never finish.
            3. Verify that the start method raises TimeoutError.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        os.environ["ETOS_DEFAULT_HTTP_TIMEOUT"] = "1"

        with FakeServer("bad_request", {}) as server:
            ruleset = {
                "id": "test_provider_start_timeout",
                "start": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a start request which will never finish.")

            with self.assertRaises(TimeoutError):
                self.logger.info(
                    "STEP: Verify that the start method raises TimeoutError.")
                provider.start(1, 2)
Ejemplo n.º 2
0
    def test_provider_start_http_exception(self):
        """Test that the start method tries again if there's an HTTP error.

        Approval criteria:
            - The start method shall try again on HTTP errors.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request that fails.
            3. Verify that the start method tries again on HTTP errors.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        expected_start_id = "123"

        with FakeServer(["bad_request", "ok"], [{}, {
                "id": expected_start_id
        }]) as server:
            ruleset = {
                "id": "test_provider_start_http_exception",
                "start": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a start request that fails.")
            start_id = provider.start(1, 2)
            self.logger.info(
                "STEP: Verify that the start method tries again on HTTP errors."
            )
            self.assertGreaterEqual(server.nbr_of_requests, 2)
            self.assertEqual(start_id, expected_start_id)
Ejemplo n.º 3
0
    def test_provider_start(self):
        """Test that it is possible to start an external IUT provider.

        Approval criteria:
            - It shall be possible to send start to an external IUT provider.

        Test steps::
            1. Initialize an external provider.
            2. Send a start request.
            3. Verify that the ID from the start request is returned.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        jsontas = JsonTas()
        jsontas.dataset.merge({
            "identity":
            PackageURL.from_string("pkg:testing/etos"),
            "artifact_id":
            "artifactid",
            "artifact_created":
            "artifactcreated",
            "artifact_published":
            "artifactpublished",
            "tercc":
            "tercc",
            "dataset": {},
            "context":
            "context",
        })
        expected_start_id = "123"

        with FakeServer("ok", {"id": expected_start_id}) as server:
            ruleset = {
                "id": "test_provider_start",
                "start": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a start request.")
            start_id = provider.start(1, 2)
            self.logger.info(
                "STEP: Verify that the ID from the start request is returned.")
            self.assertEqual(start_id, expected_start_id)