def test_insert_detail_record(self): print("\n") print("insert detail record SQL incantation") seperator() sql = SELECT_NEW_PEOPLE(where='AND subID.id = {}'.format(self.cid)) p = do_sql(sql, key='debug', earl=EARL).first() print(p) print(p.dob) # convert datetime object to string because informix #dob = p.dob.strftime("%Y-%m-%d") dob = p.dob.strftime("%m-%d-%Y") sql = INSERT_DETAIL_RECORD(batch_id=40, username=p.loginid, last_name=p.lastname, first_name=p.firstname, cid=p.id, faculty=p.facultystatus, staff=p.staffstatus, student=p.studentstatus, retire=p.retirestatus, dob=dob, postal_code=p.zip, account=p.accttypes, proxid=p.proxid, phone_ext=p.phoneext, departments=p.depts, csv='', notes='') do_sql(sql, key='debug', earl=EARL)
def test_select_new_people(self): print("\n") print("select new people SQL incantations") seperator() sql = SELECT_NEW_PEOPLE(where='') objects = do_sql(sql, key='debug', earl=EARL) for o in objects: print("{}|{}|{}|{}|{}".format(o.loginid, o.lastname, o.firstname, o.id, o.dob))
def test_create_batch(self): print("\n") print("create a batch record") seperator() session = self.session rec = ProvisioningBatchRec(total=4, sitrep=1, notes='created a test batch record') session.add(rec) session.flush() print("batch ID = {}".format(rec.batch_no)) session.commit() session.close()
def test_select_detail(self): print("\n") print("selectd all detail records") seperator() session = self.session objects = session.query(ProvisioningDetailRec).all() print("length of objects") print(len(objects)) for o in objects: print("{}|{}|{}|{}|{}|{}|{}|{}".format( o.username, o.last_name, o.first_name, o.id, o.birth_date, o.batch_rec.created_at, o.batch_rec.total, o.batch_rec.sitrep))
def test_student_balance_late_fee(self): print("\n") print("Student balance late fee") sid = settings.TEST_STUDENT_ID seperator() earl = reverse_lazy('student_balance_late_fee') # get page response = self.client.get(earl, follow=True) self.assertEqual(response.status_code, 200) # attempt to sign in with client login method login = self.client.login( username=self.user.username, password=self.password ) self.assertTrue(login) response = self.client.get(earl) self.assertEqual(response.status_code, 200) student = self.client.post( earl, {'student_number': sid} ) # create database session connection session = get_session(self.earl) # ordered terms temp table sql = ORDERED_TERMS_TEMP( start_date = settings.ORDERED_TERMS_START_DATE ) session.execute(sql) # latest terms temp table sql = LATEST_TERM_TEMP session.execute(sql) # student balance late fee sql = STUDENT_BALANCE_LATE_FEE( student_number = self.sid ) student = session.execute(sql).first() self.assertEqual( student.id, self.sid ) session.close() print student
def test_activities_invalid(self): print("\n") print("test activities select statement with invalid college ID") print(seperator()) # organization, club, etc. is_sports = False fieldname = 'activity' if not is_sports else 'sport' comparison = 'NOT' if not is_sports else '' sql = ACTIVITIES( cid = self.cid_null, fieldname = fieldname, comparison = comparison ) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print Activities SQL") activities = do_sql(sql, self.debug, self.earl).fetchall() print(activities) self.assertEqual(len(activities), 0)
def test_set_relative(self): """ corresponds also to set_relative() in manager.utils """ print("\n") print("test relative ORM data model for get_or_create() method") print(seperator()) user = User.objects.get(pk=self.cid) json_data = open( '{}/core/fixtures/relative.json'.format(settings.ROOT_DIR) ).read() data = json.loads(json_data) for i in range (0, len(data)): relative, created = Relative.objects.get_or_create( user = user, relation_code = data[i]['fields']['relation_code'], first_name = data[i]['fields']['first_name'], last_name = data[i]['fields']['last_name'] ) relative.updated_by = user relative.primary = data[i]['fields']['primary'] relative.save()
def test_grading_scales(self): print("\n") print("grading scales") print(seperator()) grading_scale = sc.get_grading_scale(section_id)
def test_address_comparision(self): print("\n") print("test address comparison") print(seperator()) student = get_alumna(self.cid) addresses = Address.objects.filter(user__id=self.cid) data = {} if (len(addresses) > 0): for a in addresses: prefix = 'home' if a.aa == 'WORK': prefix = 'business' for f in Address._meta.get_fields(): field = f.name if field not in EXCLUDE_FIELDS: key = '{}_{}'.format(prefix, field) val = getattr(a, field) if student[key] != val: data[key] = val orig_key = 'original_{}'.format(key) data[orig_key] = student[key] data[prefix] = True print(data)
def test_set_address(self): """ corresponds also to set_address() in manager.utils """ print("\n") print("test address ORM data model for get_or_create() method") print(seperator()) user = User.objects.get(pk=self.cid) json_data = open( '{}/core/fixtures/address.json'.format(settings.ROOT_DIR) ).read() data = json.loads(json_data) for i in range (0, len(data)): address, created = Address.objects.get_or_create( user = user, aa = data[i]['fields']['aa'] ) for f in address._meta.get_fields(): field = f.name if field not in EXCLUDE_FIELDS: setattr(address, field, data[0]['fields'][field]) address.updated_by = user address.save()
def test_select_batch(self): print("\n") print("selectd all batch records") seperator() session = self.session objects = session.query(ProvisioningBatchRec).all() print("length of objects") print(len(objects)) for o in objects: for d in o.details: print("{}|{}|{}|{}|{}|{}|{}|{}".format(d.username, d.last_name, d.first_name, d.id, d.birth_date, o.created_at, o.total, o.sitrep))
def test_alumna_invalid(self): print("\n") print("test get_alumna() with invalid college ID") print(seperator()) alumna = get_alumna(self.cid_null) self.assertIsNone(alumna)
def test_alumna(self): print("\n") print("test get_alumna() with valid college ID") print(seperator()) alumna = get_alumna(self.cid) self.assertGreaterEqual(len(alumna), 1)
def test_trigger_grades_json(self): print("\n") print("trigger grades JSON") print(seperator()) data = self.json_data # simple check for one json parameter self.assertIn(data['type'], 'grades.update')
def test_get_alumna(self): print("\n") print("test alumna ORM data model, which will fail if not found") print(seperator()) alumna = Alumna.objects.get(user__id=self.cid) print(alumna)
def test_home(self): print("\n") print("Home Page") seperator() earl = reverse('home') print(earl) # get home page response = self.client.get(earl) self.assertEqual(response.status_code, 302) # redirect to sign in page print("redirect to sign in at {}".format(response['location'])) # attempt to sign in with client login method login = self.client.login( username=self.username, password=self.password ) self.assertTrue(login) response = self.client.get(earl) self.assertEqual(response.status_code, 200)
def test_activity(self): print("\n") print("test activity ORM data model") print(seperator()) activities = Activity.objects.filter(user__id=self.cid) for activity in activities: print(activity) self.assertGreaterEqual(len(activities), 1)
def test_privacy(self): print("\n") print("test privacy ORM data model") print(seperator()) privacies = Privacy.objects.filter(user__id=self.cid) print("len = {}".format(len(privacies))) for privacy in privacies: print(privacy) self.assertGreaterEqual(len(privacies), 1)
def test_address(self): print("\n") print("test address ORM data model") print(seperator()) addresses = Address.objects.filter(user__id=self.cid) for address in addresses: print(address) self.assertGreaterEqual(len(addresses), 1)
def test_relative(self): print("\n") print("test relative ORM data model") print(seperator()) relatives = Relative.objects.filter(user__id=self.cid) for relative in relatives: print(relative) self.assertGreaterEqual(len(relatives), 1)
def test_trigger_grades_view(self): print("\n") print("trigger grades view") print(seperator()) # convert python dictionary to json data and POST to view response = self.client.post(reverse('trigger_grades'), json.dumps(self.json_data), content_type="application/json") self.assertEqual(response.status_code, 200) self.assertEqual(response.content, 'Success')
def test_student_detail(self): print("\n") print("Student Detail") sid = settings.TEST_STUDENT_ID seperator() earl = reverse('student_detail', args=[sid]) # get page response = self.client.get(earl, follow=True) self.assertEqual(response.status_code, 200) # attempt to sign in with client login method login = self.client.login( username=self.username, password=self.password ) self.assertTrue(login) response = self.client.get(earl) self.assertEqual(response.status_code, 200) student = self.client.post( earl, {'student_number': sid} ) enrollment = get_objects(PROGRAM_ENROLLMENT(student_number=sid), True) balances = get_objects(SUBSIDIARY_BALANCES(student_number=sid), True) notes = get_objects(ACCOUNT_NOTES(student_number=sid), True) session = get_session(self.earl) sql = SESSION_DETAILS( student_number = self.sid, start_date = settings.ORDERED_TERMS_START_DATE ) details = session.execute(sql).first() self.assertEqual(enrollment.id, sid) self.assertEqual(balances.id, sid) if notes: self.assertEqual(notes.id, sid) self.assertEqual(details.id, sid)
def test_get_majors(self): print("\n") print("test get_majors()") print(seperator()) majors = get_majors() if settings.DEBUG: for m in majors: print(m) else: print("use the --debug-mode flag to print majors") self.assertGreaterEqual(len(majors), 1)
def test_relatives_temp(self): print("\n") print("test relatives from temp table after update") print(seperator()) sql = RELATIVES_TEMP(cid = self.cid) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print RELATIVES_TEMP SQL") relatives_temp = do_sql(sql, self.debug, self.earl).fetchall() print(relatives_temp)
def test_activities_temp(self): print("\n") print("test activities select statement from temp table") print(seperator()) sql = ACTIVITIES_TEMP(cid = self.cid) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print ACTIVITIES_TEMP SQL") activities = do_sql(sql, self.debug, self.earl).fetchall() print(activities)
def test_trigger_grades_update(self): print("\n") print("trigger grades update informix") print(seperator()) data = self.json_data session = get_session(self.earl) for grade in data['data']: # 01234567890123456789012345678 # 2018;RC;FRN 2010;01;UG17;UNDG # yr sess crs_no sec cat prog school_code = grade['section_school_code'] # use the --debug-mode flag to test with SELECT if settings.DEBUG: sql = SELECT_GRADE(coursekey=school_code, student_number=grade['school_uid']) else: sql = UPDATE_GRADE(grade=grade['updated_overall_grade'], coursekey=school_code, student_number=grade['school_uid']) print("sql = {}".format(sql)) print("2018;RC;FRN 2010;01;UG17;UNDG") print("yr sess crs_no sec cat prog") print("cw_rec.yr = {}".format(school_code[0:4])) print("cw_rec.cat = {}".format(school_code[20:25])) print("cw_rec.sess = {}".format(school_code[5:7])) print("cw_rec.prog = {}".format(school_code[25:])) print("cw_rec.crs_no = {}".format(school_code[8:16])) print("cw_rec.sec = {}".format(school_code[17:19])) try: response = session.execute(sql) if settings.DEBUG: for r in response: print(r) except: logger.debug( 'test_trigger_grades_update_bad_data = {}'.format(grade)) session.close()
def test_work_address_temp(self): print("\n") print("test work address select statement from temp table") print(seperator()) sql = WORKADDRESS_TEMP(cid = self.cid) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print WORKADDRESS_TEMP SQL") workaddress = do_sql(sql, self.debug, self.earl).fetchall() print(workaddress) self.assertGreaterEqual(len(workaddress), 1)
def test_relatives_orig(self): print("\n") print("test relatives from database that were already in place") print(seperator()) sql = RELATIVES_ORIG(cid = self.cid) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print RELATIVES_ORIG SQL") relatives_orig = do_sql(sql, self.debug, self.earl).fetchall() print(relatives_orig) self.assertGreaterEqual(len(relatives_orig), 1)
def test_privacy_select(self): print("\n") print("test privacy select statement") print(seperator()) sql = PRIVACY(cid = self.cid) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print PRIVACY SQL") privacy = do_sql(sql, self.debug, self.earl).fetchall() print(privacy) self.assertGreaterEqual(len(privacy), 1)
def test_privacy_select_invalid(self): print("\n") print("test privacy select statement with invalid college ID") print(seperator()) sql = PRIVACY(cid = self.cid_null) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print PRIVACY SQL") privacy = do_sql(sql, self.debug, self.earl).fetchall() print(privacy) self.assertEqual(len(privacy), 0)
def test_set_activity(self): """ corresponds also to set_activity() in manager.utils """ print("\n") print("test activity ORM data model for get_or_create() method") print(seperator()) user = User.objects.get(pk=self.cid) json_data = open( '{}/core/fixtures/activity.json'.format(settings.ROOT_DIR) ).read() data = json.loads(json_data) for i in range (0, len(data)): activity, created = Activity.objects.get_or_create( user = user, text = data[i]['fields']['text'], code = data[i]['fields']['code'] ) activity.updated_by = user activity.save()
def test_set_alumna(self): """ corresponds also to the set_alumna() in manager.utils """ print("\n") print("test alumna ORM data model for get_or_create() method") print(seperator()) user = User.objects.get(pk=self.cid) alumna, created = Alumna.objects.get_or_create(user=user, pk=user.id) json_data = open( '{}/core/fixtures/alumna.json'.format(settings.ROOT_DIR) ).read() data = json.loads(json_data) for f in alumna._meta.get_fields(): field = f.name if field not in EXCLUDE_FIELDS: setattr(alumna, field, data[0]['fields'][field]) alumna.updated_by=(user) alumna.save()
def test_work_address_invalid(self): print("\n") print( """ test work address select statement from temp table with invalid college ID """ ) print(seperator()) sql = WORKADDRESS_TEMP(cid = self.cid_null) if settings.DEBUG: print(sql) else: print("use the --debug-mode flag to print WORKADDRESS_TEMP SQL") workaddress = do_sql(sql, self.debug, self.earl).fetchall() print(workaddress) self.assertEqual(len(workaddress), 0)
def test_activities_comparision(self): print("\n") print("test activities comparison") print(seperator()) activities = get_activity(self.cid, False) athletics = get_activity(self.cid, True) activities_orig = [] for a in activities: activities_orig.append(a) for a in athletics: activities_orig.append(a) print("activities_orig") print(activities_orig) activities = Activity.objects.filter(user__id=self.cid) activities_temp = [] for a in activities: activities_temp.append((a.text,)) print("activities_temp") print(activities_temp) activities_diff = [] for temp in activities_temp: if temp not in activities_orig: activities_diff.append(temp) print("activities_diff") print(activities_diff)
def test_trigger_grades_update_bad_data(self): print("\n") print("trigger grades update informix with bad data") print(seperator()) data = self.json_data_bad session = get_session(self.earl) for grade in data['data']: try: school_code = grade['section_school_code'] sql = UPDATE_GRADE(grade=grade['updated_overall_grade'], coursekey=school_code, student_number=grade['school_uid']) print("update grade sql = {}".format(sql)) response = session.execute(sql) except: logger.debug( 'test_trigger_grades_update_bad_data = {}'.format(grade))
def test_message(self): print("\n") print("create an Alert object") seperator() alert = Alert.objects.create()