Example #1
0
    def test_as_json_with_no_result_and_no_fallback(self):
        mock = self.MockLazyResult(None)
        response = Response('mock', mock)

        with self.assertRaises(ValueError) as error_context:
            response.as_json()
        self.assertTrue('No response data and no fallback provided!' in
                        error_context.exception.args)
Example #2
0
    def test_as_json_nested_nan(self):
        mock = self.MockLazyResult([self.MockModel(data=float('nan'))])

        mock2 = self.MockLazyResult(self.MockModel(data=mock))
        response2 = Response('mock', mock2)

        self.assertEqual({'data': [{'data': None}]}, response2.as_json())
Example #3
0
    def test_as_json_recursive_response_via_list(self):
        mock = self.MockLazyResult('hello world')

        mock2 = self.MockLazyResult([mock])
        response2 = Response('mock', mock2)

        self.assertEqual(['hello world'], response2.as_json())
Example #4
0
    def test_as_json_recursive_response(self):
        mock = self.MockLazyResult('hello world')

        mock2 = self.MockLazyResult(self.MockModel(data=mock))
        response2 = Response('mock', mock2)

        self.assertEqual({'data': 'hello world'}, response2.as_json())
Example #5
0
    def test_as_json_with_fallback_different_fallback(self):
        mock_fallback = self.MockLazyResult('hello and goodbye to the world')
        response_fallback = Response('mock', mock_fallback)

        mock = self.MockLazyResult(None)
        response = Response('mock', mock, fallback=response_fallback)

        response.evaluate()
        self.assertEqual('hello and goodbye to the world', response.as_json())
Example #6
0
    def test_as_json_recursive_response_via_response_in_property_containing_model(
            self):
        mock = self.MockLazyResult([self.MockModel(data='hello world')])

        mock2 = self.MockLazyResult(self.MockModel(data=mock))
        response2 = Response('mock', mock2)

        self.assertEqual({'data': [{
            'data': 'hello world'
        }]}, response2.as_json())
Example #7
0
 def test_as_json(self):
     mock = self.MockLazyResult(self.MockModel(data='hello'))
     response = Response('mock', mock)
     self.assertEqual({'data': 'hello'}, response.as_json())
Example #8
0
 def test_as_json_with_python_nan(self):
     mock = self.MockLazyResult({'hello': float('nan')})
     response = Response('mock', mock)
     self.assertEqual({'hello': None}, response.as_json())
Example #9
0
    def test_as_json_with_numpy_nan(self):
        import numpy as np

        mock = self.MockLazyResult({'hello': np.nan})
        response = Response('mock', mock)
        self.assertEqual({'hello': None}, response.as_json())
Example #10
0
 def test_as_json_list(self):
     mock = self.MockLazyResult(['hello', 'world'])
     response = Response('mock', mock)
     self.assertEqual(['hello', 'world'], response.as_json())
Example #11
0
 def test_as_json_non_property(self):
     mock = self.MockLazyResult('hello world')
     response = Response('mock', mock)
     self.assertEqual('hello world', response.as_json())
Example #12
0
    def test_as_json_recursive_response_via_dictionary(self):
        mock = self.MockLazyResult('hello world')

        mock2 = self.MockLazyResult({'data': mock})
        response2 = Response('mock', mock2)
        self.assertEqual({'data': 'hello world'}, response2.as_json())