def test__constraints_for_new_request(self, list_file_info_mock,
                                          get_time_from_filename_mock):
        max_rec = 10
        config = {
            'max_records': max_rec,
            'ds_params': {
                'base_url': 'test_data',
                'list_pattern': 'list_pattern',
                'date_pattern': 'date_pattern',
                'date_extraction_pattern': 'date_extraction_pattern',
                },
            }
        f_list = [('a', 1,), ('b', 2,), ('c', 3,), ]
        list_file_info_mock.return_value = f_list
        get_time_from_filename_mock.return_value = 'a_time'

        ret = DummyDataHandler._constraints_for_new_request(config)
        self.assertIn('set_new_data_check', config)
        self.assertEqual(config['set_new_data_check'], f_list)

        self.assertIn('new_files', ret)

        self.assertEqual(get_time_from_filename_mock.call_count, 2)
        self.assertEqual(ret['new_files'], f_list)
        self.assertIn('start_time', ret)
        self.assertEqual(ret['start_time'], 'a_time')
        self.assertIn('end_time', ret)
        self.assertEqual(ret['end_time'], 'a_time')
        self.assertIn('bounding_box', ret)
        self.assertIsInstance(ret['bounding_box'], dict)
        self.assertIn('vars', ret)
        self.assertIsInstance(ret['vars'], list)
    def test__constraints_for_new_request(self, list_file_info_mock, get_time_from_filename_mock):
        max_rec = 10
        config = {
            "max_records": max_rec,
            "ds_params": {
                "base_url": "test_data",
                "list_pattern": "list_pattern",
                "date_pattern": "date_pattern",
                "date_extraction_pattern": "date_extraction_pattern",
            },
        }
        f_list = [("a", 1), ("b", 2), ("c", 3)]
        list_file_info_mock.return_value = f_list
        get_time_from_filename_mock.return_value = "a_time"

        ret = DummyDataHandler._constraints_for_new_request(config)
        self.assertIn("set_new_data_check", config)
        self.assertEqual(config["set_new_data_check"], f_list)

        self.assertIn("new_files", ret)

        self.assertEqual(get_time_from_filename_mock.call_count, 2)
        self.assertEqual(ret["new_files"], f_list)
        self.assertIn("start_time", ret)
        self.assertEqual(ret["start_time"], "a_time")
        self.assertIn("end_time", ret)
        self.assertEqual(ret["end_time"], "a_time")
        self.assertIn("bounding_box", ret)
        self.assertIsInstance(ret["bounding_box"], dict)
        self.assertIn("vars", ret)
        self.assertIsInstance(ret["vars"], list)
    def test__constraints_for_new_request(self, list_file_info_mock,
                                          get_time_from_filename_mock):
        max_rec = 10
        config = {
            'max_records': max_rec,
            'ds_params': {
                'base_url': 'test_data',
                'list_pattern': 'list_pattern',
                'date_pattern': 'date_pattern',
                'date_extraction_pattern': 'date_extraction_pattern',
                },
            }
        f_list = [('a', 1,), ('b', 2,), ('c', 3,), ]
        list_file_info_mock.return_value = f_list
        get_time_from_filename_mock.return_value = 'a_time'

        ret = DummyDataHandler._constraints_for_new_request(config)
        self.assertIn('set_new_data_check', config)
        self.assertEqual(config['set_new_data_check'], f_list)

        self.assertIn('new_files', ret)

        self.assertEqual(get_time_from_filename_mock.call_count, 2)
        self.assertEqual(ret['new_files'], f_list)
        self.assertIn('start_time', ret)
        self.assertEqual(ret['start_time'], 'a_time')
        self.assertIn('end_time', ret)
        self.assertEqual(ret['end_time'], 'a_time')
        self.assertIn('bounding_box', ret)
        self.assertIsInstance(ret['bounding_box'], dict)
        self.assertIn('vars', ret)
        self.assertIsInstance(ret['vars'], list)
    def test__get_data(self, build_granule_mock, TaxyTool_mock,
                       RecordDictionaryTool_mock):
        config = {
            'constraints': {
                'array_len': 6
            },
            'max_records': 4,
            'data_producer_id': sentinel.dprod_id,
            'taxonomy': sentinel.taxy_tool
        }

        TaxyTool_mock.load.return_value = sentinel.ttool_ret_val
        RecordDictionaryTool_mock.side_effect = lambda **kwargs: {}

        for x in DummyDataHandler._get_data(config):
            RecordDictionaryTool_mock.assert_called_with(
                taxonomy=sentinel.ttool_ret_val)
            build_granule_mock.assert_called_with(
                taxonomy=sentinel.ttool_ret_val,
                data_producer_id=sentinel.dprod_id,
                record_dictionary=ANY)
            cargs = build_granule_mock.call_args
            self.assertIn('data', cargs[1]['record_dictionary'])
            self.assertIsInstance(cargs[1]['record_dictionary']['data'],
                                  numpy.ndarray)

        self.assertEquals(build_granule_mock.call_count, 2)
        self.assertEquals(RecordDictionaryTool_mock.call_count, 2)

        TaxyTool_mock.load.assert_called_once_with(sentinel.taxy_tool)
 def test__new_data_constraints(self):
     max_rec = 10
     config = {'max_records':max_rec}
     ret = DummyDataHandler._new_data_constraints(config)
     self.assertTrue('array_len' in ret)
     i=ret['array_len']
     self.assertIsInstance(i, int)
     self.assertTrue(max_rec+1 <= i <= max_rec+10)
 def test__new_data_constraints(self):
     max_rec = 10
     config = {'max_records': max_rec}
     ret = DummyDataHandler._new_data_constraints(config)
     self.assertTrue('array_len' in ret)
     i = ret['array_len']
     self.assertIsInstance(i, int)
     self.assertTrue(max_rec + 1 <= i <= max_rec + 10)
    def test__get_data(self, build_granule_mock, ParamDict_mock, RecordDictionaryTool_mock):
        config={'constraints':{'array_len':6},'max_records':4,'data_producer_id':sentinel.dprod_id,'param_dictionary':sentinel.pdict}

        ParamDict_mock.load.return_value = sentinel.pdict_return_value
        RecordDictionaryTool_mock.side_effect = lambda **kwargs: {}

        for x in DummyDataHandler._get_data(config):
            RecordDictionaryTool_mock.assert_called_with(param_dictionary=sentinel.pdict_return_value)
            build_granule_mock.assert_called_with(data_producer_id=sentinel.dprod_id, record_dictionary=ANY, param_dictionary=sentinel.pdict_return_value)
            cargs=build_granule_mock.call_args
            self.assertIn('dummy', cargs[1]['record_dictionary'])
            self.assertIsInstance(cargs[1]['record_dictionary']['dummy'], numpy.ndarray)

        self.assertEquals(build_granule_mock.call_count, 2)
        self.assertEquals(RecordDictionaryTool_mock.call_count, 2)

        ParamDict_mock.load.assert_called_once_with(sentinel.pdict)
    def test__get_data(self, RecordDictionaryTool_mock):
        config = {'constraints': {'array_len': 6},
                  'max_records': 4,
                  'data_producer_id': sentinel.dprod_id,
                  'stream_def': sentinel.stream_def_id}

        my_dict = {}

        def setitem(name, val):
            my_dict[name] = val

        retval = MagicMock(spec=RecordDictionaryTool)
        retval.__setitem__ = Mock(side_effect=setitem)
        retval.to_granule.return_value = MagicMock(spec=Granule)
        RecordDictionaryTool_mock.return_value = retval

        for x in DummyDataHandler._get_data(config):
            self.assertTrue(isinstance(x, Granule))
            retval.to_granule.assert_any_call()
    def test__get_data(self, RecordDictionaryTool_mock):
        config = {'constraints': {'array_len': 6},
                  'max_records': 4,
                  'data_producer_id': sentinel.dprod_id,
                  'stream_def': sentinel.stream_def_id}

        my_dict = {}

        def setitem(name, val):
            my_dict[name] = val

        retval = MagicMock(spec=RecordDictionaryTool)
        retval.__setitem__ = Mock(side_effect=setitem)
        retval.to_granule.return_value = MagicMock(spec=Granule)
        RecordDictionaryTool_mock.return_value = retval

        for x in DummyDataHandler._get_data(config):
            self.assertTrue(isinstance(x, Granule))
            retval.to_granule.assert_any_call()
    def test__get_data(self, build_granule_mock, ParamDict_mock, RecordDictionaryTool_mock):
        config = {
            "constraints": {"array_len": 6},
            "max_records": 4,
            "data_producer_id": sentinel.dprod_id,
            "param_dictionary": sentinel.pdict,
        }

        ParamDict_mock.load.return_value = sentinel.pdict_return_value
        RecordDictionaryTool_mock.side_effect = lambda **kwargs: {}

        for x in DummyDataHandler._get_data(config):
            RecordDictionaryTool_mock.assert_called_with(param_dictionary=sentinel.pdict_return_value)
            build_granule_mock.assert_called_with(
                data_producer_id=sentinel.dprod_id, record_dictionary=ANY, param_dictionary=sentinel.pdict_return_value
            )
            cargs = build_granule_mock.call_args
            self.assertIn("dummy", cargs[1]["record_dictionary"])
            self.assertIsInstance(cargs[1]["record_dictionary"]["dummy"], numpy.ndarray)

        self.assertEquals(build_granule_mock.call_count, 2)
        self.assertEquals(RecordDictionaryTool_mock.call_count, 2)

        ParamDict_mock.load.assert_called_once_with(sentinel.pdict)
 def test__init_acquisition_cycle(self, _init_acquisition_cycle_mock):
     config = {}
     DummyDataHandler._init_acquisition_cycle(config)
     _init_acquisition_cycle_mock.assert_called_once_with(config)
Exemplo n.º 12
0
 def test__init_acquisition_cycle(self, _init_acquisition_cycle_mock):
     config = {}
     DummyDataHandler._init_acquisition_cycle(config)
     _init_acquisition_cycle_mock.assert_called_once_with(config)