Changeset 7633


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

Add catalogs (indexes) for payments and course tickets.

Location:
main/waeup.sirp/trunk/src/waeup/sirp/students
Files:
4 edited

Legend:

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

    r7369 r7633  
    2626from waeup.sirp.interfaces import (
    2727    IUniversity, IQueryResultItem, academic_sessions_vocab)
    28 from waeup.sirp.students.interfaces import IStudent
     28from waeup.sirp.students.interfaces import (IStudent, ICourseTicket,
     29    IStudentOnlinePayment)
    2930from waeup.sirp.university.vocabularies import course_levels
    3031
     
    115116#: an instance of `SimpleFieldSearch` looking up students catalog.
    116117simple_search = SimpleFieldSearch()
     118
     119class CourseTicketIndexes(grok.Indexes):
     120    """A catalog for course tickets.
     121    """
     122    grok.site(IUniversity)
     123    grok.name('coursetickets_catalog')
     124    grok.context(ICourseTicket)
     125
     126    level = index.Field(attribute='getLevel')
     127    session = index.Field(attribute='getLevelSession')
     128    code = index.Field(attribute='code')
     129
     130class StudentPaymentIndexes(grok.Indexes):
     131    """A catalog for payments.
     132    """
     133    grok.site(IUniversity)
     134    grok.name('payments_catalog')
     135    grok.context(IStudentOnlinePayment)
     136
     137    p_session = index.Field(attribute='p_session')
     138    p_category = index.Field(attribute='p_category')
     139    p_item = index.Field(attribute='p_item')
     140    p_state = index.Field(attribute='p_state')
     141    r_pay_reference = index.Text(attribute='r_pay_reference')
  • main/waeup.sirp/trunk/src/waeup/sirp/students/interfaces.py

    r7620 r7633  
    377377        )
    378378
     379    def getLevel():
     380        """Returns the id of the level the ticket has been added to.
     381        """
     382
     383    def getLevelSession():
     384        """Returns the session of the level the ticket has been added to.
     385        """
     386
    379387class ICourseTicketAdd(ICourseTicket):
    380388    """An interface for adding course tickets.
     
    434442
    435443    def getSessionString():
    436         """Returns the the title of academic_sessions_vocab term.
     444        """Returns the title of academic_sessions_vocab term.
    437445
    438446        """
  • main/waeup.sirp/trunk/src/waeup/sirp/students/studylevel.py

    r7549 r7633  
    100100        return self.__parent__.__parent__.__parent__
    101101
     102    def getLevel(self):
     103        """Returns the id of the level the ticket has been added to.
     104        """
     105        return self.__parent__.level
     106
     107    def getLevelSession(self):
     108        """Returns the session of the level the ticket has been added to.
     109        """
     110        return self.__parent__.level_session
     111
     112
    102113CourseTicket = attrs_to_fields(CourseTicket)
    103114
  • 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.