def test_redact(self): username = "******" password = "******" redacted = "REDACTED" print_statment = f"{username}'s password is {password}," \ + "don't tell anyone" redacted_print = f"{redacted}'s password is {redacted}," \ + "don't tell anyone" outcome = None redacted_list = [username, password] redacted_print_std = RedactedPrint(STDOutOptions.STDOUT, redacted_list) redacted_print_std.enable() file_path = "./TEST_REDACT.txt" with open(file_path, "w+") as content_file: content_file = RedactedFile(content_file, redacted_list) content_file.write(print_statment) with open(file_path, 'r') as content_file: outcome = content_file.read() os.remove(file_path) self.assertEqual(redacted_print, outcome)
def add_new_user_instance(username): file_path = instance_path(state) if not check_user_exists(username): stored_username = custom_hash(username) with open(file_path, "a+") as instance_file: redacted_list = [username] instance_file = RedactedFile(instance_file, redacted_list) instance_file.write("{0} : {1}\n".format(stored_username, os.getpid())) return True return False