paulbricman commited on
Commit
154f832
1 Parent(s): 9d8df1f

feat: add basic tests

Browse files
Files changed (3) hide show
  1. main.py +1 -1
  2. requirements.txt +2 -1
  3. test_main.py +21 -0
main.py CHANGED
@@ -19,7 +19,7 @@ app.mount('/assets', StaticFiles(directory='assets'))
19
 
20
  @app.get('/save/lang')
21
  async def save_language(content: str, background_tasks: BackgroundTasks):
22
- if len(content) > 3:
23
  filename = 'conceptarium/' + secrets.token_urlsafe(8) + '.txt'
24
  open(filename, 'w').write(content)
25
  background_tasks.add_task(save, Thought(filename, content, model))
19
 
20
  @app.get('/save/lang')
21
  async def save_language(content: str, background_tasks: BackgroundTasks):
22
+ if len(content) > 0:
23
  filename = 'conceptarium/' + secrets.token_urlsafe(8) + '.txt'
24
  open(filename, 'w').write(content)
25
  background_tasks.add_task(save, Thought(filename, content, model))
requirements.txt CHANGED
@@ -4,4 +4,5 @@ fastapi
4
  Pillow
5
  secrets
6
  aiofiles
7
- python-multipart
 
4
  Pillow
5
  secrets
6
  aiofiles
7
+ python-multipart
8
+ pytest
test_main.py ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi.testclient import TestClient
2
+
3
+ from main import app
4
+
5
+ client = TestClient(app)
6
+
7
+
8
+ def test_read_style():
9
+ response = client.get("/assets/style.css")
10
+ assert response.status_code == 200
11
+
12
+
13
+ def test_save_lang_find_lang_json():
14
+ response = client.get("/save/lang?content=hello")
15
+ assert response.status_code == 200
16
+ response = client.get("/save/lang?content=hey")
17
+ assert response.status_code == 200
18
+ response = client.get("/save/lang?content=transistor")
19
+ assert response.status_code == 200
20
+ response = client.get("/find/lang/json?content=transistor")
21
+ assert response.json()[0]['content'] == 'transistor'