Skip to content

Commit 51509b1

Browse files
committed
Added checks for bio and tags
1 parent c141d99 commit 51509b1

File tree

2 files changed

+179
-19
lines changed

2 files changed

+179
-19
lines changed

PyMatcha.postman_collection.json

Lines changed: 169 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,6 +1314,106 @@
13141314
{
13151315
"name": "Complete profile",
13161316
"item": [
1317+
{
1318+
"name": "Complete profile bio too short",
1319+
"event": [
1320+
{
1321+
"listen": "test",
1322+
"script": {
1323+
"id": "436c9d4d-2eaf-43ac-b31b-ec1fe6d7b9f2",
1324+
"exec": [
1325+
"var response = JSON.parse(responseBody);",
1326+
"",
1327+
"",
1328+
"pm.test(\"Status code is 400\", function () {",
1329+
" pm.response.to.have.status(400);",
1330+
"});",
1331+
"",
1332+
"tests[\"JSON return code is 400\"] = response.code == 400",
1333+
"",
1334+
"tests[\"success is true\"] = response.success == false",
1335+
"tests[\"Message is correct\"] = response.error.message == \"Bio is too short\"",
1336+
"tests[\"Error type is Bad Request\"] = response.error.type == \"BadRequestError\""
1337+
],
1338+
"type": "text/javascript"
1339+
}
1340+
}
1341+
],
1342+
"request": {
1343+
"method": "POST",
1344+
"header": [],
1345+
"body": {
1346+
"mode": "raw",
1347+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"Bonjour\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1348+
"options": {
1349+
"raw": {
1350+
"language": "json"
1351+
}
1352+
}
1353+
},
1354+
"url": {
1355+
"raw": "{{host}}/profile/complete",
1356+
"host": [
1357+
"{{host}}"
1358+
],
1359+
"path": [
1360+
"profile",
1361+
"complete"
1362+
]
1363+
}
1364+
},
1365+
"response": []
1366+
},
1367+
{
1368+
"name": "Complete profile not enough tags",
1369+
"event": [
1370+
{
1371+
"listen": "test",
1372+
"script": {
1373+
"id": "0e03d610-46cd-4c45-8a10-42cc95f50b6f",
1374+
"exec": [
1375+
"var response = JSON.parse(responseBody);",
1376+
"",
1377+
"",
1378+
"pm.test(\"Status code is 400\", function () {",
1379+
" pm.response.to.have.status(400);",
1380+
"});",
1381+
"",
1382+
"tests[\"JSON return code is 400\"] = response.code == 400",
1383+
"",
1384+
"tests[\"success is true\"] = response.success == false",
1385+
"tests[\"Message is correct\"] = response.error.message == \"At least 3 tags are required\"",
1386+
"tests[\"Error type is Bad Request\"] = response.error.type == \"BadRequestError\""
1387+
],
1388+
"type": "text/javascript"
1389+
}
1390+
}
1391+
],
1392+
"request": {
1393+
"method": "POST",
1394+
"header": [],
1395+
"body": {
1396+
"mode": "raw",
1397+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": {{user_birthdate}}\n}",
1398+
"options": {
1399+
"raw": {
1400+
"language": "json"
1401+
}
1402+
}
1403+
},
1404+
"url": {
1405+
"raw": "{{host}}/profile/complete",
1406+
"host": [
1407+
"{{host}}"
1408+
],
1409+
"path": [
1410+
"profile",
1411+
"complete"
1412+
]
1413+
}
1414+
},
1415+
"response": []
1416+
},
13171417
{
13181418
"name": "Complete profile duplicated tags",
13191419
"event": [
@@ -1364,6 +1464,56 @@
13641464
},
13651465
"response": []
13661466
},
1467+
{
1468+
"name": "Complete profile too young",
1469+
"event": [
1470+
{
1471+
"listen": "test",
1472+
"script": {
1473+
"id": "5abbd6e3-70b6-4d12-a0e3-99f252a00794",
1474+
"exec": [
1475+
"var response = JSON.parse(responseBody);",
1476+
"",
1477+
"",
1478+
"pm.test(\"Status code is 400\", function () {",
1479+
" pm.response.to.have.status(400);",
1480+
"});",
1481+
"",
1482+
"tests[\"JSON return code is 400\"] = response.code == 400",
1483+
"",
1484+
"tests[\"success is true\"] = response.success == false",
1485+
"tests[\"Message is correct\"] = response.error.message == \"You must be 18 years old or older\"",
1486+
"tests[\"Error type is Bad Request\"] = response.error.type == \"BadRequestError\""
1487+
],
1488+
"type": "text/javascript"
1489+
}
1490+
}
1491+
],
1492+
"request": {
1493+
"method": "POST",
1494+
"header": [],
1495+
"body": {
1496+
"mode": "raw",
1497+
"raw": "{\n\t\"orientation\": \"{{user_orientation}}\",\n\t\"bio\": \"{{user_bio}}\",\n\t\"tags\": [\n\t\t\"bot\",\n\t\t\"robot\",\n\t\t\"postman\",\n\t\t\"sex\",\n\t\t\"friends\",\n\t\t\"drink\",\n\t\t\"smoke\"\n\t\t],\n\t\"gender\": \"{{user_gender}}\",\n\t\"birthdate\": 1591307841\n}",
1498+
"options": {
1499+
"raw": {
1500+
"language": "json"
1501+
}
1502+
}
1503+
},
1504+
"url": {
1505+
"raw": "{{host}}/profile/complete",
1506+
"host": [
1507+
"{{host}}"
1508+
],
1509+
"path": [
1510+
"profile",
1511+
"complete"
1512+
]
1513+
}
1514+
},
1515+
"response": []
1516+
},
13671517
{
13681518
"name": "Complete profile",
13691519
"event": [
@@ -3646,109 +3796,109 @@
36463796
],
36473797
"variable": [
36483798
{
3649-
"id": "befd8b3f-9044-4678-9d42-4a6c8338bf11",
3799+
"id": "3243df34-1e09-46d9-a5c9-14fa1d377ae7",
36503800
"key": "host",
36513801
"value": "http://127.0.0.1:5000",
36523802
"type": "string"
36533803
},
36543804
{
3655-
"id": "c4b1b28d-8534-47c2-82c7-860dc212642e",
3805+
"id": "d3fb7ee6-f649-40ba-a1a1-8a54222a905e",
36563806
"key": "user_id",
36573807
"value": "",
36583808
"type": "string"
36593809
},
36603810
{
3661-
"id": "4f7a5f1a-27ef-46df-b07a-5783a0582318",
3811+
"id": "be455f8c-7337-45b5-9fee-f3061099daff",
36623812
"key": "user_email",
36633813
"value": "foo@example.org",
36643814
"type": "string"
36653815
},
36663816
{
3667-
"id": "64c06a4c-82d7-4037-a181-a114c86cb8b1",
3817+
"id": "b5f9e01b-6131-482e-bf54-1590c9dbb641",
36683818
"key": "user_username",
36693819
"value": "foo",
36703820
"type": "string"
36713821
},
36723822
{
3673-
"id": "3434046b-300e-40f3-b9fd-73dd6bc2cd6c",
3823+
"id": "d5a1009c-95b7-42e2-be5d-cd44bf0d0ef0",
36743824
"key": "user_password",
36753825
"value": "admin",
36763826
"type": "string"
36773827
},
36783828
{
3679-
"id": "161c234f-f1f4-4ff5-bc40-657ebcb9f8c5",
3829+
"id": "d1a08ea9-b55b-4d6e-91e4-96cbc1226547",
36803830
"key": "user_firstname",
36813831
"value": "Foo",
36823832
"type": "string"
36833833
},
36843834
{
3685-
"id": "50525fc7-ea75-4c51-96a5-c5c86f23c0b0",
3835+
"id": "c16309d5-3eda-42e7-971e-5bc5f8e48d6e",
36863836
"key": "user_lastname",
36873837
"value": "Bar",
36883838
"type": "string"
36893839
},
36903840
{
3691-
"id": "44de7cd4-5407-4658-8520-6e46691bedc7",
3841+
"id": "28ef92a9-c27d-4c24-a416-99e28aa806ec",
36923842
"key": "debug_token",
36933843
"value": "xX69jules69Xx",
36943844
"type": "string"
36953845
},
36963846
{
3697-
"id": "5f242c9a-b6c8-4629-97d6-43892032c5d1",
3847+
"id": "ccf1a59e-3223-40e4-a185-65a21abea20c",
36983848
"key": "user_access_token",
36993849
"value": "",
37003850
"type": "string"
37013851
},
37023852
{
3703-
"id": "d7266cf0-0862-409b-b5fc-c628b34d0d48",
3853+
"id": "3d4b8b6d-a8d7-44fc-b5b3-425ac33d3b27",
37043854
"key": "user_refresh_token",
37053855
"value": "",
37063856
"type": "string"
37073857
},
37083858
{
3709-
"id": "ea412b72-2502-4e1c-a337-4303217e9567",
3859+
"id": "1bc11bd8-fe77-4801-8c81-90794c1b95d2",
37103860
"key": "expired_token",
37113861
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU",
37123862
"type": "string"
37133863
},
37143864
{
3715-
"id": "15a1e7fa-a337-4a29-8b7f-9678e76ac359",
3865+
"id": "e7c96071-c62d-41bd-99a3-143ee886048e",
37163866
"key": "user_orientation",
37173867
"value": "heterosexual",
37183868
"type": "string"
37193869
},
37203870
{
3721-
"id": "3637321b-78a5-4fdb-b778-0a2be4c1a4c0",
3871+
"id": "8c04f548-8d00-42d5-8524-925da29c837c",
37223872
"key": "user_bio",
37233873
"value": "Lorem Ipsum is the single greatest threat. We are not - we are not keeping up with other websites. Lorem Ipsum best not make any more threats to your website. It will be met with fire and fury like the world has never seen. Does everybody know that pig named Lorem Ipsum? An ‘extremely credible source’ has called my office and told me that Barack Obama’s placeholder text is a fraud.",
37243874
"type": "string"
37253875
},
37263876
{
3727-
"id": "c6b3be30-6f52-484e-bb25-7287064a18d2",
3877+
"id": "ac4953fd-ab5e-4d3c-94c9-9241d176709d",
37283878
"key": "user_gender",
37293879
"value": "male",
37303880
"type": "string"
37313881
},
37323882
{
3733-
"id": "1b2c293e-b2e3-47fb-8843-37dfc40527ef",
3883+
"id": "6cde30ee-9f1d-48a5-9f64-85831089f86e",
37343884
"key": "user_birthdate",
3735-
"value": "1590674628",
3885+
"value": "891871428",
37363886
"type": "string"
37373887
},
37383888
{
3739-
"id": "cfc85af0-71b7-4e21-aec9-e6ed932baa07",
3889+
"id": "6da6191a-5954-4e89-9a50-6e4772e34276",
37403890
"key": "user_lat",
37413891
"value": "44.8404",
37423892
"type": "string"
37433893
},
37443894
{
3745-
"id": "bea4970c-1b1b-495e-aacd-5f28919da8be",
3895+
"id": "b6764588-2618-433c-b462-9907784b47a0",
37463896
"key": "user_lng",
37473897
"value": "-0.5805",
37483898
"type": "string"
37493899
},
37503900
{
3751-
"id": "56bc40c9-b5d0-47bb-bf4c-030cd02f35fb",
3901+
"id": "1db8f131-cc74-4e34-8611-7b0379838411",
37523902
"key": "user_ip",
37533903
"value": "77.205.46.181",
37543904
"type": "string"

backend/PyMatcha/routes/api/profile.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,19 @@ def complete_profile():
7171
gender = data["gender"]
7272
birthdate = data["birthdate"]
7373

74+
if len(bio) <= 50:
75+
raise BadRequestError("Bio is too short", "Try again")
76+
77+
if len(tags) < 3:
78+
raise BadRequestError("At least 3 tags are required", "Try again")
79+
7480
if len(tags) != len(set(tags)):
7581
raise BadRequestError("Duplicate tags", "Try again")
7682

83+
minimum_age = 364.25 * 24 * 60 * 60 * 18
84+
if datetime.datetime.utcnow().timestamp() - birthdate < minimum_age:
85+
raise BadRequestError("You must be 18 years old or older", "Try again later")
86+
7787
for tag in tags:
7888
Tag.create(name=tag, user_id=current_user.id)
7989

0 commit comments

Comments
 (0)