Skip to content

Commit

Permalink
code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
TheFJcurve committed Nov 15, 2024
1 parent c0f6b48 commit b2f9def
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 12 deletions.
2 changes: 1 addition & 1 deletion backend/code/p2p_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]]
Expand Down
5 changes: 2 additions & 3 deletions backend/code/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""

import os
import hashlib

from pathlib import Path
from typing import Optional
Expand All @@ -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
Expand All @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion backend/test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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).
"""

Expand Down
9 changes: 5 additions & 4 deletions backend/test/test_file_tokenizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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.
"""

Expand Down
5 changes: 2 additions & 3 deletions backend/test/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
"""
Expand Down

0 comments on commit b2f9def

Please sign in to comment.