Beispiel #1
0
    def test_raise_from_erroneous_request(self):
        err_req = requests.Request()
        err_req.status_code = 401
        err_req.json = mock.MagicMock(return_value={"error": "ThisIsAnException", "errorMessage": "Went wrong."})

        with self.assertRaises(YggdrasilError) as e:
            _raise_from_request(err_req)
            self.assertEqual(e, "[401]) ThisIsAnException: Went Wrong.")
    def test_raise_from_erroneous_request_without_error(self):
        err_req = requests.Request()
        err_req.status_code = 401
        err_req.json = mock.MagicMock(return_value={"goldfish": "are pretty."})

        with self.assertRaises(YggdrasilError) as e:
            _raise_from_request(err_req)

            self.assertEqual(e, "Malformed error message.")
Beispiel #3
0
    def test_raise_from_erroneous_request_without_error(self):
        err_req = requests.Request()
        err_req.status_code = 401
        err_req.json = mock.MagicMock(return_value={"goldfish": "are pretty."})

        with self.assertRaises(YggdrasilError) as e:
            _raise_from_request(err_req)

            self.assertEqual(e, "Malformed error message.")
Beispiel #4
0
    def test_raise_invalid_json(self):
        err_req = requests.Request()
        err_req.status_code = 401
        err_req.json = mock.MagicMock(
            side_effect=ValueError("no json could be decoded")
        )

        with self.assertRaises(YggdrasilError) as e:
            _raise_from_request(err_req)
            self.assertTrue("Unknown requests error" in e)
Beispiel #5
0
    def test_raise_from_erroneous_request(self):
        err_req = requests.Request()
        err_req.status_code = 401
        err_req.json = mock.MagicMock(
            return_value={"error": "ThisIsAnException",
                          "errorMessage": "Went wrong."})

        with self.assertRaises(YggdrasilError) as e:
            _raise_from_request(err_req)
            self.assertEqual(e, "[401]) ThisIsAnException: Went Wrong.")
    def test_raise_from_healthy_request(self):
        req = requests.Request()
        req.status_code = 200
        req.json = mock.MagicMock(return_value={"vegetables": "are healthy."})

        self.assertIs(_raise_from_request(req), None)
Beispiel #7
0
    def test_raise_from_healthy_request(self):
        req = requests.Request()
        req.status_code = 200
        req.json = mock.MagicMock(return_value={"vegetables": "are healthy."})

        self.assertIs(_raise_from_request(req), None)