本文整理匯總了Python中spreadsheetimport.SpreadsheetImport.get_identifier_field方法的典型用法代碼示例。如果您正苦於以下問題:Python SpreadsheetImport.get_identifier_field方法的具體用法?Python SpreadsheetImport.get_identifier_field怎麽用?Python SpreadsheetImport.get_identifier_field使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類spreadsheetimport.SpreadsheetImport
的用法示例。
在下文中一共展示了SpreadsheetImport.get_identifier_field方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testImportSimple
# 需要導入模塊: from spreadsheetimport import SpreadsheetImport [as 別名]
# 或者: from spreadsheetimport.SpreadsheetImport import get_identifier_field [as 別名]
def testImportSimple(self):
no_signals()
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
self.assertEqual(0, self.collection.records.count())
testimport.analyze()
dc = dict(
identifier=Field.objects.get(name='identifier', standard__prefix='dc'),
title=Field.objects.get(name='title', standard__prefix='dc'),
creator=Field.objects.get(name='creator', standard__prefix='dc'),
coverage=Field.objects.get(name='coverage', standard__prefix='dc'),
)
testimport.mapping = {
'ID': dc['identifier'],
'Filename': None,
'Title': dc['title'],
'Creator': dc['creator'],
'Location': dc['coverage'],
}
testimport.name_field = 'ID'
self.assertNotEqual(None, testimport.get_identifier_field())
testimport.run()
self.assertEquals(2, self.collection.records.count())
r1 = self.collection.records.get(name='A001'.lower())
self.assertEqual('A001', r1.fieldvalue_set.get(field=dc['identifier']).value)
示例2: test_analyze
# 需要導入模塊: from spreadsheetimport import SpreadsheetImport [as 別名]
# 或者: from spreadsheetimport.SpreadsheetImport import get_identifier_field [as 別名]
def test_analyze(self):
testimport = SpreadsheetImport(StringIO(csv_file), [self.collection])
self.assertFalse(testimport.analyzed)
data = testimport.analyze()
self.assertTrue(testimport.analyzed)
self.assertEqual(2, len(data))
self.assertEqual('A001', data[0]['ID'][0])
self.assertEqual('a001.jpg', data[0]['Filename'][0])
self.assertEqual('Test', data[0]['Title'][0])
self.assertEqual('Knab, Andreas', data[0]['Creator'][0])
self.assertEqual('Harrisonburg, VA', data[0]['Location'][0])
self.assertEqual(None, data[0]['Unused'])
self.assertEqual('A002', data[1]['ID'][0])
self.assertEqual('a002.jpg', data[1]['Filename'][0])
self.assertEqual('Another Test', data[1]['Title'][0])
self.assertEqual('Andreas Knab;John Doe', data[1]['Creator'][0])
self.assertEqual('Virginia', data[1]['Location'][0])
self.assertEqual(None, data[1]['Unused'])
# These don't match anything
self.assertEqual(None, testimport.mapping['ID'])
self.assertEqual(None, testimport.mapping['Filename'])
self.assertEqual(None, testimport.mapping['Unused'])
# These should match standards fields
self.assertNotEqual(None, testimport.mapping['Title'])
self.assertNotEqual(None, testimport.mapping['Creator'])
self.assertNotEqual(None, testimport.mapping['Location'])
self.assertEqual(None, testimport.get_identifier_field())
# Map the ID field and try again
testimport.mapping['ID'] = Field.objects.get(
name='identifier', standard__prefix='dc')
self.assertEqual('ID', testimport.get_identifier_field())