Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions
CMFTopic.tests.test_exportimport.TopicExportImportTests Class Reference
Inheritance diagram for CMFTopic.tests.test_exportimport.TopicExportImportTests:
Inheritance graph
[legend]
Collaboration diagram for CMFTopic.tests.test_exportimport.TopicExportImportTests:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def test_listExportableItems
def test__getExportInfo_empty
def test_export_empty
def test__getExportInfo_with_criteria
def test_export_with_string_criterion
def test_export_with_integer_criterion
def test_export_with_date_criterion
def test_export_with_list_criterion
def test_export_with_sort_criterion
def test_export_with_mixed_criteria
def test_import_empty_with_string_criterion
def test_import_empty_with_integer_criterion
def test_import_empty_with_date_criterion
def test_import_empty_with_list_criterion
def test_import_empty_with_sort_criterion
def test_import_empty_with_mixed_criterion
def test_import_without_purge_leaves_existing_criteria
def test_import_with_purge_removes_existing_criteria

Static Public Attributes

 layer = ExportImportZCMLLayer

Private Member Functions

def _getTargetClass
def _makeOne
def _makeTopic

Detailed Description

Definition at line 47 of file test_exportimport.py.


Member Function Documentation

Definition at line 51 of file test_exportimport.py.

00051 
00052     def _getTargetClass(self):
00053         from Products.CMFTopic.exportimport import TopicExportImport
00054         return TopicExportImport

def CMFTopic.tests.test_exportimport.TopicExportImportTests._makeOne (   self,
  context,
  args,
  kw 
) [private]

Definition at line 55 of file test_exportimport.py.

00055 
00056     def _makeOne(self, context, *args, **kw):
00057         return self._getTargetClass()(context, *args, **kw)

def CMFTopic.tests.test_exportimport.TopicExportImportTests._makeTopic (   self,
  id,
  with_criteria = False 
) [private]

Definition at line 58 of file test_exportimport.py.

00058 
00059     def _makeTopic(self, id, with_criteria=False):
00060         from Products.CMFTopic.Topic import Topic
00061         topic = Topic(id)
00062 
00063         if with_criteria:
00064             for field, c_type, attrs in _CRITERIA_DATA:
00065                 topic.addCriterion(field, c_type)
00066                 criterion = topic.getCriterion(field)
00067                 criterion.edit(**attrs)
00068 
00069         return topic

Here is the caller graph for this function:

Definition at line 78 of file test_exportimport.py.

00078 
00079     def test__getExportInfo_empty(self):
00080         topic = self._makeTopic('empty', False).__of__(self.root)
00081         adapter = self._makeOne(topic)
00082 
00083         info = adapter._getExportInfo()
00084         self.assertEqual(len(info['criteria']), 0)

Definition at line 103 of file test_exportimport.py.

00103 
00104     def test__getExportInfo_with_criteria(self):
00105         topic = self._makeTopic('with_criteria', True).__of__(self.root)
00106         adapter = self._makeOne(topic)
00107 
00108         info = adapter._getExportInfo()
00109         self.assertEqual(len(info['criteria']), len(_CRITERIA_DATA))
00110 
00111         for found, expected in zip(info['criteria'], _CRITERIA_DATA):
00112             attributes = expected[2]
00113             for k, v in attributes.items():
00114                 if type(v) in (list, tuple):
00115                     attributes[k] = ','.join(v)
00116 
00117             self.assertEqual(found['criterion_id'], 'crit__%s' % expected[0])
00118             self.assertEqual(found['type'], expected[1])
00119             self.assertEqual(found['field'], expected[0])
00120             self.assertEqual(dict(found['attributes']), attributes)

Definition at line 85 of file test_exportimport.py.

