From a080de4b31553e9c180f32eb47c31a4d00155d86 Mon Sep 17 00:00:00 2001
From: Kurtis Massey <55586356+kurtismassey@users.noreply.github.com>
Date: Tue, 21 May 2024 23:23:37 +0100
Subject: [PATCH] More tests

---
 tests/unit/encoders/test_bedrock.py | 39 +++++++++++++++++++++++++++++
 1 file changed, 39 insertions(+)

diff --git a/tests/unit/encoders/test_bedrock.py b/tests/unit/encoders/test_bedrock.py
index 1a9cf835..619325ed 100644
--- a/tests/unit/encoders/test_bedrock.py
+++ b/tests/unit/encoders/test_bedrock.py
@@ -86,6 +86,22 @@ class TestBedrockEncoder:
             bedrock_encoder.access_key_id == "env_id"
         ), "Access key ID not set correctly from environment variable"
 
+    def test_missing_access_key_id(self, mocker):
+        mocker.patch(
+            "semantic_router.encoders.bedrock.BedrockEncoder._initialize_client"
+        )
+
+        with pytest.raises(ValueError):
+            BedrockEncoder(access_key_id=None, secret_access_key="fake_secret")
+
+    def test_missing_secret_access_key(self, mocker):
+        mocker.patch(
+            "semantic_router.encoders.bedrock.BedrockEncoder._initialize_client"
+        )
+
+        with pytest.raises(ValueError):
+            BedrockEncoder(access_key_id="fake_id", secret_access_key=None)
+
     def test_initialisation_missing_env_variables(self, mocker):
         mocker.patch.dict(os.environ, {}, clear=True)
         with pytest.raises(ValueError):
@@ -96,6 +112,17 @@ class TestBedrockEncoder:
                 region=None,
             )
 
+    def test_failed_client_initialisation(self, mocker):
+        mocker.patch.dict(os.environ, clear=True)
+
+        mocker.patch(
+            "semantic_router.encoders.bedrock.BedrockEncoder._initialize_client",
+            side_effect=Exception("Initialization failed"),
+        )
+
+        with pytest.raises(ValueError):
+            BedrockEncoder(access_key_id="fake_id", secret_access_key="fake_secret")
+
     def test_call_method(self, bedrock_encoder):
         response_content = json.dumps({"embedding": [0.1, 0.2, 0.3]})
         response_body = BytesIO(response_content.encode("utf-8"))
@@ -182,6 +209,18 @@ class TestBedrockEncoder:
         with pytest.raises(ValueError):
             BedrockEncoder.get_env_variable("MISSING_VAR", None)
 
+    def test_uninitialised_client(self, bedrock_encoder):
+        bedrock_encoder.client = None
+
+        with pytest.raises(ValueError):
+            bedrock_encoder(["test"])
+
+    def test_missing_env_variables(self, mocker):
+        mocker.patch.dict(os.environ, clear=True)
+
+        with pytest.raises(ValueError):
+            BedrockEncoder()
+
 
 class TestBedrockEncoderWithCohere:
     def test_cohere_embedding_single_chunk(self, bedrock_encoder_with_cohere):
-- 
GitLab