Ignore:
Timestamp:
15 May 2024, 06:42:58 (6 months ago)
Author:
Henrik Bettermann
Message:

Add SessionConfigurationProcessor.
Add ConfigurationContainerProcessor.
Add ConfigurationContainerExporter.

Location:
main/waeup.kofa/trunk/src/waeup/kofa/tests
Files:
2 added
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/src/waeup/kofa/tests/test_configuration.py

    r17782 r17787  
    3030from waeup.kofa.configuration import (
    3131    ConfigurationContainer, SessionConfiguration, SessionConfigurationFactory,
    32     ConfigurationContainerExporter, ConfigurationExporter)
    33 from waeup.kofa.interfaces import(ICSVExporter,
     32    ConfigurationContainerExporter, SessionConfigurationExporter,
     33    ConfigurationContainerProcessor, SessionConfigurationProcessor)
     34from waeup.kofa.interfaces import(ICSVExporter, IBatchProcessor,
    3435    IConfigurationContainer, ISessionConfiguration, ISessionConfigurationAdd)
    3536
     
    124125        result = open(self.outfile, 'rb').read()
    125126        self.assertTrue(
    126             'acronym,captcha,carry_over,current_academic_session,email_admin,'
    127             'email_subject,export_disabled_message,frontpage,frontpage_dict,'
     127            'acronym,carry_over,current_academic_session,email_admin,'
     128            'email_subject,export_disabled_message,frontpage,'
    128129            'maintmode_enabled_by,name,name_admin,next_matric_integer,'
    129130            'next_matric_integer_2,next_matric_integer_3,'
    130131            'next_matric_integer_4,smtp_mailer,curr_stud_id\r\n'
    131             'WAeUP.Kofa,No captcha,0,,contact@waeup.org,Kofa Contact,,'
     132            'WAeUP.Kofa,0,,contact@waeup.org,Kofa Contact,,'
    132133            '"<h1>Welcome to WAeUP.Kofa\n<br>' in result
    133134            )
     
    138139    def test_ifaces(self):
    139140        # make sure we fullfill interface contracts
    140         obj = ConfigurationExporter()
     141        obj = SessionConfigurationExporter()
    141142        verify.verifyObject(ICSVExporter, obj)
    142         verify.verifyClass(ICSVExporter, ConfigurationExporter)
     143        verify.verifyClass(ICSVExporter, SessionConfigurationExporter)
    143144        return
    144145
    145146    def test_get_as_utility(self):
    146147        # we can get a faculty exporter as utility
    147         result = queryUtility(ICSVExporter, name="configurations")
     148        result = queryUtility(ICSVExporter, name="sessionconfigurations")
    148149        self.assertTrue(result is not None)
    149150        return
     
    154155        self.sessionconfig.clearance_fee = 3000.6
    155156        self.app['configuration'].addSessionConfiguration(self.sessionconfig)
    156         exporter = ConfigurationExporter()
     157        exporter = SessionConfigurationExporter()
    157158        exporter.export_all(self.app, self.outfile)
    158159        result = open(self.outfile, 'rb').read()
     
    164165            )
    165166        return
     167
     168BASECONFIG_SAMPLE_DATA = open(
     169    os.path.join(os.path.dirname(__file__), 'sample_baseconfig_data.csv'),
     170    'rb').read()
     171
     172BASECONFIG_HEADER_FIELDS = BASECONFIG_SAMPLE_DATA.split(
     173    '\n')[0].split(',')
     174
     175class BaseConfigurationProcessorTests(ConfigurationImportExportSetup):
     176
     177    layer = FunctionalLayer
     178
     179    def setUp(self):
     180        super(BaseConfigurationProcessorTests, self).setUp()
     181        self.processor = ConfigurationContainerProcessor()
     182
     183    def test_interface(self):
     184        # Make sure we fulfill the interface contracts.
     185        assert verify.verifyObject(IBatchProcessor, self.processor) is True
     186        assert verify.verifyClass(
     187            IBatchProcessor, ConfigurationContainerProcessor) is True
     188
     189    def test_import(self):
     190        self.csv_file = os.path.join(
     191            self.workdir, 'sample_baseconfig_data.csv')
     192        open(self.csv_file, 'wb').write(BASECONFIG_SAMPLE_DATA)
     193        num, num_warns, fin_file, fail_file = self.processor.doImport(
     194            self.csv_file, BASECONFIG_HEADER_FIELDS,'update')
     195        self.assertEqual(num_warns,0)
     196        configcontainer = self.processor.getEntry(dict(), self.app)
     197        self.assertEqual(configcontainer.frontpage, 'Hello World')
     198
     199SESSIONCONFIG_SAMPLE_DATA = open(
     200    os.path.join(os.path.dirname(__file__), 'sample_sessionconfig_data.csv'),
     201    'rb').read()
     202
     203SESSIONCONFIG_HEADER_FIELDS = SESSIONCONFIG_SAMPLE_DATA.split(
     204    '\n')[0].split(',')
     205
     206class SessionConfigurationProcessorTests(ConfigurationImportExportSetup):
     207
     208    layer = FunctionalLayer
     209
     210    def setUp(self):
     211        super(SessionConfigurationProcessorTests, self).setUp()
     212        self.processor = SessionConfigurationProcessor()
     213
     214    def test_interface(self):
     215        # Make sure we fulfill the interface contracts.
     216        assert verify.verifyObject(IBatchProcessor, self.processor) is True
     217        assert verify.verifyClass(
     218            IBatchProcessor, SessionConfigurationProcessor) is True
     219
     220    def test_import(self):
     221        self.csv_file = os.path.join(
     222            self.workdir, 'sample_sessionconfig_data.csv')
     223        open(self.csv_file, 'wb').write(SESSIONCONFIG_SAMPLE_DATA)
     224        num, num_warns, fin_file, fail_file = self.processor.doImport(
     225            self.csv_file, SESSIONCONFIG_HEADER_FIELDS,'create')
     226        self.assertEqual(num_warns,0)
     227        sessionconfig = self.processor.getEntry({'academic_session':'2017'}, self.app)
     228        self.assertEqual(sessionconfig.payment_disabled[0], 'sf_all')
     229
     230
Note: See TracChangeset for help on using the changeset viewer.