Ejemplo n.º 1
0
class Test_SchoolSched_create_secondary_objects_type(unittest.TestCase):
    
    # test that when a lesson object is created, all other records
    # that are new are created by asserting that the values are of
    # the correct object type

    def setUp(self):
        self.database = Database('htmlparser',True)
        self.of = ObjFactory(True)
    
    def test_(self):
        
        _dm = _cdict(['schedule_num','day_num','period_num','student_num'],[1,0,1,0])
    
        datamembers = _initdatamembers('lesson',**_dm)
    
        _enrich('QUAD CAFE',datamembers)
        
        _lesson_create(datamembers,self.database,self.of)

        attr_list = [(obj, obj.objtype) for obj in self.of.object_iter()]

        for obj in self.of.object_iter():
            self.assertTrue(isinstance(obj,eval(obj.objtype)))
            
        with self.database:
            pass
class Test_ObjFrameworkIter(unittest.TestCase):

    def setUp(self):
        self.of = ObjFactory(True)
        self.of.new(GenericBase,
                    'Student',
                    objid='booker',
                    modname=__name__)
        
        self.of.new(GenericBase,
                    'Student',
                    objid='fred',
                    modname=__name__)
        
        self.of.new(GenericBase,
                    'Classroom',
                    objid='1a',
                    modname=__name__)
        

    def tearDown(self):
        self.of.reset()
        
    def test_iter(self):
        result = [obj.objid for obj in self.of.object_iter()]
        result.sort()
        
        self.assertListEqual(result,['1a','booker','fred'])
Ejemplo n.º 3
0
class Test_SchoolSched_create_secondary_objects_with_teacher(unittest.TestCase):
    
    # test that when a lesson object is created, all other records
    # that are new are created by asserting the contents of the
    # objfactory store

    def setUp(self):
        self.database = Database('htmlparser')
        self.of = ObjFactory(True)
    
    def test_(self):
        
        _dm = _cdict(['schedule_num','day_num','period_num','student_num'],[1,0,1,0])
    
        datamembers = _initdatamembers('lesson',**_dm)
    
        _enrich('Science WP With: Kayla',datamembers)

        #exp_res = [('None','teacher'),
                   
        exp_res =  [('KAYLA','teacher'),
                    ('9:11-9:51','period'),
                   ('NATHANIEL','student'),
                   ('Monday','dow'),
                   ('1.0.1','lesson'),
                   ('wp','lessontype'),
                   ('SCIENCE','subject')]


        _lesson_create(datamembers,self.database,self.of)

        attr_list = [(obj.userdefid, obj.objtype) for obj in self.of.object_iter() if obj.objtype not in ['objtype','userdefid']]

        attr_list.sort()
        exp_res.sort()
        
        #_pprint(exp_res,attr_list)
        self.assertListEqual(attr_list,exp_res)
Ejemplo n.º 4
0
class Test_SchoolSched_persist_multi(unittest.TestCase):

    # test that a lesson object is persisted to the db correctly
    # by asserting the fields written into the database table
    def setUp(self):
        self.database = Database('htmlparser')
        self.of = ObjFactory(True)
        
        self._create('Math WP With: Moira', [1,2,7,0])
        self._create('HUMANITIES',[1,4,9,0])
        self._create('Math WP With: Moira',[1,2,3,0])
        self._persist()

    def _create(self,lessonname,params):
        
        _dm = _cdict(['schedule_num','day_num','period_num','student_num'],params)
        datamembers = _initdatamembers('lesson',**_dm)
        _enrich(lessonname,datamembers)
        
        _lesson_create(datamembers,self.database,self.of)

    def _persist(self):
        
        with self.database:
            for obj in self.of.object_iter():
                obj.persist()
            
    def test_persist_multi_lesson(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'lesson'),3)
            
    def test_persist_multi_teacher(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'teacher'),1)
            _,rowvals = tbl_rows_get(self.database,'teacher',['userdefid'])
                 
        self.assertListEqual(rowvals,[['MOIRA']])
            
    def test_persist_multi_subject(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'subject'),2)
            _,rowvals = tbl_rows_get(self.database,'subject',['userdefid'])
        
        rowvals.sort()         
        self.assertListEqual(rowvals,[['HUMANITIES'],['MATH']])
            
    def test_persist_multi_dow(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'dow'),2)
            _,rowvals = tbl_rows_get(self.database,'dow',['userdefid'])
        
        rowvals.sort()   
        self.assertListEqual(rowvals,[['Friday'],['Wednesday']])
        
    def test_persist_multi_period(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'period'),3)
            _,rowvals = tbl_rows_get(self.database,'period',['userdefid'])
        
        rowvals.sort()
        self.assertListEqual(rowvals,[['10:33-11:13'],['1:07-1:47'],['2:30-3:00']])
            
    def test_persist_multi_student(self):
        self.database = Database('htmlparser',True)
        with self.database:
            self.assertEquals(tbl_count_get(self.database,'student'),1)
            _,rowvals = tbl_rows_get(self.database,'student',['userdefid'])
                 
        self.assertListEqual(rowvals,[['NATHANIEL']])