Ignore:
Timestamp:
11 Feb 2012, 23:02:24 (13 years ago)
Author:
Henrik Bettermann
Message:

Add catalogs (indexes) for payments and course tickets.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/students/tests/test_catalog.py

    r7357 r7633  
    2626from waeup.sirp.testing import FunctionalLayer, FunctionalTestCase
    2727from waeup.sirp.students.student import Student
     28from waeup.sirp.students.studylevel import StudentStudyLevel, CourseTicket
    2829from waeup.sirp.university.faculty import Faculty
    2930from waeup.sirp.university.department import Department
    3031
    3132class CatalogTestSetup(FunctionalTestCase):
    32     # A setup for testing students catalog related stuff.
     33    # A setup for testing catalog related stuff.
    3334    #
    3435    # sets up a site with some student already created.
     
    5455            self.certificate)
    5556
    56         # Create student with studycourse subobject
     57        # Create student with subobjects
    5758        student = Student()
    5859        student.firstname = u'Bob'
     
    6263        self.student = self.app['students'][self.student_id]
    6364        self.student['studycourse'].certificate = self.certificate
    64         # Update the catalog
     65        # Update the students_catalog
    6566        notify(grok.ObjectModifiedEvent(self.student))
     67        studylevel = StudentStudyLevel()
     68        studylevel.level = 100
     69        studylevel.level_session = 2010
     70        self.student['studycourse']['100'] = studylevel
     71        ticket = CourseTicket()
     72        ticket.code = 'Course1'
     73        self.student['studycourse']['100']['Course1'] = ticket
     74        payment = createObject(u'waeup.StudentOnlinePayment')
     75        payment.p_id = 'p1234567890'
     76        payment.p_item = u'any item'
     77        payment.p_session = 2010
     78        payment.p_category = 'schoolfee'
     79        payment.p_state = 'paid'
     80        payment.r_pay_reference = u'GTB|WEB|FUT'
     81        self.student['payments'][payment.p_id] = payment
    6682        return
    6783
     
    111127        assert len(results) == 1
    112128        assert results[0] is self.app['students'][self.student_id]
     129
     130class CourseTicketCatalogTests(CatalogTestSetup):
     131
     132    layer = FunctionalLayer
     133
     134    def test_get_catalog(self):
     135        # We can get an students catalog if we wish
     136        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     137        assert cat is not None
     138
     139    def test_search_by_code(self):
     140        # We can find a certain course ticket by its code
     141        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     142        results = cat.searchResults(code=('Course1', 'Course1'))
     143        results = [x for x in results] # Turn results generator into list
     144        assert len(results) == 1
     145        assert results[0] is self.app['students'][self.student_id][
     146            'studycourse']['100']['Course1']
     147
     148    def test_search_by_level(self):
     149        # We can find a certain course ticket by the level
     150        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     151        results = cat.searchResults(level=(100, 100))
     152        results = [x for x in results] # Turn results generator into list
     153        assert len(results) == 1
     154        assert results[0] is self.app['students'][self.student_id][
     155            'studycourse']['100']['Course1']
     156
     157    def test_search_by_session(self):
     158        # We can find a certain course ticket by the level session
     159        cat = queryUtility(ICatalog, name='coursetickets_catalog')
     160        results = cat.searchResults(session=(2010, 2010))
     161        results = [x for x in results] # Turn results generator into list
     162        assert len(results) == 1
     163        assert results[0] is self.app['students'][self.student_id][
     164            'studycourse']['100']['Course1']
     165
     166class PaymentCatalogTests(CatalogTestSetup):
     167
     168    layer = FunctionalLayer
     169
     170    def test_get_catalog(self):
     171        # We can get an students catalog if we wish
     172        cat = queryUtility(ICatalog, name='payments_catalog')
     173        assert cat is not None
     174
     175    def test_search_by_session(self):
     176        # We can find a payment ticket by the payment session
     177        cat = queryUtility(ICatalog, name='payments_catalog')
     178        results = cat.searchResults(p_session=(2010, 2010))
     179        results = [x for x in results] # Turn results generator into list
     180        assert len(results) == 1
     181        assert results[0] is self.app['students'][self.student_id][
     182            'payments']['p1234567890']
     183
     184    def test_search_by_category(self):
     185        # We can find a payment ticket by the payment category
     186        cat = queryUtility(ICatalog, name='payments_catalog')
     187        results = cat.searchResults(p_category=('schoolfee','schoolfee'))
     188        results = [x for x in results] # Turn results generator into list
     189        assert len(results) == 1
     190        assert results[0] is self.app['students'][self.student_id][
     191            'payments']['p1234567890']
     192
     193    def test_search_by_item(self):
     194        # We can find a payment ticket by the payment item
     195        cat = queryUtility(ICatalog, name='payments_catalog')
     196        results = cat.searchResults(p_item=('any item','any item'))
     197        results = [x for x in results] # Turn results generator into list
     198        assert len(results) == 1
     199        assert results[0] is self.app['students'][self.student_id][
     200            'payments']['p1234567890']
     201
     202    def test_search_by_state(self):
     203        # We can find a payment ticket by the payment state
     204        cat = queryUtility(ICatalog, name='payments_catalog')
     205        results = cat.searchResults(p_state=('paid','paid'))
     206        results = [x for x in results] # Turn results generator into list
     207        assert len(results) == 1
     208        assert results[0] is self.app['students'][self.student_id][
     209            'payments']['p1234567890']
     210
     211    def test_search_by_reference(self):
     212        # We can find a payment ticket by parts of the response reference
     213        cat = queryUtility(ICatalog, name='payments_catalog')
     214        results = cat.searchResults(r_pay_reference='GTB')
     215        results = [x for x in results] # Turn results generator into list
     216        assert len(results) == 1
     217        assert results[0] is self.app['students'][self.student_id][
     218            'payments']['p1234567890']
Note: See TracChangeset for help on using the changeset viewer.