예제 #1
0
    def test_provider_status_http_exceptions(self):
        """Test that the wait method handles HTTP errors.

        Approvial criteria:
            - The wait method shall raise IutNotAvailable on 404 errors.
            - The wait method shall raise RuntimeError on 400 errors.

        Test steps::
            1. For status [400, 404]:
                1.1 Initialize an external provider.
                1.2 Send a status request for a started IUT provider.
                1.3 Verify that the wait method raises the correct exception.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        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",
        })
        self.logger.info("STEP: For status [400, 404]:")
        for status, exception in (
            ("bad_request", RuntimeError),
            ("not_found", IutNotAvailable),
        ):
            with FakeServer(status, {"error": "failure"}) as server:
                ruleset = {
                    "id": "test_provider_status_http_exceptions",
                    "status": {
                        "host": server.host
                    },
                }
                self.logger.info("STEP: Initialize an external provider.")
                provider = Provider(etos, jsontas, ruleset)
                self.logger.info(
                    "STEP: Send a status request for a started IUT provider.")
                with self.assertRaises(exception):
                    self.logger.info(
                        "STEP: Verify that the wait method raises the correct exception."
                    )
                    provider.wait("1")
예제 #2
0
    def test_provider_status_pending(self):
        """Test that the wait method waits on status PENDING.

        Approvial criteria:
            - The wait method shall call the status endpoint, waiting on PENDING.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started IUT provider.
            3. Verify that the wait method waits on PENDING.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 10)
        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",
        })
        responses = [{
            "status": "PENDING"
        }, {
            "status": "PENDING"
        }, {
            "status": "DONE"
        }]
        with FakeServer("ok", responses.copy()) as server:
            ruleset = {
                "id": "test_provider_status_pending",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started IUT provider.")
            provider.wait("1")
            self.logger.info(
                "STEP: Verify that the wait method waits on PENDING.")
            self.assertEqual(server.nbr_of_requests, len(responses))
예제 #3
0
    def test_provider_status_failed(self):
        """Test that the wait method raises IutCheckoutFailed on FAILED status.

        Approvial criteria:
            - The wait method shall raise IutCheckoutFailed on a FAILED status.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started IUT provider.
            3. Verify that the wait method raises IutCheckoutFailed.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        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",
        })
        description = "something failed!"
        with FakeServer("ok", {
                "status": "FAILED",
                "description": description
        }) as server:
            ruleset = {
                "id": "test_provider_status_failed",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started IUT provider.")
            with self.assertRaises(IutCheckoutFailed):
                self.logger.info(
                    "STEP: Verify that the wait method raises IutCheckoutFailed."
                )
                provider.wait("1")
예제 #4
0
    def test_provider_status_timeout(self):
        """Test that the wait method raises TimeoutError when timed out.

        Approvial criteria:
            - The wait method shall raise TimeoutError when timed out.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request that times out.
            3. Verify that the wait method raises TimeoutError.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        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",
        })
        with FakeServer("internal_server_error", {}) as server:
            ruleset = {
                "id": "test_provider_status_timeout",
                "status": {
                    "host": server.host
                },
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info("STEP: Send a status request that times out.")
            with self.assertRaises(TimeoutError):
                self.logger.info(
                    "STEP: Verify that the wait method raises TimeoutError.")
                provider.wait("1")
예제 #5
0
    def test_provider_status(self):
        """Test that the wait method waits for status DONE and exits with response.

        Approvial criteria:
            - The wait method shall call the status endpoint and return on DONE.

        Test steps::
            1. Initialize an external provider.
            2. Send a status request for a started IUT provider.
            3. Verify that the wait method returns response on DONE.
        """
        etos = ETOS("testing_etos", "testing_etos", "testing_etos")
        etos.config.set("WAIT_FOR_IUT_TIMEOUT", 1)
        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",
        })
        test_id = "123"
        with FakeServer("ok", {
                "status": "DONE",
                "test_id": test_id
        }) as server:
            ruleset = {
                "id": "test_provider_status",
                "status": {
                    "host": server.host
                }
            }
            self.logger.info("STEP: Initialize an external provider.")
            provider = Provider(etos, jsontas, ruleset)
            self.logger.info(
                "STEP: Send a status request for a started IUT provider.")
            response = provider.wait("1")
            self.logger.info(
                "STEP: Verify that the wait method return response on DONE.")
            self.assertEqual(response.get("test_id"), test_id)