Exemplo n.º 1
0
 def test_time_related_components_of_generated_queries(
         self, given_params, expected_query_expr_reprs):
     mock = MagicMock()
     meth = MethodProxy(
         _QueryProcessor,
         mock,
         class_attrs=[
             # for them, the actual members/methods (not mocks) will be used
             # class constants:
             'queried_model_class',
             'client_relationship',
             'client_asoc_model_class',
             # methods:
             'pop_time_min_max_until',
             'pop_limit',
             'make_time_cmp_generator',
             'query__ordering_by',
             'query__limit',
         ])
     actual_query_expr_reprs = []
     and_mock = self._make_the_and_mock(actual_query_expr_reprs)
     query_mock = self._make_the_query_mock(actual_query_expr_reprs)
     mock.build_query.return_value = query_mock
     with patch('n6lib.data_backend_api.and_', and_mock), \
          patch('n6lib.data_backend_api.utcnow', return_value=self._UTCNOW):
         list(
             meth.generate_query_results(given_params,
                                         item_number_limit=None,
                                         day_step=1))
     self.assertEqual(actual_query_expr_reprs, expected_query_expr_reprs)
Exemplo n.º 2
0
 def test_time_related_components_of_generated_queries(
         self, given_time_constraints_items, expected_query_expr_reprs):
     mock = MagicMock()
     meth = MethodProxy(
         _EventsQueryProcessor,
         mock,
         class_attrs=[
             # for them, the actual members/methods (not mocks) will be used
             # * class constants:
             'queried_model_class',
             'client_asoc_model_class',
             # * methods:
             '_prepare_result_production_tools',
             '_fetch_rows_from_db',
             '_time_comparisons_per_step',
             '_fetch_rows_for_single_step',
             '_build_query_base_for_single_step',
             '_build_actual_query',
         ])
     actual_query_expr_reprs = []
     and_mock = self._make_mock_of_sqlalchemy_and(actual_query_expr_reprs)
     mock._query_base = self._make_mock_of_query_base(
         actual_query_expr_reprs)
     mock._day_step = 1
     mock._opt_limit = None
     mock._time_constraints = (
         given_time_constraints_items['time.min'],
         given_time_constraints_items.get('time.max'),
         given_time_constraints_items.get('time.until'))
     with patch('n6lib.data_backend_api.and_', and_mock), \
          patch('n6lib.data_backend_api.utcnow', return_value=self._UTCNOW):
         list(meth.generate_query_results())
     self.assertEqual(actual_query_expr_reprs, expected_query_expr_reprs)