def test_write_related(self):
     """Test that related info is written to a file"""
     writer = RelatedInfoWriter(self.definition_name, self.definition, field_transform=dict())
     related_info = {'prop1': 'value1', 'prop2': 'value2', '_localId': 'relInfoId'}
     writer.write_related('record-id', related_info, self.outfile)
     csv_line = self.outfile.getvalue()
     for val in ['value1', 'value2', 'relInfoId', 'record-id']:
         self.assertIn(val, csv_line, '{} not found in CSV line'.format(val))
 def test_write_header(self):
     """Test that the header written to a file"""
     writer = RelatedInfoWriter(self.definition_name, self.definition, field_transform=dict())
     writer.write_header(self.outfile)
     header = self.outfile.getvalue()
     # Unlike the Record exporter, the related info exporter doesn't have a defined field order
     for col in ['prop1', 'prop2', 'record_id', 'testRelatedInfo_id']:
         self.assertIn(col, header, '{} not found in header line'.format(col))
Example #3
0
 def test_write_header(self):
     """Test that the header written to a file"""
     writer = RelatedInfoWriter(self.definition_name,
                                self.definition,
                                field_transform=dict())
     writer.write_header(self.outfile)
     header = self.outfile.getvalue()
     # Unlike the Record exporter, the related info exporter doesn't have a defined field order
     for col in ['prop1', 'prop2', 'record_id', 'testRelatedInfo_id']:
         self.assertIn(col, header,
                       '{} not found in header line'.format(col))
 def test_transform_value_keys(self):
     """Test that key names are changed and values dropped if specified"""
     rename_transform = {'prop1': 'newName'}
     drop_transform = {'prop1': None}
     rename_writer = RelatedInfoWriter(self.definition_name, self.definition,
                                         field_transform=rename_transform)
     drop_writer = RelatedInfoWriter(self.definition_name, self.definition,
                                       field_transform=drop_transform)
     input_data = {'prop1': 'value'}
     self.assertEqual(rename_writer.transform_value_keys(input_data), {'newName': 'value'})
     self.assertEqual(drop_writer.transform_value_keys(input_data), dict())
Example #5
0
 def test_property_auto_detect(self):
     """Test that the Exporter auto-detects sub-schema fields properly"""
     bad_def = {}
     with self.assertRaises(ValueError):
         writer = RelatedInfoWriter(self.definition_name, bad_def)
     writer = RelatedInfoWriter(self.definition_name,
                                self.definition,
                                field_transform=dict())
     self.assertEqual(writer.is_multiple, self.definition['multiple'])
     self.assertEqual(4, len(writer.csv_columns))
     for prop in ['record_id', 'testRelatedInfo_id', 'prop1', 'prop2']:
         self.assertIn(prop, writer.csv_columns,
                       '{} missing from CSV columns'.format(prop))
Example #6
0
 def test_write_related(self):
     """Test that related info is written to a file"""
     writer = RelatedInfoWriter(self.definition_name,
                                self.definition,
                                field_transform=dict())
     related_info = {
         'prop1': 'value1',
         'prop2': 'value2',
         '_localId': 'relInfoId'
     }
     writer.write_related('record-id', related_info, self.outfile)
     csv_line = self.outfile.getvalue()
     for val in ['value1', 'value2', 'relInfoId', 'record-id']:
         self.assertIn(val, csv_line,
                       '{} not found in CSV line'.format(val))
Example #7
0
 def test_transform_value_keys(self):
     """Test that key names are changed and values dropped if specified"""
     rename_transform = {'prop1': 'newName'}
     drop_transform = {'prop1': None}
     rename_writer = RelatedInfoWriter(self.definition_name,
                                       self.definition,
                                       field_transform=rename_transform)
     drop_writer = RelatedInfoWriter(self.definition_name,
                                     self.definition,
                                     field_transform=drop_transform)
     input_data = {'prop1': 'value'}
     self.assertEqual(rename_writer.transform_value_keys(input_data),
                      {'newName': 'value'})
     self.assertEqual(drop_writer.transform_value_keys(input_data), dict())