class Test_ObjFrameworkDumpRpt(unittest.TestCase): def setUp(self): self.of = ObjFactory(True) self.obj1 = self.of.new(GenericBase, 'Student', objid='booker', nationality='british', modname=__name__) def test_no_datafields(self): from types import StringType,IntType, UnicodeType expected_results = [['ROOT', 'Student']] results = self.of.dumpobjrpt(objref=False) expected_results.sort() results.sort() self.assertListEqual(expected_results,results) def test_inc_datafields(self): from types import StringType,IntType, UnicodeType expected_results = [['ROOT', 'british', 'Student']] results = self.of.dumpobjrpt(fields=['nationality'],objref=False) expected_results.sort() results.sort() self.assertListEqual(expected_results,results)
class Test_ObjFramework_2_records_same_cls(unittest.TestCase): def setUp(self): self.of = ObjFactory() self.obj1= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__, name='booker', age=23) self.obj2= self.of.new(GenericBase, 'Student', objid='frank', modname=__name__, name='frank', age=19) def tearDown(self): self.of.reset() def test_2records_same_class(self): names = [obj.name for obj in self.of.query('Student')] names.sort() self.assertEquals(names,['booker','frank'])
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_ObjFrameworkBasic(unittest.TestCase): def setUp(self): self.of = ObjFactory() foobar= self.of.new(GenericBase, "Student", objid='booker', modname=__name__, name='booker', age=23) def tearDown(self): self.of.reset() def test_num_obj_created(self): self.assertEquals(len(ObjFactory().store['Student']),1) def test_correct_keys_created(self): self.assertTrue(ObjFactory().store['Student'].has_key('booker')) def test_objects_created_stored(self): _student = ObjFactory().store['Student']['booker'] self.assertEquals(_student.__class__.__name__,"Student") def test_objects_have_attributes(self): _student = ObjFactory().store['Student']['booker'] self.assertEquals(_student.name,'booker') self.assertEquals(_student.age,23)
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'])
class Test_ObjFrameworkDumpNested(unittest.TestCase): def setUp(self): self.of = ObjFactory(True) self.obj1 = self.of.new(GenericBase, 'Student', objid='booker', nationality='british', modname=__name__) self.of.new(GenericBase, 'Student', objid='fred', age=23, nationality='british', modname=__name__) self.of.new(GenericBase, 'Student', objid='fred', age=35, nationality='irish', modname=__name__) self.of.new(GenericBase, 'Classroom', objid='1a', nationality='swedish', modname=__name__) def tearDown(self): self.of.reset() '''def test_1clause(self): results = self.of.query_advanced('Student',[('objid','booker')]) self.assertEquals(len(results),1) self.assertEquals(results[0].objid,'booker') def test_2clause(self): results = self.of.query_advanced('Student',[('nationality','british'), ('objid','fred')]) self.assertEquals(len(results),1) self.assertEquals(results[0].age,23)''' def test_update_then_search(self): ''' make sure that search picks up the updated version of the object ''' self.obj1.nationality = 'indian' results = self.of.query_advanced('Student',[('objid','booker')]) self.assertEquals(results[0].nationality,'indian')
class Test_update(unittest.TestCase): def setUp(self): self.dbname='test_ssviewer_util_add' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database,refdatabase=self.database,saveversion=1, of=self.of,enums=self.enums,keepversion=True) ssviewer_utils.dataset_load(**args) def test_update_subject(self): expected_results = [[u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement'], [u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'ELA']] obj = self.of.query_advanced("lesson",[('period','830-910'), ('dow','WE')]) obj[0].update(self.of,'subject','ELA') with self.database: _,rows,_ = tbl_rows_get(self.database,"lesson", fields = ['status', 'substatus', 'recordtype', 'period', 'dow', 'source', 'session', 'teacher', 'student', 'prep', 'userobjid', 'subject'], whereclause = [["period","=","\"830-910\""], ["dow","=","\"WE\""]]) self.assertListEqual(rows,expected_results) def test_update_adult(self): expected_results = [[u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement'], [u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'Amelia', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement']] obj = self.of.query_advanced("lesson",[('period','830-910'), ('dow','WE')]) obj[0].update(self.of,'teacher','Amelia') with self.database: _,rows,_ = tbl_rows_get(self.database,"lesson", fields = ['status', 'substatus', 'recordtype', 'period', 'dow', 'source', 'session', 'teacher', 'student', 'prep', 'userobjid', 'subject'], whereclause = [["period","=","\"830-910\""], ["dow","=","\"WE\""]]) self.assertListEqual(rows,expected_results) def tearDown(self): shutil.copyfile(self.dbname+".sqlite.backup",self.dbname + ".sqlite")
class Test_ObjFrameworkDumpRptNestedSchoolschedFieldNameHdr(unittest.TestCase): # same as above just with the school sched nested object # so each attr is another object of (not a string or int) that # potentially needs to be accessed via accessors def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') datamembers = dict(period='830-910',student='Booker',dow='MO', teacher='Amelia',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson0',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='910-950',student='Booker',dow='MO', teacher='Stan',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson1',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='950-1020',student='Booker',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson2',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='830-910',student='Clayton',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson3',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) def test_1constraint(self): from types import StringType,IntType, UnicodeType expected_results = [['ROOT', 'student:Booker', 'period:830-910', 'objtype:DBLesson'], ['ROOT', 'student:Clayton', 'period:830-910', 'objtype:DBLesson']] results = self.of.dumpobjrpt(objtypes=['DBLesson'], objref=False, fields=['student','period'], omitfields=['id'], fieldnames=True) expected_results.sort() results.sort() self.assertListEqual(expected_results,results) self.assertListEqual(expected_results,results)
class Test_SchoolSched_schdule_load_1lesson(unittest.TestCase): def setUp(self): self.database = Database('htmlparser') self.of = ObjFactory(True) f = "/home/burtnolej/Development/pythonapps3/clean/apps/schoolscheduler/schedule.html" self.schedule = htmlschedule_slice(f,num_periods=1,num_students=1,num_days=1) schedule_load(self.schedule, self.of, self.database) def test_schdload_lesson(self): schedule_load(self.schedule, self.of, self.database) exp_res = ['0.0.0'] exp_res.sort() _res = self.of.query('lesson') _resstr = [str(_r) for _r in _res] _resstr.sort() self.assertListEqual(exp_res, _resstr) def test_schdload_subject(self): schedule_load(self.schedule, self.of, self.database) _res = self.of.query('subject') _resstr = [str(_r) for _r in _res] _resstr.sort() self.assertListEqual(['MOVEMENT'], _resstr) def test_schdload_objtype(self): schedule_load(self.schedule, self.of, self.database) exp_res = ['period','student','dow','lessontype','subject','lesson'] exp_res.sort() _res = self.of.query('objtype') _resstr = [str(_r) for _r in _res] _resstr.sort() self.assertListEqual(exp_res,_resstr)
def setUp(self): self.of = ObjFactory(True) self.obj1 = self.of.new(GenericBase, 'Student', objid='booker', nationality='british', modname=__name__)
def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_rest_dump' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=self.enums) ssviewer_utils.dataset_load(**args)
def __init__(self,dbname,refdbname): log.log(thisfuncname(),3,msg="initialize",dbname=dbname,refdbname=refdbname) self.colorpalette = dict(wp=green,subject=lightblue,ap='yellow', Movement=pink,ELA=salmon,Humanities=lightyellow, Counseling=lightgreen,Math=lightturquoise, Music=lightblue,STEM=lavender,Art=purple,History=pink, Science=darkgreen,Core=karky,Chess=burgundy, computertime='darkgrey',Speech=darkburgundy, Student_News=darkgrey,Computer_Time=brown, Activity_Period=mauve,Melissa=navyblue,Amelia=darkgreen, Samantha=darkyellow, Alexa=paleblue, Paraic=palegreen, Francisco=cerise,Rahul=verydarkgrey,Dylan=verydarkgrey, Moira=verydarkgrey,Issey=verydarkgrey, Daryl=verydarkgrey, Karolina=verydarkgrey) self.fontpalette = dict(Amelia=green,Paraic=darkgreen,Stan=lavender, Samantha=lightgreen,Alexa=blue,Francisco=purple, Melissa=lightblue,Rahul=dirtyyellow,Dylan=dirtyyellow, Moira=dirtyyellow,Issey=dirtyyellow, Daryl=dirtyyellow, Karolina=dirtyyellow,Chess=pink,Student_News=lightyellow, subject=blue) self.of = ObjFactory(True) self.refdatabase = Database(refdbname) self.dbname = dbname self.database = Database(self.dbname) self.lastsaveversion=0
def setUp(self): self.of = ObjFactory(True) self.obj1 = self.of.new(GenericBase, 'Student', objid='booker', nationality='british', modname=__name__) self.of.new(GenericBase, 'Student', objid='dave', age=23, nationality='british', modname=__name__) self.of.new(GenericBase, 'Student', objid='fred', age=35, nationality='irish', modname=__name__) self.of.new(GenericBase, 'Classroom', objid='1a', modname=__name__)
class Test_dump(unittest.TestCase): def setUp(self): self.dbname='test_ssviewer_rest_dump' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database,refdatabase=self.database,saveversion=1,of=self.of,enums=self.enums) ssviewer_utils.dataset_load(**args) def test_(self): expected_results = [[u'1.2.2.6.22', '-', '-', 'subject'], ['ROOT', u'Amelia', u'Clayton', 'lesson'], ['ROOT', '-', '-', 'subject']] result = self.of.dumpobjrpt(objtypes=['lesson','subject'],objref=False, fields=['adult','student']) self.assertListEqual(result,expected_results) def tearDown(self): shutil.copyfile(self.dbname+".sqlite.backup",self.dbname + ".sqlite")
def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') datamembers = dict(period='830-910',student='Booker',dow='MO', teacher='Amelia',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson0',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='910-950',student='Booker',dow='MO', teacher='Stan',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson1',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='950-1020',student='Booker',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson2',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers) datamembers = dict(period='830-910',student='Clayton',dow='MO', teacher='Samantha',saveversion=0,session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric,'DBLesson',objid='dblesson3',constructor='datamembers',database=self.database,of=self.of,modname=__name__,dm=datamembers)
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 setUp(self): self.database = Database('htmlparser') self.of = ObjFactory(True) f = "/home/burtnolej/Development/pythonapps3/clean/apps/schoolscheduler/schedule.html" self.schedule = htmlschedule_slice(f,num_periods=2,num_students=1) schedule_load(self.schedule, self.of, self.database)
class Test_ObjFramework_Database_Derived_DB(unittest.TestCase): def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') datamembers = dict(period='830', student='Booker', teacher='Amelia', saveversion=0, session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric, 'DBLesson', objid='dblesson0', constructor='datamembers', database=self.database, of=self.of, modname=__name__, dm=datamembers) self.foobar.keepversion = True def test_persist(self): with self.database: self.foobar.persist() self.database = Database('foobar',True) with self.database: col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['student','teacher']) self.assertEquals([['Booker','Amelia']],tbl_rows) def test_persist_customtimestamp(self): self.foobar.customtimestamp = "%y%m%d_%H%M%S" with self.database: self.foobar.persist() self.database = Database('foobar',True) with self.database: col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['__timestamp']) self.assertTrue(13,len(tbl_rows[0][0])) def test_update_1field(self): expected_results = [[u'830', u'AM.AC.SC', u'Booker', u'Amelia', u'version'], [u'830', u'AM.AC.SC', u'Booker', u'Aaron', u'current']] self.foobar.customtimestamp = "%y%m%d_%H%M%S" with self.database: self.foobar.persist() self.foobar.update('teacher',"\"Aaron\"") self.database = Database('foobar',True) with self.database: col_name,tbl_rows,_ = tbl_rows_get(self.database,'DBLesson',['period','session','student','teacher','__version'] ) self.assertListEqual(tbl_rows,expected_results)
class Test_ObjFramework_Database(unittest.TestCase): def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') self.foobar= self.of.new(dbtblgeneric, 'DBLesson', objid='dblesson0', constructor='datamembers', modname=__name__, database=self.database, dm={'student':'booker', 'period':2, 'dow':3}) def tearDown(self): self.of.reset() def test_num_obj_created(self): self.assertEquals(len(self.of.query('DBLesson')),1) def test_correct_keys_created(self): self.assertTrue(self.of.object_exists('DBLesson','dblesson0')) def test_objects_created_stored(self): _lesson = self.of.object_get('DBLesson','dblesson0') self.assertEquals(_lesson.__class__.__name__,"DBLesson") def test_objects_have_attributes(self): _lesson = self.of.object_get('DBLesson','dblesson0') self.assertEquals(_lesson.student,'booker') self.assertEquals(_lesson.period,2) self.assertEquals(_lesson.dow,3)
def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') self.datamembers = dict(period='830', student='Booker', teacher='Amelia', saveversion=0, session='AM.AC.SC')
def setUp(self): self.of = ObjFactory() foobar= self.of.new(GenericBase, "Student", objid='booker', modname=__name__, name='booker', age=23)
class Test_SchoolSched_htmlschedule_slice_2periods_1student_persist(unittest.TestCase): def setUp(self): filename = "/home/burtnolej/Development/pythonapps3/clean/apps/schoolscheduler/schedule.html" self.schedule = htmlschedule_slice(filename, num_periods = 2, num_students = 1) self.database = Database('htmlparser') self.of = ObjFactory(True) schedule_load(self.schedule,self.of,self.database) def test_content_subject(self): exp_res = ['MOVEMENT', 'CHESS', 'CORE','STEM','YOGA','ART','READING PERIOD','SCIENCE'] res = [str(res) for res in self.of.query('subject')] self.assertListEqual(res,exp_res) def test_content_teacher(self): exp_res = ['RAHUL', 'NATHANIEL'] res = [str(res) for res in self.of.query('teacher')] self.assertListEqual(res,exp_res) def test_content_student(self): exp_res = ['NATHANIEL'] res = [str(res) for res in self.of.query('student')] self.assertListEqual(res,exp_res) def test_content_userdefid(self): exp_res = ['0.0.0','0.1.0','0.2.0','0.3.0','0.4.0', '0.0.1','0.1.1','0.2.1','0.3.1','0.4.1'] res = [str(res) for res in self.of.query('userdefid')] self.assertListEqual(res,exp_res) def test_content_lessontype(self): exp_res = ['other','break','edu'] res = [str(res) for res in self.of.query('lessontype')] self.assertListEqual(res,exp_res)
class Test_ObjFrameworkGetByVal(unittest.TestCase): # test we can find an return an object given the type and the value def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') datamembers = dict(period='830', student='Booker', dow='MO', teacher='Amelia', saveversion=0, session='AM.AC.SC') self.foobar= self.of.new(schoolschedgeneric, 'DBLesson', objid='dblesson0', constructor='datamembers', database=self.database, of=self.of, modname=__name__, dm=datamembers) datamembers = dict(period='910', student='Clayton', dow='TU', teacher='Stan', saveversion=0, session='ST.AC.SC') self.foobar= self.of.new(schoolschedgeneric, 'DBLesson', objid='dblesson1', constructor='datamembers', database=self.database, of=self.of, modname=__name__, dm=datamembers) def test_(self): self.assertEquals(self.of.object_get_byval("period","830").name,"830") self.assertEquals(self.of.object_get_byval("period","910").name,"910") self.assertEquals(self.of.object_get_byval("period","foobar"),None)
def setUp(self): self.dbname='test_ssviewer_rest_dump' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all",prep=-1,database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database,refdatabase=self.database,saveversion=1,of=self.of,enums=self.enums) ssviewer_utils.dataset_load(**args)
def setUp(self): self.of = ObjFactory() self.obj1= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__) self.obj2= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__)
class Test_ObjFrameworkDupeID(unittest.TestCase): def setUp(self): self.of = ObjFactory() self.obj1= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__) self.obj2= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__) def tearDown(self): self.of.reset() def test_num_dupe_objid(self): self.assertEqual(self.obj1,self.obj2)
def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') self.foobar= self.of.new(self.Dummy, 'DBLesson', objid='dblesson0', constructor='datamembers', modname=__name__, database=self.database, dm={'student':'booker', 'period':2, 'dow':3})
class Test_ObjFramework_Database_Derived(unittest.TestCase): # pass in a subclass of dbtblgeneric as a baseclass; testing a bug found # in schoolschedulewizard class Dummy(dbtblgeneric): pass def setUp(self): self.of = ObjFactory(True) self.database = Database('foobar') self.foobar= self.of.new(self.Dummy, 'DBLesson', objid='dblesson0', constructor='datamembers', modname=__name__, database=self.database, dm={'student':'booker', 'period':2, 'dow':3}) def test_num_obj_created(self): self.assertEquals(len(self.of.query('DBLesson')),1)
def setUp(self,dbname,refdbname): dbpath = '/Users/burtnolej/Development/pythonapps3/clean/apps/schoolschedulewizard/test_sswizard' chdir(dbpath) self.dbname = dbname self.dbfilename = path.join(dbpath,self.dbname) self.database = Database(self.dbfilename) self.of = ObjFactory(True) self.ui = WizardUI(self.dbname, self.of,refdbname) self.ui.dbname_entry_sv.set(dbname) parent_name = self.ui.entrygrid.widgets[0][0].winfo_parent() self.parent_widget = self.ui.entrygrid.widgets[0][0]._nametowidget(parent_name) self.parent_widget.update()
def test_dbwrite_reload(self): self.of = ObjFactory(True) self.ui = WizardUI('test_sswizard_save', self.of,'test_sswizard_save') self.ui.dbname_entry_sv.set('test_sswizard_save') parent_name = self.ui.entrygrid.widgets[0][0].winfo_parent() self.parent_widget = self.ui.entrygrid.widgets[0][0]._nametowidget(parent_name) self.parent_widget.update() self.ui.load(1) self.ui.save(1) self.assertListEqual(self.of.store['lesson'].keys(),['1,1,156', '1,2,156'])
class Test_ObjFrameworkDump(unittest.TestCase): def setUp(self): self.of = ObjFactory(True) self.obj1 = self.of.new(GenericBase, 'Student', objid='booker', nationality='british', modname=__name__) def test_(self): from types import StringType,IntType, UnicodeType expected_results = [[('pobjid', 'ROOT'),('objid', 'booker'), ('objtype', 'Student'), ('nationality', 'british')]] _results = self.of.dumpobj() results = [] for result in _results: result.pop('id') results.append([(k,v) for k,v in result.iteritems() if type(v) in [IntType,StringType,UnicodeType]]) expected_results.sort() results.sort() self.assertListEqual(expected_results,results)
class Test_ObjFramework_2_class(unittest.TestCase): def setUp(self): self.of = ObjFactory() self.obj1= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__, name='booker', age=23) self.obj2= self.of.new(GenericBase, 'Subject', objid='science', modname=__name__, name='science', teacher_name='fran') def tearDown(self): self.of.reset() def test_2_class(self): self.assertListEqual(self.of.query(),['Student','Subject'])
def setUp(self): self.of = ObjFactory() self.obj1= self.of.new(GenericBase, 'Student', objid='booker', modname=__name__, name='booker', age=23) self.obj2= self.of.new(GenericBase, 'Subject', objid='science', modname=__name__, name='science', teacher_name='fran')
def setUp(self): dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'service_getrecord_1lesson' self.database = Database(dbname) self.of = ObjFactory(True) enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=enums) ssviewer_utils.dataset_load(**args)
class Test_dump(unittest.TestCase): def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_rest_dump' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=self.enums) ssviewer_utils.dataset_load(**args) def test_(self): expected_results = [[u'1.2.2.6.22', '-', '-', 'subject'], ['ROOT', 'Amelia', 'Clayton', 'lesson'], [u'1.2.3.4.5', '-', '-', 'subject'], ['ROOT', 'Stan', 'Clayton', 'lesson'], ['ROOT', '-', '-', 'subject'], ['ROOT', '-', '-', 'subject']] result = self.of.dumpobjrpt(objtypes=['lesson', 'subject'], objref=False, fields=['adult', 'student']) self.assertListEqual(result, expected_results) def tearDown(self): shutil.copyfile(self.dbname + ".sqlite.backup", self.dbname + ".sqlite")
exec_str, result = obj.persist() log.log(thisfuncname(), 9, msg="persisting of obj", objid=str(obj), exec_str=exec_str, result=result) def _lastsaveversion_get(self): try: with self.database: colndefn, rows = tbl_query( self.database, "select max(saveversion) from lesson") return (rows[0][0]) except Exception: return (-1) if __name__ == "__main__": #master = Tk() of = ObjFactory(True) #app = WizardUI('htmlparser',of,'quadref',maxentrycols=12,maxentryrows=20) app = WizardUI('test_ssloader', of, 'test_ssloader', maxentrycols=12, maxentryrows=20) app.mainloop()
class Test_update(unittest.TestCase): def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_util_add' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=self.enums, keepversion=True) ssviewer_utils.dataset_load(**args) def test_update_subject(self): expected_results = [ [ u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement' ], [ u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'ELA' ] ] obj = self.of.query_advanced("lesson", [('period', '830-910'), ('dow', 'WE')]) obj[0].update(self.of, 'subject', 'ELA') with self.database: _, rows, _ = tbl_rows_get( self.database, "lesson", fields=[ 'status', 'substatus', 'recordtype', 'period', 'dow', 'source', 'session', 'teacher', 'student', 'prep', 'userobjid', 'subject' ], whereclause=[["period", "=", "\"830-910\""], ["dow", "=", "\"WE\""]]) self.assertListEqual(rows, expected_results) def test_update_adult(self): expected_results = [ [ u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'[Dylan,Francisco]', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement' ], [ u'master', u'complete', u'academic', u'830-910', u'WE', u'dbinsert', u'[Dylan,Francisco].Movement.Wednesday.830-910', u'Amelia', u'Nathaniel', 5, u'1.4.1.None.8', u'Movement' ] ] obj = self.of.query_advanced("lesson", [('period', '830-910'), ('dow', 'WE')]) obj[0].update(self.of, 'teacher', 'Amelia') with self.database: _, rows, _ = tbl_rows_get( self.database, "lesson", fields=[ 'status', 'substatus', 'recordtype', 'period', 'dow', 'source', 'session', 'teacher', 'student', 'prep', 'userobjid', 'subject' ], whereclause=[["period", "=", "\"830-910\""], ["dow", "=", "\"WE\""]]) self.assertListEqual(rows, expected_results) def tearDown(self): shutil.copyfile(self.dbname + ".sqlite.backup", self.dbname + ".sqlite")
class Test_addrecord(unittest.TestCase): def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'service_add_record' self.database = Database(self.dbname) self.of = ObjFactory(True) self.enums = sswizard_utils.setenums(dow="all", prep=-1, database=self.database) self.prepmap = sswizard_utils._loadprepmapper(self.database) args = dict(database=self.database, refdatabase=self.database, saveversion=1, of=self.of, enums=self.enums) ssviewer_utils.dataset_load(**args) def test_(self): # test that a new object is added into of store with the correct userobjid expected_result = 'Stan.Math.Tuesday.830-910' datamembers = { 'student': 'Nathaniel', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'academic', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) ssviewer_utils.dataset_add(**args) self.assertEqual( self.of.object_get('lesson', datamembers['userobjid']).session.name, expected_result) def test_internal_dict(self): # test that the internal datamembers/dm dict has the correct keys by asserting correct values # and comparing keys vs a recovered record expected_result = { 'status': 'master', 'prep': 5, 'recordtype': 'subject', 'period': '830-910', 'substatus': 'complete', 'source': 'manual', 'session': 'Stan.Math.Tuesday.830-910', 'adult': 'Stan', 'student': 'Nathaniel', 'objtype': 'lesson', 'dow': u'TU', 'userobjid': '1.2.1.2.4', 'subject': 'Math' } datamembers = { 'student': 'Nathaniel', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'subject', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) ssviewer_utils.dataset_add(**args) obj_recovered = self.of.query('lesson')[0].dm.keys() obj_add = self.of.query('lesson')[1].dm.keys() obj_recovered.sort() obj_add.sort() # test keys self.assertListEqual(obj_recovered, obj_add) obj = self.of.object_get('lesson', datamembers['userobjid']) obj.dm.pop("id") # test values self.assertEqual(obj.dm, expected_result) def test_internal_attr(self): # check the member attr values and that the keys are the same between recovered and added objects datamembers = { 'student': 'Nathaniel', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'subject', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) obj = ssviewer_utils.dataset_add(**args) self.assertEquals(obj.adult.name, 'Stan') self.assertEquals(obj.dow.name, 'TU') self.assertTrue(hasattr(obj, 'id')) self.assertEquals(obj.objtype.name, 'lesson') self.assertEquals(obj.period.name, '830-910') self.assertEquals(obj.prep.name, 5) self.assertEquals(obj.recordtype.name, 'subject') self.assertEquals(obj.session.name, 'Stan.Math.Tuesday.830-910') self.assertEquals(obj.source.name, 'manual') self.assertEquals(obj.status.name, 'master') self.assertEquals(obj.student.name, 'Nathaniel') self.assertEquals(obj.subject.name, 'Math') self.assertEquals(obj.substatus.name, 'complete') self.assertEquals(obj.userobjid.name, '1.2.1.2.4') obj_addattrnames = [ k for k, v in obj.attr_get_keyval(include_callable=False, include_nondataattr=False) ] obj_recoveredattrnames = [ k for k, v in self.of.query('lesson')[0].attr_get_keyval( include_callable=False, include_nondataattr=False) ] self.assertListEqual(obj_addattrnames, obj_recoveredattrnames) def test_db(self): expected_result = [[ u'Dylan', u'Clayton', u'1030-1110', u'MO', u'Game Period', u'academic' ], [u'Stan', u'Nathaniel', u'830-910', u'TU', u'Math', u'academic']] datamembers = { 'student': 'Nathaniel', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'academic', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) obj = ssviewer_utils.dataset_add(**args) obj.keepversion = True obj.customtimestamp = "%y%m%d_%H%M%S" with self.database: _, rows, _ = tbl_rows_get(self.database, 'lesson', [ 'teacher', 'student', 'period', 'dow', 'subject', 'recordtype' ]) self.assertListEqual(expected_result, rows) def test_db_updates_enabled(self): expected_result = [[ u'Dylan', u'Clayton', u'1030-1110', u'MO', u'Game Period', u'academic', 'current' ], [ u'Stan', u'Nathaniel', u'830-910', u'TU', u'Math', u'academic', 'current' ]] datamembers = { 'student': 'Nathaniel', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'academic', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers, keepversion=True) obj = ssviewer_utils.dataset_add(**args) obj.keepversion = True obj.customtimestamp = "%y%m%d_%H%M%S" with self.database: _, rows, _ = tbl_rows_get(self.database, 'lesson', [ 'teacher', 'student', 'period', 'dow', 'subject', 'recordtype', '__version' ]) self.assertListEqual(expected_result, rows) def test_pivot(self): expected_result = [['', u'MO', u'TU'], [u'1030-1110', [(u'Game Period', )], []], ['830-910', [], [('Math', )]]] datamembers = { 'student': 'Clayton', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'subject', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) newobj = ssviewer_utils.dataset_add(**args) args = dict(of=self.of, enums=self.enums, yaxis_type='dow', xaxis_type='period', source_type='student', source_value='Clayton', ztypes=['subject']) result = ssviewer_utils.dataset_pivot(**args) self.assertListEqual(result, expected_result) def test_dupe(self): expected_result = [['', u'MO', u'TU'], [u'830-910', [], [('Math', )]], [u'1030-1110', [(u'Game Period', )], []]] datamembers = { 'student': 'Clayton', 'teacher': 'Stan', 'subject': 'Math', 'period': '830-910', 'recordtype': 'subject', 'dow': 'Tuesday' } args = dict(database=self.database, refdatabase=self.database, prepmap=self.prepmap, of=self.of, enums=self.enums, datamembers=datamembers) newobj = ssviewer_utils.dataset_add(**args) with self.assertRaises(Exception): newobj = ssviewer_utils.dataset_add(**args) def tearDown(self): shutil.copyfile(self.dbname + ".sqlite.backup", self.dbname + ".sqlite")
def setUp(self): self.dbname = CURRENTDIR + "/" + THISEXEC + "/" + 'test_ssviewer_util_add' self.database = Database(self.dbname) self.of = ObjFactory(True)