def test_create_artefact(self): # create source fake_src = os.path.join( self.EXAMPLE_PROJECT, "fake_folder_{}".format(self.build.timestamp())) self.build.mkdir(fake_src) fake_src_aux = os.path.join("subfake_folder_{}".format( self.build.timestamp())) for i in range(0, 4): folder = os.path.join(fake_src, fake_src_aux) self.build.mkdir(folder) touch(os.path.join(TESTS_PATH, folder, "test1")) touch(os.path.join(TESTS_PATH, folder, "test2")) fake_src_aux = os.path.join(fake_src_aux, fake_src_aux) # Set destination fake_zip = "fake_zip_{}.zip".format(self.build.timestamp()) dest_folder = os.path.join(self.EXAMPLE_PROJECT, self.DIST_FOLDER) self.build.mkdir(dest_folder) fake_dest_file = os.path.join(dest_folder, fake_zip) # Run result = self.build.create_artefact(fake_src, dest_folder, fake_zip) # Test result fake_dest_file = os.path.join(TESTS_PATH, fake_dest_file) self.assertEqual(result, fake_dest_file) self.assertTrue(os.path.isfile(fake_dest_file)) # remove os.remove(fake_dest_file) shutil.rmtree(os.path.join(TESTS_PATH, fake_src))
def test_disallows_multiple_h1s(self): with temp_directory(): touch('CHANGELOG.md', '# My Changelog\n# Current Release\n') with self.assertRaisesRegexp( Exception, 'Changelog has multiple level 1 headings.'): parse_changelog('CHANGELOG.md')
def test_list_photos(testing_server): users = utils.load_csv(USERS_PATH)[0:3] photos = [ settings.environment["current_year"] + "/a01-" + users[1]["wwuid"] + ".jpg", settings.environment["current_year"] + "/a02-" + users[2]["wwuid"] + ".jpg", "1718" + "/a03-" + users[2]["wwuid"] + ".jpg", ] distutils.dir_util.create_tree( settings.environment["profile_photos_location"], photos) for photo in photos: utils.touch(settings.environment["profile_photos_location"] + "/" + photo) expected_empty_photos = [] session = assert_verify_login(users[0])[1] empty_response = mask_requests.get_list_profile_photos(session) actual_empty_response = json.loads(empty_response.text)["photos"] assert empty_response.status_code == 200 assert actual_empty_response == expected_empty_photos expected_many_photos = ["profiles/" + photo for photo in photos[1:3]] session = assert_verify_login(users[2])[1] many_response = mask_requests.get_list_profile_photos(session) actual_many_response = json.loads(many_response.text)["photos"] assert many_response.status_code == 200 assert len(actual_many_response) == 2 assert set(actual_many_response) == set(expected_many_photos)
def test_creating_file_with_same_name(directory: Directory) -> None: path_string = str(directory) touch(path_string) with pytest.raises(OSError): directory.exists()
def test_loading_multiple_file(self): with temp_directory(): touch('.maintain.yaml') touch('.maintain.yml') with self.assertRaises(Exception): Configuration.load()
def fill_directory(path_string_with_counts: Tuple[str, int, int]) -> str: (path_string, sub_directories_count, sub_files_count) = path_string_with_counts for _ in range(sub_directories_count): mkdtemp(dir=path_string) for _ in range(sub_files_count): touch(mktemp(dir=path_string)) return path_string
def test_disallows_heading_level_jump(self): with temp_directory(): touch('CHANGELOG.md', '# H1\n#### H3\n') with self.assertRaisesRegexp( Exception, 'Changelog heading level jumps from level 1 to level 4. Must jump one level per heading.' ): parse_changelog('CHANGELOG.md')
def test_disallows_heading_level_3_without_release(self): with temp_directory(): touch('CHANGELOG.md', '# H1\n### H3\n') with self.assertRaisesRegexp( Exception, 'Level 3 heading was not found within a release \(level 2 heading\)' ): parse_changelog('CHANGELOG.md')
def test_disallows_missing_h1(self): with temp_directory(): touch('CHANGELOG.md', 'Hello World') with self.assertRaisesRegexp( Exception, 'Changelog does not start with a level 1 heading, including the changelog name.' ): parse_changelog('CHANGELOG.md')
def test_retrieves_only_changelog(self): with temp_directory(): touch( 'CHANGELOG.md', '# My Changelog\n## Current Release\n\nThe Release Information' ) changelog = extract_last_changelog('CHANGELOG.md') self.assertEqual(changelog, 'The Release Information')
def create_zip(cls, fname): example_file = fname + ".txt" zip_file = fname + ".zip" touch(example_file) zfh = zipfile.ZipFile(fname + ".zip", 'w', zipfile.ZIP_DEFLATED) zfh.write(example_file) zfh.close() os.remove(example_file) return zip_file
def assert_upload_resume_success(session, resume_file_name, job_id): resume_location = environment["temporary_files"] + "/" + resume_file_name distutils.dir_util.create_tree(environment["resumes_location"], [resume_file_name]) utils.touch(resume_location) file_content = resume_file_name + " contents" file_object = open(resume_location, 'w+') file_object.write(file_content) file_object.close() file = {'file': open(resume_location, "r")} response = post_resume_upload(file, job_id, session) file["file"].close() assert response.status_code == 201 assert response.json() == {"status": "Submitted"} return response, file_content
def make_existent(file_path_string: str) -> str: touch(file_path_string) return file_path_string
def test_loading_file_validation(self): with temp_directory(): touch('.maintain.yml', 'release: []') with self.assertRaises(Exception): configuration.load()
def test_loading_file_config_maintain_yaml(self): with temp_directory(): touch('.maintain/config.yaml', 'release:\n test: {}') configuration = Configuration.load() self.assertEqual(configuration.release.get('test'), {})