def test_apply_multiple_with_previous_values(self): # given: converter = _create_mock_string_converter() cell_conversion = ListElementCellConversion('staff.developers.name', converter) # and: metadata = MetadataEntity() metadata.define_content('developers', [{'age': 32}, {'age': 23}]) # when: cell_conversion.apply(metadata, 'John||Paul||George||Ringo') # then: developers = metadata.get_content('developers') self.assertEqual(4, len(developers)) # and: expected_names = [ 'John - converted', 'Paul - converted', 'George - converted', 'Ringo - converted' ] expected_ages = [32, 23, None, None] for index, developer in enumerate(developers): self.assertEqual(expected_names[index], developer.get('name')) self.assertEqual(expected_ages[index], developer.get('age'))
def test_define_content(self): # given: metadata = MetadataEntity() # when: metadata.define_content('user.name', 'Juan dela Cruz') metadata.define_content('user.age', 47) # then: user = metadata.get_content('user') self.assertIsNotNone(user) self.assertEqual('Juan dela Cruz', user.get('name')) self.assertEqual(47, user.get('age'))
def test_apply_previously_processed_field(self): # given: converter = _create_mock_string_converter() cell_conversion = ListElementCellConversion('shop.user.basket.product_name', converter) # and: metadata = MetadataEntity() metadata.define_content('user.basket', [{'quantity': 3}]) # when: cell_conversion.apply(metadata, 'apple') # then: basket = metadata.get_content('user.basket') self.assertEqual(1, len(basket)) # and: current_element = basket[0] self.assertEqual(3, current_element.get('quantity')) self.assertEqual('apple - converted', current_element.get('product_name'))
def apply(self, metadata: MetadataEntity, cell_data): value = self.converter.convert(cell_data) metadata.object_id = metadata.object_id or value if not metadata.is_module: metadata.define_content(self.applied_field, value)
def apply(self, metadata: MetadataEntity, cell_data): if cell_data is not None: content = self.converter.convert(cell_data) metadata.define_content(self.applied_field, content)
def apply(self, metadata: MetadataEntity, cell_data): value = self.converter.convert(cell_data) metadata.object_id = value metadata.define_content(self.applied_field, value)