Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running user_input tests #72

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions product_selection/user_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ def input_to_json(self, type):
raw_input = None

if type == 'who':
example_output = '\n\nEXAMPLE OUTPUT:{\"Age\":\"22\",\"Sex\":\"Female\",\"Skin Tone\":\"Olive\",\"Skin Type\":\"Oily\"}'
example_output = '\n\nEXAMPLE OUTPUT:{\"Age\":\"22\",\"Sex\":\"Female\",\"Ethnicity\":\"Mixed\",\"Skin Tone\":\"Olive\",\"Skin Type\":\"Oily\",\"Conditions\":\"Acne\",\"Allergies\":\"Fragrance\"}'
message = "Extract user information (in JSON format - in one line) from the following string (for Products category, return a comma-separated string and use only singular nouns): " + raw_input + example_output
elif type == 'what':
example_output = '\n\nEXAMPLE OUTPUT:{\"Products\":\"Foundation\",\"Price\":\"40\",\"Brand\":\"Dior\"}'
message = "Extract user information (in JSON format - in one line) from the following string. For Price, always return a specific number (if 'around X' is given, use X; if no price mentioned, use 50; if 'cheap' or 'affordable', use 25; if 'expensive' or 'high-end', use 100): " + raw_input + example_output
example_output = '\n\nEXAMPLE OUTPUT:{\"Products\":\"Foundation\",\"Price\":\"40\",\"Brand\":\"Dior\",\"Finish\":\"Matte\",\"Without\":\"Petrolatum\",\"Purpose\":\"Soothing\",\"Specification\":\"Hypoallergenic\"}'
message = "Extract user information (in JSON format - in one line) from the following string. Use antonyms or synonyms where necessary. For Price, always return a specific number (if 'around X' is given, use X; if no price mentioned, use 50; if 'cheap' or 'affordable', use 25; if 'expensive' or 'high-end', use 100): " + raw_input + example_output
else:
example_output = ""
message = ""
Expand Down Expand Up @@ -91,6 +91,7 @@ def input_to_json(self, type):
break

# For debugging purposes
print("internal")
print(reply)

# debug and check if reply is empty or doesn't make sense
Expand Down
18 changes: 18 additions & 0 deletions tests/test_shopping_site.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import pytest
from shopping_site import app
from flask import Flask, session, request, redirect, url_for

@pytest.fixture
def client():
with app.test_client() as client:
yield client

def test_landing_who_get(client):
response = client.get('/')
assert response.status_code == 200 # page loads successfully

def test_landing_who_with_cookie(client):
client.set_cookie('userdetails', 'I am a 23 year-old Asian woman with oily sensitive skin and light-medium complexion')
response = client.get('/')
assert response.status_code == 302 # redirect
assert response.location == url_for('landing_what')
64 changes: 64 additions & 0 deletions tests/test_user_input.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import pytest
import json
from product_selection.user_input import UserInput
from product_selection.key import API_key

@pytest.fixture
def u():
who = "I am 60 year old woman with sun spots and wrinkles"
what = "I want a serum that fades hyperpigmentation and a mineral sunscreen, I don't have a price range"
return UserInput(API_key, who, what)

@pytest.fixture
def arr_who():
return ["60", "sun", "spot", "wrinkle"]

@pytest.fixture
def arr_what():
return ["serum", "pigment", "mineral", "sun"]

def test_who_you_are(u, arr_who):
u.input_to_json('who')
check = u.input_who
print(check)
# assert False
ch = json.loads(check)
for key, value in ch.items():
if isinstance(value, str):
ch[key] = value.lower()
for word in arr_who:
res = False
for v in ch.values():
if word in v:
res = True
break
print(word)
assert res


def test_what_you_want(u, arr_what):
u.input_to_json('what')
check = u.input_what
print(check)
# assert False
ch = json.loads(check)
for key, value in ch.items():
if isinstance(value, str):
ch[key] = value.lower()
for word in arr_what:
res = False
for v in ch.values():
if word in v:
res = True
break
print(word)
assert res # mostly correct but test is having issues with lists in price ranges

def test_is_json(): # already covered in code
""" try:
json.loads(input)
return True
except ValueError:
return False """
pass

30 changes: 30 additions & 0 deletions tests/testcases.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FORMAT:
who
expected json
what
expected json

who = "I am a 23 year-old Asian woman with oily sensitive skin and light-medium complexion"
["23", "asian", "oily", "sensitive", "light", "medium"]
what = "I want an exfoliating toner, lip balm, and eyeliner, each under $30"
["exfoliat", "toner", "lip", "balm", "eyeliner", "30"] -> test fails sometimes when correct

who = "I am teenager with dry lips"
["teen", "dry", "lips"] -> dry is attached to skin tye instead of lips
what = "I want a high-shine lip gloss"
["shin", "lip", "gloss"] -> shine: high is a category

who = "I am teenager with eczema and acne"
["teen", "acne", "eczema"]
what = "I want a gentle cleanser and retinoid"
["cleanser", "gentle", "retinoid"]

who = "I am a college student with oily skin and a damaged skin barrier"
["college", "oily", "damaged"]
what = "I want an affordable moisturizer that will repair my skin but isn't too heavy"
["moisturizer", "repair", "light"]

who = "I am 60 year old woman with sun spots and wrinkles"
["60", "sun", "spot", "wrinkle"]
what = "I want a serum that fades hyperpigmentation and a mineral sunscreen, I don't have a price range"
["serum", "pigment", "mineral", "sun"] -> misses some things sometimes (for example, when i used dark spots it didn't include that)