def test_date_comparison(self): target_filepath = get_temporary_file(directory="/tmp") file_last_modified = get_file_modified_date(target_filepath) comparison_date = "2013-07-18T16:31:46-0400" self.assertFalse(compare_datetime_to_iso8601_date(file_last_modified, comparison_date)) comparison_date = "2013-07-18T16:31:46Z" self.assertFalse(compare_datetime_to_iso8601_date(file_last_modified, comparison_date))
def generate_xml_for_records(records, directory, prefix="apsharvest_result_", suffix=".xml", pretty=True): """ Given a list of APSRecord objects, generate a MARCXML containing Metadata and FFT for all of them. """ new_filename = get_temporary_file(prefix=prefix, suffix=suffix, directory=directory) generated_xml = '<?xml version="1.0" encoding="UTF-8"?>\n' \ "<collection>\n%s\n</collection>" % \ ("\n".join([record.to_xml() for record in records]),) try: fd = open(new_filename, 'w') fd.write(generated_xml) fd.close() except IOError, e: write_message("\nException caught: %s" % e, sys.stderr) write_message(traceback.format_exc()[:-1]) task_update_status("CERROR") return
def test_date_comparison(self): target_filepath = get_temporary_file(directory="/tmp") file_last_modified = get_file_modified_date(target_filepath) comparison_date = "2013-07-18T16:31:46-0400" self.assertFalse( compare_datetime_to_iso8601_date(file_last_modified, comparison_date)) comparison_date = "2013-07-18T16:31:46Z" self.assertFalse( compare_datetime_to_iso8601_date(file_last_modified, comparison_date))
def test_md5_check(self): """ Test md5 checking done by APS Harvester. """ # Create temporary file to test with hashtarget_filepath = get_temporary_file(directory="/tmp") tmpfd = open(hashtarget_filepath, "w") tmpfd.write("this is a test") tmpfd.close() dirpath, filename = os.path.split(hashtarget_filepath) hashtarget_md5 = calculate_md5_external(hashtarget_filepath) # Create a md5 keyfile looking like: # 54b0c58c7ce9f2a8b551351102ee0938 apsharvest_test_lFecZz md5_keyfile = get_temporary_file(directory="/tmp") tmpfd = open(md5_keyfile, "w") tmpfd.write("%s %s\n" % (hashtarget_md5, filename)) tmpfd.close() dirpath, filename = os.path.split(md5_keyfile) res = find_and_validate_md5_checksums(in_folder=dirpath, md5key_filename=filename) self.assertTrue(len(res) == 1)
def test_md5_check(self): """ Test md5 checking done by APS Harvester. """ # Create temporary file to test with hashtarget_filepath = get_temporary_file(directory="/tmp") tmpfd = open(hashtarget_filepath, 'w') tmpfd.write("this is a test") tmpfd.close() dirpath, filename = os.path.split(hashtarget_filepath) hashtarget_md5 = calculate_md5_external(hashtarget_filepath) # Create a md5 keyfile looking like: # 54b0c58c7ce9f2a8b551351102ee0938 apsharvest_test_lFecZz md5_keyfile = get_temporary_file(directory="/tmp") tmpfd = open(md5_keyfile, 'w') tmpfd.write("%s %s\n" % (hashtarget_md5, filename)) tmpfd.close() dirpath, filename = os.path.split(md5_keyfile) res = find_and_validate_md5_checksums(in_folder=dirpath, md5key_filename=filename) self.assertTrue(len(res) == 1)