test_client.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import os
  2. import unittest
  3. from dify_client.client import ChatClient, CompletionClient, DifyClient
  4. API_KEY = os.environ.get("API_KEY")
  5. APP_ID = os.environ.get("APP_ID")
  6. class TestChatClient(unittest.TestCase):
  7. def setUp(self):
  8. self.chat_client = ChatClient(API_KEY)
  9. def test_create_chat_message(self):
  10. response = self.chat_client.create_chat_message({}, "Hello, World!", "test_user")
  11. self.assertIn("message_id", response)
  12. def test_get_conversation_messages(self):
  13. response = self.chat_client.get_conversation_messages("test_user")
  14. self.assertIsInstance(response, list)
  15. def test_get_conversations(self):
  16. response = self.chat_client.get_conversations("test_user")
  17. self.assertIsInstance(response, list)
  18. class TestCompletionClient(unittest.TestCase):
  19. def setUp(self):
  20. self.completion_client = CompletionClient(API_KEY)
  21. def test_create_completion_message(self):
  22. response = self.completion_client.create_completion_message({}, "What's the weather like today?", "blocking", "test_user")
  23. self.assertIn("message_id", response)
  24. class TestDifyClient(unittest.TestCase):
  25. def setUp(self):
  26. self.dify_client = DifyClient(API_KEY)
  27. def test_message_feedback(self):
  28. response = self.dify_client.message_feedback("test_message_id", 5, "test_user")
  29. self.assertIn("success", response)
  30. def test_get_application_parameters(self):
  31. response = self.dify_client.get_application_parameters("test_user")
  32. self.assertIsInstance(response, dict)
  33. if __name__ == "__main__":
  34. unittest.main()