예제 #1
0
 def test_extract_model_data_from_should_get_data_extracted_from_a_key_defined_by_list(
         self):
     model_ids = {'name': ['message', 'subject']}
     data_extractor = DataExtractor(model_id_mapping=model_ids)
     model_ids, model_data = data_extractor.extract_model_data_from(
         discussion_data)
     self.assertEquals({'name': 'subject is nothing'}, model_ids)
 def test_extract_model_data_should_process_data_and_return_it(self):
     model_ids = {"name": ["message", "subject"]}
     processor = Mock()
     processor.process.return_value = "subject is something"
     data_extractor = DataExtractor(model_id_mapping=model_ids, using_processors={"name": processor})
     model_ids, model_data = data_extractor.extract_model_data_from(discussion_data)
     self.assertEquals({"name": "subject is something"}, model_ids)
예제 #3
0
 def test_should_accept_only_dicts(self):
     with self.assertRaises(AssertionError):
         DataExtractor([], {'name': 'name_val'}, {})
     with self.assertRaises(AssertionError):
         DataExtractor({'id': 'some_id'}, [], {})
     with self.assertRaises(AssertionError):
         DataExtractor({'id': 'some_id'}, {'name': 'name_val'}, [])
 def test_extract_model_data_from_should_get_data_extracted_from_what_is_passed_in(self):
     model_data = {"name": "name", "mytw_user_id": "id", "email": "email"}
     model_ids = {"username": "******"}
     data_extractor = DataExtractor(model_id_mapping=model_ids, model_data_mapping=model_data)
     model_ids, model_data = data_extractor.extract_model_data_from(user_test_data[0])
     self.assertEquals({"username": "******"}, model_ids)
     self.assertEquals({"email": "*****@*****.**", "name": "John Doe", "mytw_user_id": 1278237}, model_data)
 def test_extract_model_data_from_should_merge_default_into_model_id_if_specefied(self):
     model_data = {"name": "name", "mytw_user_id": "id", "email": "email"}
     model_ids = {"username": "******"}
     data_extractor = DataExtractor(
         model_id_mapping=model_ids, model_data_mapping=model_data, default={"type": "user"}
     )
     model_ids, model_data = data_extractor.extract_model_data_from(user_test_data[0])
     self.assertEquals({"username": "******", "type": "user"}, model_ids)
예제 #6
0
 def test_extract_model_data_should_process_data_and_return_it(self):
     model_ids = {'name': ['message', 'subject']}
     processor = Mock()
     processor.process.return_value = "subject is something"
     data_extractor = DataExtractor(model_id_mapping=model_ids,
                                    using_processors={'name': processor})
     model_ids, model_data = data_extractor.extract_model_data_from(
         discussion_data)
     self.assertEquals({'name': 'subject is something'}, model_ids)
예제 #7
0
 def test_extract_model_data_from_should_merge_default_into_model_id_if_specefied(
         self):
     model_data = {"name": "name", "mytw_user_id": "id", "email": "email"}
     model_ids = {"username": "******"}
     data_extractor = DataExtractor(model_id_mapping=model_ids,
                                    model_data_mapping=model_data,
                                    default={'type': 'user'})
     model_ids, model_data = data_extractor.extract_model_data_from(
         user_test_data[0])
     self.assertEquals({'username': '******', 'type': 'user'}, model_ids)
예제 #8
0
 def test_extract_model_data_from_should_get_data_extracted_from_what_is_passed_in(
         self):
     model_data = {"name": "name", "mytw_user_id": "id", "email": "email"}
     model_ids = {"username": "******"}
     data_extractor = DataExtractor(model_id_mapping=model_ids,
                                    model_data_mapping=model_data)
     model_ids, model_data = data_extractor.extract_model_data_from(
         user_test_data[0])
     self.assertEquals({'username': '******'}, model_ids)
     self.assertEquals(
         {
             'email': '*****@*****.**',
             'name': 'John Doe',
             'mytw_user_id': 1278237
         }, model_data)
예제 #9
0
 def create_or_update(self,
                      model,
                      model_id_mapping,
                      model_data_mapping={},
                      default={},
                      using_processors={}):
     data_extractor = DataExtractor(model_id_mapping=model_id_mapping,
                                    model_data_mapping=model_data_mapping,
                                    default=default,
                                    using_processors=using_processors)
     node = OperationNode(model,
                          informer=self._informer,
                          data_extractor=data_extractor,
                          url_extractor=self._url_extractor,
                          data_sanitizer=self._data_sanitizer)
     if not self.root:
         self.root = node
     self.current = node
     self._informer = None
     self._data_sanitizer = None
     return self
예제 #10
0
 def test_should_augment_id_with_defaults(self):
     data_extractor = DataExtractor({'id': 'some_id'}, {'name': 'name_val'},
                                    {'type': 'node_type'})
     self.assertEquals({'id': 'some_id'}, data_extractor._model_id_mapping)
     self.assertEquals({'type': 'node_type'}, data_extractor._model_default)
예제 #11
0
 def test_should_set_params(self):
     data_extractor = DataExtractor({'id': 'some_id'}, {'name': 'name_val'},
                                    {})
     self.assertEquals({'id': 'some_id'}, data_extractor._model_id_mapping)
     self.assertEquals({'name': 'name_val'},
                       data_extractor._model_data_mapping)
 def test_extract_model_data_from_should_get_data_extracted_from_a_key_defined_by_list(self):
     model_ids = {"name": ["message", "subject"]}
     data_extractor = DataExtractor(model_id_mapping=model_ids)
     model_ids, model_data = data_extractor.extract_model_data_from(discussion_data)
     self.assertEquals({"name": "subject is nothing"}, model_ids)