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

Add all words endpoints #1

Merged
merged 1 commit into from
Mar 16, 2024
Merged
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
23 changes: 19 additions & 4 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,32 @@

app = FastAPI()

def get_response(words_list):
def get_word_response(words_list):
return {"word": random.choice(words_list)}

def get_words_list_response(words_list):
return {"words": words_list}

@app.get("/get-so-word")
def get_random_word():
return get_response(words_accordind_dictionary)
return get_word_response(words_accordind_dictionary)

@app.get("/get-host-so-word")
def get_random_host_word():
return get_response(words_accordind_host)
return get_word_response(words_accordind_host)

@app.get("/get-dvinyatin-so-word")
def get_random_dvinyatin_word():
return get_response(words_accordind_Dvinyatin)
return get_word_response(words_accordind_Dvinyatin)

@app.get("/get-all-so-word")
def get_all_words():
return get_words_list_response(words_accordind_dictionary)

@app.get("/get-all-host-so-word")
def get_all_host_words():
return get_words_list_response(words_accordind_host)

@app.get("/get-all-dvinyatin-so-word")
def get_all_dvinyatin_words():
return get_words_list_response(words_accordind_Dvinyatin)
25 changes: 25 additions & 0 deletions test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,28 @@ async def test_get_random_dvinyatin_word():
assert response.status_code == 200
assert "word" in response.json()
assert isinstance(response.json()["word"], str)


@pytest.mark.asyncio
async def test_get_all_words():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
response = await ac.get("/get-all-so-word")
assert response.status_code == 200
assert "words" in response.json()
assert isinstance(response.json()["words"], list)

@pytest.mark.asyncio
async def test_get_all_host_words():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
response = await ac.get("/get-all-host-so-word")
assert response.status_code == 200
assert "words" in response.json()
assert isinstance(response.json()["words"], list)

@pytest.mark.asyncio
async def test_get_all_dvinyatin_words():
async with AsyncClient(transport=ASGITransport(app=app), base_url="http://test") as ac:
response = await ac.get("/get-all-dvinyatin-so-word")
assert response.status_code == 200
assert "words" in response.json()
assert isinstance(response.json()["words"], list)
Loading