diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index c4e8f090bd..5d41671f2a 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -23,14 +23,12 @@ jobs: services: redis: image: 'redis:7.2.4' - # Set health checks to wait until redis has started options: >- --health-cmd "redis-cli ping" --health-interval 10s --health-timeout 5s --health-retries 5 ports: - # Maps port 6379 on service container to the host - 6379:6379 steps: @@ -58,7 +56,6 @@ jobs: "admin:email": "test@example.org", "admin:password": "hAN3Eg8W", "admin:password:confirm": "hAN3Eg8W", - "database": "redis", "redis:host": "127.0.0.1", "redis:port": 6379, @@ -85,3 +82,20 @@ jobs: - name: Test coverage uses: coverallsapp/github-action@v2 + + # Python setup and run for Translator Tests + - name: Set up Python + uses: actions/setup-python@v4 + with: + python-version: '3.8' # Adjust to your version + + - name: Install Python dependencies + run: | + python -m venv .venv + source .venv/bin/activate + pip install -r translator-service/requirements.txt + + - name: Run Translator Tests + run: | + source .venv/bin/activate + pytest test/unit/test_translator.py # Adjust path if necessary diff --git a/test/translator_test.py b/test/translator_test.py new file mode 100644 index 0000000000..ecf945a5f0 --- /dev/null +++ b/test/translator_test.py @@ -0,0 +1,35 @@ +from unittest.mock import Mock, patch +import unittest + +class TestTranslator(unittest.TestCase): + def test_llm_normal_response(self): + """Test normal LLM response""" + with patch('openai.AzureOpenAI') as mock_client: + mock_responses = [ + Mock(choices=[Mock(message=Mock(content="No"))]), # Language detection + Mock(choices=[Mock(message=Mock(content="Hello world"))]), # Translation + ] + mock_client.return_value.chat.completions.create.side_effect = mock_responses + + # Test translation + is_english, translation = translate("Hallo Welt") + + self.assertEqual(is_english, False) + self.assertEqual(translation, "Hello world") + + def test_llm_gibberish_response(self): + """Test handling of gibberish input""" + with patch('openai.AzureOpenAI') as mock_client: + # Mock an unexpected response + mock_client.return_value.chat.completions.create.return_value = Mock( + choices=[Mock(message=Mock(content="I don't understand"))] + ) + + # Test translation of gibberish + is_english, translation = translate("asdfghjkl") + + self.assertEqual(is_english, False) + self.assertEqual(translation, "Error: Could not determine language") + +if __name__ == '__main__': + unittest.main() \ No newline at end of file