예제 #1
0
    def test_lazy_result_only_does_not_evaluate_other_properties(self):
        should_not_call_mock = self.ErrorMock()
        should_not_call_result = LazyResult(should_not_call_mock.value)

        mock = self.Mock(
            self.MockModelTwo(some_data='hello',
                              some_other_data=should_not_call_result))
        lazy_result = LazyResult(mock.value)

        lazy_result.only(['some_data']).evaluate()
예제 #2
0
 def test_lazy_result_only_filter_properties_in_list(self):
     mock = self.Mock(
         [self.MockModelTwo(some_data='hello', some_other_data='world')])
     lazy_result = LazyResult(mock.value)
     self.assertEqual([{
         'some_data': 'hello'
     }],
                      lazy_result.only(['some_data']).evaluate())
예제 #3
0
 def test_lazy_result_only_filter_properties_multiple_properties(self):
     mock = self.Mock(
         self.MockModelTwo(some_data='hello', some_other_data='world'))
     lazy_result = LazyResult(mock.value)
     self.assertEqual({
         'some_data': 'hello',
         'some_other_data': 'world'
     },
                      lazy_result.only(['some_data',
                                        'some_other_data']).evaluate())
예제 #4
0
    def test_lazy_result_only_does_not_filter_too_much(self):
        parent_mock = self.Mock(self.MockModel(data='hello'))
        parent_lazy_result = LazyResult(parent_mock.value)

        mock = self.Mock(
            self.MockModelTwo(some_data=parent_lazy_result,
                              some_other_data='world'))
        lazy_result = LazyResult(mock.value)

        result = lazy_result.only(['some_data']).evaluate()
        self.assertEqual(['some_data'], list(result.keys()))
        self.assertEqual({'data': 'hello'}, result['some_data'].attributes)