Esempio n. 1
0
 def test_response_for_path(self):
     data = json.dumps({
         "path": {
             "code": 200,
             "data": "data",
             "content-type": "application/json"
         }
     })
     config = server.Config(data=data)
     response = config.response_for_path("path")
     self.assertEqual(response.code, 200)
     self.assertEqual(response.data, b"data")
     self.assertEqual(response.content_type, "application/json")
Esempio n. 2
0
    def test_init_path(self):
        try:
            original_open = server.__builtins__["open"]
            mock_open = unittest.mock.MagicMock()
            mock_file = unittest.mock.MagicMock()
            mock_open.return_value.__enter__.return_value = mock_file
            mock_file.read = lambda: '{"path": {"code": 200}}'
            server.__builtins__["open"] = mock_open

            config = server.Config(config_path="path")
            self.assertEqual(config.data, {"path": {"code": 200}})
        finally:
            server.__builtins__["open"] = original_open
Esempio n. 3
0
 def test_response_for_path_not_found(self):
     config = server.Config()
     response = config.response_for_path("path")
     self.assertEqual(response.code, 404)
Esempio n. 4
0
 def test_init_no_data(self):
     config = server.Config()
     self.assertEqual(config.data, {})
Esempio n. 5
0
 def test_init_data_and_path(self):
     with self.assertRaises(ValueError):
         server.Config(data='{"path": {"code": 200}}',
                       config_path="config_path")
Esempio n. 6
0
 def test_init_data(self):
     config = server.Config(data='{"path": {"code": 200}}')
     self.assertEqual(config.data, {"path": {"code": 200}})