From b2f9def71c6c9590ea345b6e084ea968c2977cb1 Mon Sep 17 00:00:00 2001 From: TheFJcurve Date: Fri, 15 Nov 2024 12:23:11 -0500 Subject: [PATCH] code cleanup --- backend/code/p2p_client.py | 2 +- backend/code/utils.py | 5 ++--- backend/test/common.py | 2 +- backend/test/test_file_tokenizer.py | 9 +++++---- backend/test/test_utils.py | 5 ++--- 5 files changed, 11 insertions(+), 12 deletions(-) diff --git a/backend/code/p2p_client.py b/backend/code/p2p_client.py index 1805fa2..0fa7ac5 100644 --- a/backend/code/p2p_client.py +++ b/backend/code/p2p_client.py @@ -152,7 +152,7 @@ def response_block(self, message): 'type': 'response_block', 'file_id': file_id, 'block_index': block_index, - 'block_data': str(block_data, 'utf-8') + 'block_data': block_data }) caller_ip = self.peers[message["user_id"]] diff --git a/backend/code/utils.py b/backend/code/utils.py index f97d0a9..e382ee0 100644 --- a/backend/code/utils.py +++ b/backend/code/utils.py @@ -5,7 +5,6 @@ """ import os -import hashlib from pathlib import Path from typing import Optional @@ -15,7 +14,7 @@ def custom_encoding(normal_input: any) -> str: """ - Using utf-8 encoding. This is our custom encoding function we use in the entire project, + Using utf-8 encoding. This is our custom encoding function we use in the entire project, we should not use the inbuilt functions. TODO Correct Implementation has to be written @@ -24,7 +23,7 @@ def custom_encoding(normal_input: any) -> str: return normal_input -def custom_decoding(encoded_string: bytes) -> str: +def custom_decoding(encoded_string: any) -> str: """ Assuming that the encoding is utf-8. We should not read the file to get back the original value. diff --git a/backend/test/common.py b/backend/test/common.py index 60b0c92..e45bcb8 100644 --- a/backend/test/common.py +++ b/backend/test/common.py @@ -10,7 +10,7 @@ def write_to_testing_file_and_create_hackthehill(function_name: str, testing_file: str) -> None: """ - Write the function name to the testing file (which is generated as a side effect) and + Write the function name to the testing file (which is generated as a side effect) and generate the hackthehill function (also a side effect). """ diff --git a/backend/test/test_file_tokenizer.py b/backend/test/test_file_tokenizer.py index 339c045..d7e9a64 100644 --- a/backend/test/test_file_tokenizer.py +++ b/backend/test/test_file_tokenizer.py @@ -7,9 +7,10 @@ from code.file_tokenizer import hash_file_blocks, get_block_content from code.utils import custom_encoding -from config import UPLOADS_FOLDER, SOURCES_FOLDER, HASH_EXTENSION from test.common import write_to_testing_file_and_create_hackthehill, remove_files +from config import UPLOADS_FOLDER, SOURCES_FOLDER, HASH_EXTENSION + class TestFileTokenizer(unittest.TestCase): """ @@ -111,9 +112,9 @@ def test_get_block_content_block_out_index_throws_error(self): def test_get_block_content_returns_correct_value(self): """ - Remember that the indexing starts at 0. Given the encoding function, we should see the - correct decoding being applied, such that we don't need to original file to decode the - .hackthehill's content. Now, the data transmission totally depends on the encoding and + Remember that the indexing starts at 0. Given the encoding function, we should see the + correct decoding being applied, such that we don't need to original file to decode the + .hackthehill's content. Now, the data transmission totally depends on the encoding and decoding. """ diff --git a/backend/test/test_utils.py b/backend/test/test_utils.py index d18c4cb..4c36083 100644 --- a/backend/test/test_utils.py +++ b/backend/test/test_utils.py @@ -5,11 +5,10 @@ import os.path import unittest -from code.file_tokenizer import hash_file_blocks from code.utils import find_file, custom_encoding, get_filename_by_file_id, custom_decoding +from test.common import write_to_testing_file_and_create_hackthehill, remove_files from config import SOURCES_FOLDER, CODE_FOLDER, UPLOADS_FOLDER, HASH_EXTENSION -from test.common import write_to_testing_file_and_create_hackthehill, remove_files class TestUtils(unittest.TestCase): @@ -34,7 +33,7 @@ def test_custom_decoding(self): standard_input = "Hi Mom" encoded_input = custom_encoding(standard_input) - self.assertEqual(custom_decoding(encoded_input), str(encoded_input)) + self.assertEqual(custom_decoding(encoded_input), encoded_input) def test_find_file_with_garbage_file_name_returns_none(self): """