00085 
00086     def test_export_empty(self):
00087         topic = self._makeTopic('empty', False).__of__(self.root)
00088         adapter = self._makeOne(topic)
00089 
00090         context = DummyExportContext(topic)
00091         adapter.export(context, 'test', False)
00092 
00093         self.assertEqual( len( context._wrote ), 2 )
00094         filename, text, content_type = context._wrote[ 0 ]
00095         self.assertEqual( filename, 'test/empty/.objects' )
00096         self.assertEqual( text, '' )
00097         self.assertEqual( content_type, 'text/comma-separated-values' )
00098 
00099         filename, text, content_type = context._wrote[ 1 ]
00100         self.assertEqual( filename, 'test/empty/criteria.xml' )
00101         self._compareDOM( text, _EMPTY_TOPIC_CRITERIA )
00102         self.assertEqual( content_type, 'text/xml' )

Definition at line 163 of file test_exportimport.py.

00163 
00164     def test_export_with_date_criterion(self):
00165         topic = self._makeTopic('with_date', False).__of__(self.root)
00166         data = _CRITERIA_DATA[2]
00167         topic.addCriterion(data[0], data[1])
00168         topic.getCriterion(data[0]).edit(**data[2])
00169         adapter = self._makeOne(topic)
00170 
00171         context = DummyExportContext(topic)
00172         adapter.export(context, 'test', False)
00173 
00174         self.assertEqual( len( context._wrote ), 2 )
00175         filename, text, content_type = context._wrote[ 0 ]
00176         self.assertEqual( filename, 'test/with_date/.objects' )
00177         self.assertEqual( text, '' )
00178         self.assertEqual( content_type, 'text/comma-separated-values' )
00179 
00180         filename, text, content_type = context._wrote[ 1 ]
00181         self.assertEqual( filename, 'test/with_date/criteria.xml' )
00182         self._compareDOM( text, _DATE_TOPIC_CRITERIA )
00183         self.assertEqual( content_type, 'text/xml' )

Definition at line 142 of file test_exportimport.py.

00142 
00143     def test_export_with_integer_criterion(self):
00144         topic = self._makeTopic('with_integer', False).__of__(self.root)
00145         data = _CRITERIA_DATA[1]
00146         topic.addCriterion(data[0], data[1])
00147         topic.getCriterion(data[0]).edit(**data[2])
00148         adapter = self._makeOne(topic)
00149 
00150         context = DummyExportContext(topic)
00151         adapter.export(context, 'test', False)
00152 
00153         self.assertEqual( len( context._wrote ), 2 )
00154         filename, text, content_type = context._wrote[ 0 ]
00155         self.assertEqual( filename, 'test/with_integer/.objects' )
00156         self.assertEqual( text, '' )
00157         self.assertEqual( content_type, 'text/comma-separated-values' )
00158 
00159         filename, text, content_type = context._wrote[ 1 ]
00160         self.assertEqual( filename, 'test/with_integer/criteria.xml' )
00161         self._compareDOM( text, _INTEGER_TOPIC_CRITERIA )
00162         self.assertEqual( content_type, 'text/xml' )

Definition at line 184 of file test_exportimport.py.

00184 
00185     def test_export_with_list_criterion(self):
00186         topic = self._makeTopic('with_list', False).__of__(self.root)
00187         data = _CRITERIA_DATA[3]
00188         topic.addCriterion(data[0], data[1])
00189         topic.getCriterion(data[0]).edit(**data[2])
00190         adapter = self._makeOne(topic)
00191 
00192         context = DummyExportContext(topic)
00193         adapter.export(context, 'test', False)
00194 
00195         self.assertEqual( len( context._wrote ), 2 )
00196         filename, text, content_type = context._wrote[ 0 ]
00197         self.assertEqual( filename, 'test/with_list/.objects' )
00198         self.assertEqual( text, '' )
00199         self.assertEqual( content_type, 'text/comma-separated-values' )
00200 
00201         filename, text, content_type = context._wrote[ 1 ]
00202         self.assertEqual( filename, 'test/with_list/criteria.xml' )
00203         self._compareDOM( text, _LIST_TOPIC_CRITERIA )
00204         self.assertEqual( content_type, 'text/xml' )

