Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
jladrover committed Apr 15, 2024
1 parent bf219bf commit 0943397
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 31 deletions.
44 changes: 22 additions & 22 deletions machine-learning-client/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,28 @@ def test_connect_option_false():
mock_connection.assert_called_once_with(False)


def test_get_emotion_invalid_input():
with open("test1.png", "rb") as file:
image = file.read()
assert get_emotion("test")[:33] == "ERROR: cannot identify image file"
assert get_emotion(image)[:33] == "ERROR: cannot identify image file"

def test_get_emotion_success():
"""Testing connection"""
# pylint: disable=unused-variable
with patch("pymongo.MongoClient") as mock_client:
with patch("pymongo.collection.Collection") as mock_collection:
mock_collection.find_one.return_value = {
"_id": "",
"photo": base64.b64encode(cv2.imread("test1.png")).decode("utf-8"),
}
connect_db(False)

def test_get_emotion_with_image():
"""Testing get_emotion method"""
with open("./test0.png", "rb") as file:
image = file.read()
print(get_emotion(base64.b64encode(image).decode("utf-8")))
# def test_get_emotion_invalid_input():
# with open("test1.png", "rb") as file:
# image = file.read()
# assert get_emotion("test")[:33] == "ERROR: cannot identify image file"
# assert get_emotion(image)[:33] == "ERROR: cannot identify image file"

# def test_get_emotion_success():
# """Testing connection"""
# # pylint: disable=unused-variable
# with patch("pymongo.MongoClient") as mock_client:
# with patch("pymongo.collection.Collection") as mock_collection:
# mock_collection.find_one.return_value = {
# "_id": "",
# "photo": base64.b64encode(cv2.imread("test1.png")).decode("utf-8"),
# }
# connect_db(False)

# def test_get_emotion_with_image():
# """Testing get_emotion method"""
# with open(".machine/test0.png", "rb") as file:
# image = file.read()
# #print(get_emotion(base64.b64encode(image).decode("utf-8")))



19 changes: 10 additions & 9 deletions web-app/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,14 @@ def test_upload_with_invalid_file_type(client):
json_data = response.get_json()
assert json_data['message'] == 'Invalid file type'
os.remove('test_file.txt') # Remove the file after running the test
def test_upload_valid_file(client, test_image_file):
data = {
'photo': (open(test_image_file, 'rb'), test_image_file),
'name': 'test_image'
}
response = client.post('/upload', content_type='multipart/form-data', data=data)
assert response.status_code == 200
json_data = response.get_json()
assert json_data['message'] == 'Image uploaded and processing started.'

# def test_upload_valid_file(client, test_image_file):
# data = {
# 'photo': (open(test_image_file, 'rb'), test_image_file),
# 'name': 'test_image'
# }
# response = client.post('/upload', content_type='multipart/form-data', data=data)
# assert response.status_code == 200
# json_data = response.get_json()
# assert json_data['message'] == 'Image uploaded and processing started.'

0 comments on commit 0943397

Please sign in to comment.