Changeset 4391


Ignore:
Timestamp:
2 Jul 2009, 09:53:15 (15 years ago)
Author:
uli
Message:

Move existing CSV importer tests to new module tests.

Location:
waeup/branches/ulif-rewrite/src/waeup
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • waeup/branches/ulif-rewrite/src/waeup/university/facultycontainer.txt

    r4232 r4391  
    6969know before.
    7070
    71 Importing from CSV files
    72 ------------------------
    73 
    74 We create a facultycontainer, which we want to populate with some CSV
    75 data afterwards:
    76 
    77     >>> from waeup.university.facultycontainer import FacultyContainer
    78     >>> mycontainer = FacultyContainer()
    79 
    80 Next, we create a CSV file we want to import:
    81 
    82     >>> open('myfaculties.csv', 'wb').write(
    83     ... """code,review_state,title,title_prefix
    84     ... AGR,static,Agriculture,faculty
    85     ... ART,static,Arts,faculty
    86     ... DEN,static,Dentistry,faculty
    87     ... """)
    88 
    89 We get a suitable importer by asking for a multi-adapter to
    90 our file and IWAeUPCSVExporter (see section above, the importexport
    91 module and the `waeup.csvfile` README for details):
    92 
    93     >>> from waeup.csvfile import getCSVFile
    94     >>> from waeup.interfaces import IWAeUPCSVImporter
    95     >>> from zope.component import getMultiAdapter
    96     >>> importer = getMultiAdapter((getCSVFile('myfaculties.csv'),
    97     ...                             mycontainer),
    98     ...                            IWAeUPCSVImporter)
    99     >>> importer
    100     <waeup.university.facultycontainer.FacultyCSVImporter object at 0x...>
    101 
    102 This importer complies with the IWAeUPCSVImporter interface:
    103 
    104     >>> from waeup.university.facultycontainer import FacultyCSVImporter
    105     >>> IWAeUPCSVImporter.implementedBy(FacultyCSVImporter)
    106     True
    107 
    108     >>> from zope.interface.verify import verifyClass
    109     >>> verifyClass(IWAeUPCSVImporter, FacultyCSVImporter)
    110     True
    111 
    112 The container is still empty:
    113 
    114     >>> len(mycontainer)
    115     0
    116 
    117 Now we can easily import the data:
    118 
    119     >>> importer.doImport()
    120 
    121 The container is now filled:
    122 
    123     >>> len(mycontainer)
    124     3
    125 
    126     >>> print [(x.code, x.title) for x in list(mycontainer.values())]
    127     [('AGR', 'Agriculture'), ('ART', 'Arts'), ('DEN', 'Dentistry')]
    128 
    129 
    130 Clean up:
    131 
    132     >>> import os
    133     >>> os.unlink('myfaculties.csv')
Note: See TracChangeset for help on using the changeset viewer.