Definition at line 226 of file test_exportimport.py.

00226 
00227     def test_export_with_mixed_criteria(self):
00228         topic = self._makeTopic('with_mixed', False).__of__(self.root)
00229         for index in 0, 2, 4:
00230             data = _CRITERIA_DATA[index]
00231             topic.addCriterion(data[0], data[1])
00232             topic.getCriterion(data[0]).edit(**data[2])
00233         adapter = self._makeOne(topic)
00234 
00235         context = DummyExportContext(topic)
00236         adapter.export(context, 'test', False)
00237 
00238         self.assertEqual( len( context._wrote ), 2 )
00239         filename, text, content_type = context._wrote[ 0 ]
00240         self.assertEqual( filename, 'test/with_mixed/.objects' )
00241         self.assertEqual( text, '' )
00242         self.assertEqual( content_type, 'text/comma-separated-values' )
00243 
00244         filename, text, content_type = context._wrote[ 1 ]
00245         self.assertEqual( filename, 'test/with_mixed/criteria.xml' )
00246         self._compareDOM( text, _MIXED_TOPIC_CRITERIA )
00247         self.assertEqual( content_type, 'text/xml' )

Definition at line 205 of file test_exportimport.py.

00205 
00206     def test_export_with_sort_criterion(self):
00207         topic = self._makeTopic('with_sort', False).__of__(self.root)
00208         data = _CRITERIA_DATA[4]
00209         topic.addCriterion(data[0], data[1])
00210         topic.getCriterion(data[0]).edit(**data[2])
00211         adapter = self._makeOne(topic)
00212 
00213         context = DummyExportContext(topic)
00214         adapter.export(context, 'test', False)
00215 
00216         self.assertEqual( len( context._wrote ), 2 )
00217         filename, text, content_type = context._wrote[ 0 ]
00218         self.assertEqual( filename, 'test/with_sort/.objects' )
00219         self.assertEqual( text, '' )
00220         self.assertEqual( content_type, 'text/comma-separated-values' )
00221 
00222         filename, text, content_type = context._wrote[ 1 ]
00223         self.assertEqual( filename, 'test/with_sort/criteria.xml' )
00224         self._compareDOM( text, _SORT_TOPIC_CRITERIA )
00225         self.assertEqual( content_type, 'text/xml' )

Definition at line 121 of file test_exportimport.py.

00121 
00122     def test_export_with_string_criterion(self):
00123         topic = self._makeTopic('with_string', False).__of__(self.root)
00124         data = _CRITERIA_DATA[0]
00125         topic.addCriterion(data[0], data[1])
00126         topic.getCriterion(data[0]).edit(**data[2])
00127         adapter = self._makeOne(topic)
00128 
00129         context = DummyExportContext(topic)
00130         adapter.export(context, 'test', False)
00131 
00132         self.assertEqual( len( context._wrote ), 2 )
00133         filename, text, content_type = context._wrote[ 0 ]
00134         self.assertEqual( filename, 'test/with_string/.objects' )
00135         self.assertEqual( text, '' )
00136         self.assertEqual( content_type, 'text/comma-separated-values' )
00137 
00138         filename, text, content_type = context._wrote[ 1 ]
00139         self.assertEqual( filename, 'test/with_string/criteria.xml' )
00140         self._compareDOM( text, _STRING_TOPIC_CRITERIA )
00141         self.assertEqual( content_type, 'text/xml' )

Definition at line 289 of file test_exportimport.py.

