## $Id: test_applicantcopier.py 13977 2016-06-23 07:25:56Z henrik $
##
## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
## This program is free software; you can redistribute it and/or modify
## it under the terms of the GNU General Public License as published by
## the Free Software Foundation; either version 2 of the License, or
## (at your option) any later version.
##
## This program is distributed in the hope that it will be useful,
## but WITHOUT ANY WARRANTY; without even the implied warranty of
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
## GNU General Public License for more details.
##
## You should have received a copy of the GNU General Public License
## along with this program; if not, write to the Free Software
## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
##
"""
Tests for the creation of student containers with data from admitted applicants.
"""
import os
import grok
from datetime import datetime
from hurry.workflow.interfaces import IWorkflowInfo, IWorkflowState
from zope.event import notify
from zope.component import getUtility
from zope.i18n import translate
from waeup.kofa.interfaces import IExtFileStore, IFileStoreNameChooser
from waeup.kofa.applicants.tests.test_browser import ApplicantsFullSetup
from waeup.aaue.testing import FunctionalLayer

session = datetime.now().year - 2

class ApplicantCopierFunctionalTests(ApplicantsFullSetup):

    layer = FunctionalLayer

    def setUp(self):
        super(ApplicantCopierFunctionalTests, self).setUp()
        return

    def test_copier(self):
        IWorkflowState(self.applicant).setState('admitted')
        self.browser.addHeader('Authorization', 'Basic mgr:mgrpw')
        self.browser.open(self.manage_path)
        self.fill_correct_values()
        self.browser.getControl("Save").click()
        self.browser.getControl(name="form.nationality").value = ['NG']
        self.browser.getControl(name="form.lga").value = ['abia_aba_north']
        self.browser.getControl(name="form.course_admitted").value = ['CERT1']
        #self.browser.getControl(name="form.programme_type").value = ['regular']
        # Date of birth is not required
        self.browser.getControl(name="form.date_of_birth").value = ''

        self.browser.getControl(name="form.fst_sit_fname").value = 'Alfons'
        self.browser.getControl(name="form.fst_sit_no").value = '123'
        self.browser.getControl(name="form.fst_sit_type").value = ['ssce']
        self.browser.getControl(name="form.scd_sit_fname").value = 'John'
        self.browser.getControl(name="form.scd_sit_no").value = '456'
        self.browser.getControl(name="form.scd_sit_type").value = ['waec']
        self.browser.getControl(name="form.alr_fname").value = 'Uli'
        self.browser.getControl(name="form.alr_no").value = '345'

        self.browser.getControl("Save").click()
        (success, msg) = self.applicant.createStudent()
        student_id = translate(msg, 'waeup.kofa').split()[1]
        student = self.app['students'][student_id]
        self.assertEqual(student.state, 'admitted')

        # Has the student the correct attributes?
        self.assertEqual(student.fst_sit_fname, 'Alfons')
        self.assertEqual(student.fst_sit_no, '123')
        self.assertEqual(student.fst_sit_type, 'ssce')
        self.assertEqual(student.scd_sit_fname, 'John')
        self.assertEqual(student.scd_sit_no, '456')
        self.assertEqual(student.scd_sit_type, 'waec')
        self.assertEqual(student.alr_fname, 'Uli')
        self.assertEqual(student.alr_no, '345')
