test_json_parsing.py 755 B

123456789101112131415161718192021222324
  1. import unittest
  2. from utils import parse_json_from_response
  3. class TestJsonParsing(unittest.TestCase):
  4. def test_unescaped_quotes(self):
  5. # This JSON is invalid because of quotes around "情境认知教育基金会" inside the string
  6. invalid_json = """
  7. [
  8. {
  9. "name": "Test",
  10. "bio": "He founded the "Foundation" successfully."
  11. }
  12. ]
  13. """
  14. result = parse_json_from_response(invalid_json)
  15. self.assertIsNone(result)
  16. def test_valid_json(self):
  17. valid_json = '[{"name": "Test"}]'
  18. result = parse_json_from_response(valid_json)
  19. self.assertEqual(result[0]['name'], "Test")
  20. if __name__ == '__main__':
  21. unittest.main()