00289 
00290     def test_import_empty_with_date_criterion(self):
00291         topic = self._makeTopic('empty', False).__of__(self.root)
00292         adapter = self._makeOne(topic)
00293 
00294         context = DummyImportContext(topic, encoding='ascii')
00295         context._files['test/empty/criteria.xml'] = _DATE_TOPIC_CRITERIA
00296 
00297         adapter.import_(context, 'test', False)
00298 
00299         expected = _CRITERIA_DATA[2]
00300         found = topic.listCriteria()
00301         self.assertEqual(len(found), 1)
00302 
00303         criterion = found[0]
00304 
00305         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00306         self.assertEqual(criterion.Type(), expected[1])
00307         self.assertEqual(criterion.Field(), expected[0])
00308         self.assertEqual(criterion.value, expected[2]['value'])
00309         self.assertEqual(criterion.operation, expected[2]['operation'])
00310         self.assertEqual(criterion.daterange, expected[2]['daterange'])

Definition at line 268 of file test_exportimport.py.

00268 
00269     def test_import_empty_with_integer_criterion(self):
00270         topic = self._makeTopic('empty', False).__of__(self.root)
00271         adapter = self._makeOne(topic)
00272 
00273         context = DummyImportContext(topic, encoding='ascii')
00274         context._files['test/empty/criteria.xml'] = _INTEGER_TOPIC_CRITERIA
00275 
00276         adapter.import_(context, 'test', False)
00277 
00278         expected = _CRITERIA_DATA[1]
00279         found = topic.listCriteria()
00280         self.assertEqual(len(found), 1)
00281 
00282         criterion = found[0]
00283 
00284         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00285         self.assertEqual(criterion.Type(), expected[1])
00286         self.assertEqual(criterion.Field(), expected[0])
00287         self.assertEqual(criterion.value, expected[2]['value'])
00288         self.assertEqual(criterion.direction, expected[2]['direction'])

Definition at line 311 of file test_exportimport.py.

00311 
00312     def test_import_empty_with_list_criterion(self):
00313         topic = self._makeTopic('empty', False).__of__(self.root)
00314         adapter = self._makeOne(topic)
00315 
00316         context = DummyImportContext(topic, encoding='ascii')
00317         context._files['test/empty/criteria.xml'] = _LIST_TOPIC_CRITERIA
00318 
00319         adapter.import_(context, 'test', False)
00320 
00321         expected = _CRITERIA_DATA[3]
00322         found = topic.listCriteria()
00323         self.assertEqual(len(found), 1)
00324 
00325         criterion = found[0]
00326 
00327         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00328         self.assertEqual(criterion.Type(), expected[1])
00329         self.assertEqual(criterion.Field(), expected[0])
00330         self.assertEqual(','.join(criterion.value), expected[2]['value'])
00331         self.assertEqual(criterion.operator, expected[2]['operator'])

Definition at line 353 of file test_exportimport.py.

00353 
00354     def test_import_empty_with_mixed_criterion(self):
00355         topic = self._makeTopic('empty', False).__of__(self.root)
00356         adapter = self._makeOne(topic)
00357 
00358         context = DummyImportContext(topic, encoding='ascii')
00359         context._files['test/empty/criteria.xml'] = _MIXED_TOPIC_CRITERIA
00360 
00361         adapter.import_(context, 'test', False)
00362 
00363         found = topic.listCriteria()
00364         self.assertEqual(len(found), 3)
00365 
00366         criterion = found[0]
00367         expected = _CRITERIA_DATA[0]
00368 
00369         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00370         self.assertEqual(criterion.Type(), expected[1])
00371         self.assertEqual(criterion.Field(), expected[0])
00372         self.assertEqual(criterion.value, expected[2]['value'])
00373 
00374         criterion = found[1]
00375         expected = _CRITERIA_DATA[2]
00376 
00377         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00378         self.assertEqual(criterion.Type(), expected[1])
00379         self.assertEqual(criterion.Field(), expected[0])
00380         self.assertEqual(criterion.value, expected[2]['value'])
00381         self.assertEqual(criterion.operation, expected[2]['operation'])
00382         self.assertEqual(criterion.daterange, expected[2]['daterange'])
00383 
00384         criterion = found[2]
00385         expected = _CRITERIA_DATA[4]
00386 
00387         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00388         self.assertEqual(criterion.Type(), expected[1])
00389         self.assertEqual(criterion.field, None)
00390         self.assertEqual(criterion.index, expected[0])
00391         self.assertEqual(criterion.reversed, bool(expected[2]['reversed']))

