def test_(self): write_text_to_file( self.filename, "database_name:" + encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n") append_text_to_file( self.filename, "sp_name:" + encode("student_schedule", self.encoding) + "\n") append_text_to_file( self.filename, "delete_flag:" + encode("False", self.encoding) + "\n") append_text_to_file( self.filename, "sp_args:" + encode( "<root><students>70</students><days>M</days><periods>1</periods></root>", self.encoding) + "\n") result = DataStoredProc.stored_proc_by_file( self.filename, result_file=self.result_filename) self.assertEqual(result, [[ u'Homeroom', u'Homeroom', None, u'Isaac', u'M', 1, 9, 165, u'Seminar', 5, 993 ]]) self.assertTrue(os_file_exists(self.result_filename)) self.assertEqual( "Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993", os_file_to_string(self.result_filename))
def test_(self): write_text_to_file( self.filename, "database_name:" + encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n") append_text_to_file( self.filename, "sp_name:" + encode("student_schedule", self.encoding) + "\n") append_text_to_file( self.filename, "delete_flag:" + encode("False", self.encoding) + "\n") append_text_to_file( self.filename, "header_flag:" + encode("True", self.encoding) + "\n") append_text_to_file( self.filename, "sp_args:" + encode( "<root><students>70</students><days>M</days><periods>1</periods></root>", self.encoding) + "\n") result = DataStoredProc.stored_proc_by_file( self.filename, result_file=self.result_filename) self.assertEqual(result, [[ 'sSubjectLongDesc', 'sCourseNm', 'sClassFocusArea', 'sFacultyFirstNm', 'cdDay', 'idTimePeriod', 'idLocation', 'idSection', 'cdClassType', 'iFreq', 'idClassLecture' ], [ u'Homeroom', u'Homeroom', None, u'Isaac', u'M', 1, 9, 165, u'Seminar', 5, 993 ]]) self.assertTrue(os_file_exists(self.result_filename)) self.assertEqual( "sSubjectLongDesc^sCourseNm^sClassFocusArea^sFacultyFirstNm^cdDay^idTimePeriod^idLocation^idSection^cdClassType^iFreq^idClassLecture$$Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993", os_file_to_string(self.result_filename))
def test_(self): write_text_to_file( self.filename, "database_name:" + encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n") append_text_to_file( self.filename, "sp_name:" + encode("student_schedule", self.encoding) + "\n") append_text_to_file( self.filename, "delete_flag:" + encode("False", self.encoding) + "\n") append_text_to_file( self.filename, "sp_args:" + encode( "<root><students>70</students><students>69</students><days>M</days><days>T</days><periods>1</periods><periods>2</periods></root>", self.encoding) + "\n") result = DataStoredProc.stored_proc_by_file( self.filename, result_file=self.result_filename) expected_results = [[ u'Homeroom', u'Homeroom', None, u'Samantha', u'M', 1, 10, 163, u'Seminar', 5, 983 ], [ u'Homeroom', u'Homeroom', None, u'Isaac', u'M', 1, 9, 165, u'Seminar', 5, 993 ], [ u'Movement', u'Movement', None, u'Michael', u'M', 2, 37, 432, u'Seminar', 1, 1196 ], [ u'Science', u'Science', None, u'John', u'M', 2, 4, 162, u'1on1', 1, 143 ], [ u'Homeroom', u'Homeroom', None, u'Samantha', u'T', 1, 10, 163, u'Seminar', 5, 984 ], [ u'Homeroom', u'Homeroom', None, u'Isaac', u'T', 1, 9, 165, u'Seminar', 5, 994 ], [ u'Foreign Language', u'Spanish 1', None, u'Jamie', u'T', 2, 6, 451, u'Seminar', 2, 1218 ], [ u'Work Period', u'Work Period', None, u'Alyssa', u'T', 2, 37, 564, u'Seminar', 1, 713 ]] self.assertEqual(result, expected_results) self.assertTrue(os_file_exists(self.result_filename)) self.assertEqual( os_file_to_string(self.result_filename), "Homeroom^Homeroom^None^Samantha^M^1^10^163^Seminar^5^983$$Homeroom^Homeroom^None^Isaac^M^1^9^165^Seminar^5^993$$Movement^Movement^None^Michael^M^2^37^432^Seminar^1^1196$$Science^Science^None^John^M^2^4^162^1on1^1^143$$Homeroom^Homeroom^None^Samantha^T^1^10^163^Seminar^5^984$$Homeroom^Homeroom^None^Isaac^T^1^9^165^Seminar^5^994$$Foreign Language^Spanish 1^None^Jamie^T^2^6^451^Seminar^2^1218$$Work Period^Work Period^None^Alyssa^T^2^37^564^Seminar^1^713" )
def _create_input_tree(filename,repo, base_tree=GithubObject.NotSet, mode="100644"): """ generate a GitTreeElement for a file (a Git commit is 1 or more GitTreeElements) :param filename: full path of the file :repo : Repository :rtype: GitTreeElement """ file_str = os_file_to_string(filename) return repo.create_git_tree([InputGitTreeElement(filename,mode, "blob",file_str)], base_tree=base_tree)
def test_query_encoded_by_file(self): append_text_to_file( self.filename, "database_name:" + b64encode(self.database_name) + "\n") append_text_to_file( self.filename, "qry_str:" + b64encode("select col1,col2,col3 from " + self.table_name) + "\n") append_text_to_file(self.filename, "delete_flag:" + b64encode("True") + "\n") result = DatabaseQueryTable.query_by_file( self.filename, result_file=self.result_filename) self.assertEqual( "eA==^eQ==^Ng==", os_file_to_string(self.result_filename).split("\n")[0])
def _create_input_tree_multi(filenames,repo, base_tree=GithubObject.NotSet, mode="100644"): """ generate a GitTreeElement for a file(s) (a Git commit is 1 or more GitTreeElements) :param filenames: list of full path of the file :repo : Repository :rtype: GitTreeElement """ tree_input = [] for filename in filenames: file_str = os_file_to_string(filename) tree_input.append(InputGitTreeElement(filename,mode, "blob",file_str)) return repo.create_git_tree(tree_input, base_tree=base_tree)
def test_(self): write_text_to_file( self.filename, "database_name:" + encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n") append_text_to_file( self.filename, "sp_name:" + encode("delete_student", self.encoding) + "\n") append_text_to_file( self.filename, "delete_flag:" + encode("False", self.encoding) + "\n") append_text_to_file( self.filename, "sp_args:" + encode( "<root><students>666</students><students>667</students></root>", self.encoding) + "\n") result = DataStoredProc.stored_proc_by_file( self.filename, result_file=self.result_filename) write_text_to_file( self.filename, "database_name:" + encode(path.join(TESTDIR, TESTDBNAME), self.encoding) + "\n") append_text_to_file( self.filename, "sp_name:" + encode("student", self.encoding) + "\n") append_text_to_file( self.filename, "delete_flag:" + encode("False", self.encoding) + "\n") append_text_to_file( self.filename, "sp_args:" + encode("<root><students>666</students></root>", self.encoding) + "\n") result = DataStoredProc.stored_proc_by_file( self.filename, result_file=self.result_filename) self.assertEqual("", os_file_to_string(self.result_filename))
def _parse_input_file(cls, filepath, mandatory_fields, encoding="unicode", runtime_path=".", **kwargs): """ take a key,value pair param text file and create class attributes of the name key with the value, value :param filepath:string, full path of the param text file :param encoding: string of member unicode|base64|b64encode :param mandatory_fields: list, all the fields that must be present in this file rtype : -1 on failure or None """ if os_file_exists(filepath) == False: log.log(PRIORITY.FAILURE, msg="filename [" + filepath + "] not found]") return ([-1]) file_str = os_file_to_string(filepath) if encoding == "base64": # this is just for uuencoding; because encoding can create newline characters # we can get around this by converting them to + and then to space; which # is treated as the same as a newline file_str = file_str.replace("+++", " ") lines = file_str.split("\n") all_fields = [] # holds all fields detected not just mandatory ones try: # first load all attributes passed for _line in lines: _line_split = [] try: _line_split = _line.split(":") except: log.log(PRIORITY.INFO, msg="cannot process line [" + _line + "] in file [" + filepath + "]") if len(_line_split) == 2: setattr(cls, _line_split[0], _line_split[1]) all_fields.append(_line_split[0]) else: log.log(PRIORITY.INFO, msg="cannot process line [" + _line + "] in file [" + filepath + "]") # call validate func for each mandatory field for _field in mandatory_fields: if getattr(cls, "_validate_" + _field)(encoding=encoding) == [-1]: log.log(PRIORITY.FAILURE, msg="mandatory field could not be validated [" + _field + "]") raise Exception( "mandatory field could not be validated [" + _field + "]") else: log.log(PRIORITY.INFO, msg="parsed mandatory [" + str(_field) + "=" + str(getattr(cls, _field)) + "]") # then validate all optional fields for _field in all_fields: if _field not in mandatory_fields: if getattr(cls, "_validate_" + _field)(encoding=encoding) != [-1]: log.log(PRIORITY.INFO, msg="parsed optional [" + str(_field) + "=" + str(getattr(cls, _field)) + "]") # check to see if an explicit runtime path is set for databases and log files setattr(cls, "runtime_path", runtime_path) log.log(PRIORITY.INFO, msg="setting runtime_path to [" + runtime_path + "]") except TypeError, e: log.log(PRIORITY.FAILURE, msg="TypeError encoding issues? [" + str(e.message) + "]") return ([-1])
def _get_token(): """ get a OAuth token for the GitHub server. This has likely been created on the github.com and saved to the text file :rtype:string """ return os_file_to_string(GIT_TOKEN_FILE)