Definition at line 332 of file test_exportimport.py.

00332 
00333     def test_import_empty_with_sort_criterion(self):
00334         topic = self._makeTopic('empty', False).__of__(self.root)
00335         adapter = self._makeOne(topic)
00336 
00337         context = DummyImportContext(topic, encoding='ascii')
00338         context._files['test/empty/criteria.xml'] = _SORT_TOPIC_CRITERIA
00339 
00340         adapter.import_(context, 'test', False)
00341 
00342         expected = _CRITERIA_DATA[4]
00343         found = topic.listCriteria()
00344         self.assertEqual(len(found), 1)
00345 
00346         criterion = found[0]
00347 
00348         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00349         self.assertEqual(criterion.Type(), expected[1])
00350         self.assertEqual(criterion.field, None)
00351         self.assertEqual(criterion.index, expected[0])
00352         self.assertEqual(criterion.reversed, bool(expected[2]['reversed']))

Definition at line 248 of file test_exportimport.py.

00248 
00249     def test_import_empty_with_string_criterion(self):
00250         topic = self._makeTopic('empty', False).__of__(self.root)
00251         adapter = self._makeOne(topic)
00252 
00253         context = DummyImportContext(topic, encoding='ascii')
00254         context._files['test/empty/criteria.xml'] = _STRING_TOPIC_CRITERIA
00255 
00256         adapter.import_(context, 'test', False)
00257 
00258         expected = _CRITERIA_DATA[0]
00259         found = topic.listCriteria()
00260         self.assertEqual(len(found), 1)
00261 
00262         criterion = found[0]
00263 
00264         self.assertEqual(criterion.getId(), 'crit__%s' % expected[0])
00265         self.assertEqual(criterion.Type(), expected[1])
00266         self.assertEqual(criterion.Field(), expected[0])
00267         self.assertEqual(criterion.value, expected[2]['value'])

Definition at line 405 of file test_exportimport.py.

00405 
00406     def test_import_with_purge_removes_existing_criteria(self):
00407 
00408         topic = self._makeTopic('with_criteria', True).__of__(self.root)
00409         adapter = self._makeOne(topic)
00410 
00411         context = DummyImportContext(topic, purge=True)
00412         context._files['test/with_criteria/criteria.xml'
00413                       ] = _EMPTY_TOPIC_CRITERIA
00414 
00415         self.assertEqual(len(topic.listCriteria()), len(_CRITERIA_DATA))
00416         adapter.import_(context, 'test', False)
00417         self.assertEqual(len(topic.listCriteria()), 0)

Definition at line 392 of file test_exportimport.py.

00392 
00393     def test_import_without_purge_leaves_existing_criteria(self):
00394 
00395         topic = self._makeTopic('with_criteria', True).__of__(self.root)
00396         adapter = self._makeOne(topic)
00397 
00398         context = DummyImportContext(topic, purge=False)
00399         context._files['test/with_criteria/criteria.xml'
00400                       ] = _EMPTY_TOPIC_CRITERIA
00401 
00402         self.assertEqual(len(topic.listCriteria()), len(_CRITERIA_DATA))
00403         adapter.import_(context, 'test', False)
00404         self.assertEqual(len(topic.listCriteria()), len(_CRITERIA_DATA))

Definition at line 70 of file test_exportimport.py.

00070 
00071     def test_listExportableItems(self):
00072         topic = self._makeTopic('lEI', False).__of__(self.root)
00073         adapter = self._makeOne(topic)
00074 
00075         self.assertEqual(len(adapter.listExportableItems()), 0)
00076         topic.addCriterion('field_a', 'String Criterion')
00077         self.assertEqual(len(adapter.listExportableItems()), 0)


Member Data Documentation

Definition at line 49 of file test_exportimport.py.


The documentation for this class was generated from the following file: