Skip to content

Commit 1dc067f

Browse files
committed
Added postman tests for conversations
1 parent ef8c6ea commit 1dc067f

File tree

2 files changed

+231
-23
lines changed

2 files changed

+231
-23
lines changed

PyMatcha.postman_collection.json

Lines changed: 227 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5225,6 +5225,215 @@
52255225
}
52265226
},
52275227
"response": []
5228+
},
5229+
{
5230+
"name": "Like message_me message",
5231+
"event": [
5232+
{
5233+
"listen": "test",
5234+
"script": {
5235+
"id": "45228336-12aa-41a5-a29a-8548f20f17b5",
5236+
"exec": [
5237+
"var response = JSON.parse(responseBody);",
5238+
"",
5239+
"",
5240+
"pm.test(\"Status code is 200\", function () {",
5241+
" pm.response.to.have.status(200);",
5242+
"});",
5243+
"",
5244+
"tests[\"Message is correct\"] = response.message == \"Liked message 2.\""
5245+
],
5246+
"type": "text/javascript"
5247+
}
5248+
}
5249+
],
5250+
"request": {
5251+
"method": "POST",
5252+
"header": [],
5253+
"url": {
5254+
"raw": "{{host}}/messages/like/2",
5255+
"host": [
5256+
"{{host}}"
5257+
],
5258+
"path": [
5259+
"messages",
5260+
"like",
5261+
"2"
5262+
]
5263+
}
5264+
},
5265+
"response": []
5266+
},
5267+
{
5268+
"name": "Get conversation with yourself",
5269+
"event": [
5270+
{
5271+
"listen": "test",
5272+
"script": {
5273+
"id": "358bff1a-c455-4edb-8021-8ffd85ba810c",
5274+
"exec": [
5275+
"var response = JSON.parse(responseBody);",
5276+
"",
5277+
"",
5278+
"pm.test(\"Status code is 400\", function () {",
5279+
" pm.response.to.have.status(400);",
5280+
"});",
5281+
"",
5282+
"tests[\"JSON return code is 400\"] = response.code == 400",
5283+
"",
5284+
"tests[\"success is false\"] = response.success == false",
5285+
"tests[\"Message is correct\"] = response.error.message == \"Cannot get conversation with yourself. Get a life...\"",
5286+
"tests[\"Error type is Bad Request\"] = response.error.type == \"BadRequestError\""
5287+
],
5288+
"type": "text/javascript"
5289+
}
5290+
}
5291+
],
5292+
"request": {
5293+
"method": "GET",
5294+
"header": [],
5295+
"url": {
5296+
"raw": "{{host}}/conversations/{{user_username}}",
5297+
"host": [
5298+
"{{host}}"
5299+
],
5300+
"path": [
5301+
"conversations",
5302+
"{{user_username}}"
5303+
]
5304+
}
5305+
},
5306+
"response": []
5307+
},
5308+
{
5309+
"name": "Get conversation with message_me",
5310+
"event": [
5311+
{
5312+
"listen": "test",
5313+
"script": {
5314+
"id": "208cbcfd-f990-4a68-9d3d-56946ebd7f13",
5315+
"exec": [
5316+
"var response = JSON.parse(responseBody);",
5317+
"",
5318+
"",
5319+
"pm.test(\"Status code is 200\", function () {",
5320+
" pm.response.to.have.status(200);",
5321+
"});",
5322+
"",
5323+
"tests[\"Conversations is empty\"] = response.messages.length == 2",
5324+
"tests[\"First message content\"] = response.messages[0].content == \"Hello World !\"",
5325+
"tests[\"Second message content\"] = response.messages[1].content == \"My Reply\"",
5326+
"tests[\"First message is_liked\"] = response.messages[0].is_liked == false",
5327+
"tests[\"Second message is liked\"] = response.messages[1].is_liked == true",
5328+
"tests[\"First message is seen\"] = response.messages[0].is_seen == false",
5329+
"tests[\"Second message is seen\"] = response.messages[1].is_seen == true",
5330+
"",
5331+
""
5332+
],
5333+
"type": "text/javascript"
5334+
}
5335+
}
5336+
],
5337+
"request": {
5338+
"method": "GET",
5339+
"header": [],
5340+
"url": {
5341+
"raw": "{{host}}/conversations/message_me",
5342+
"host": [
5343+
"{{host}}"
5344+
],
5345+
"path": [
5346+
"conversations",
5347+
"message_me"
5348+
]
5349+
}
5350+
},
5351+
"response": []
5352+
},
5353+
{
5354+
"name": "Send message to message_me2",
5355+
"event": [
5356+
{
5357+
"listen": "test",
5358+
"script": {
5359+
"id": "e106fa57-56de-4eb6-b564-5197e097ad91",
5360+
"exec": [
5361+
"var response = JSON.parse(responseBody);",
5362+
"",
5363+
"",
5364+
"pm.test(\"Status code is 200\", function () {",
5365+
" pm.response.to.have.status(200);",
5366+
"});",
5367+
"",
5368+
"tests[\"Message is correct\"] = response.message == \"Message successfully sent to message_me2.\""
5369+
],
5370+
"type": "text/javascript"
5371+
}
5372+
}
5373+
],
5374+
"request": {
5375+
"method": "POST",
5376+
"header": [],
5377+
"body": {
5378+
"mode": "raw",
5379+
"raw": "{\n \"to_uid\": \"message_me2\",\n \"content\": \"Hello World 2 !\"\n}",
5380+
"options": {
5381+
"raw": {
5382+
"language": "json"
5383+
}
5384+
}
5385+
},
5386+
"url": {
5387+
"raw": "{{host}}/messages/send",
5388+
"host": [
5389+
"{{host}}"
5390+
],
5391+
"path": [
5392+
"messages",
5393+
"send"
5394+
]
5395+
}
5396+
},
5397+
"response": []
5398+
},
5399+
{
5400+
"name": "Get conversations after message to 2",
5401+
"event": [
5402+
{
5403+
"listen": "test",
5404+
"script": {
5405+
"id": "f7240da9-b01f-4485-81ab-8461fb6bb138",
5406+
"exec": [
5407+
"var response = JSON.parse(responseBody);",
5408+
"",
5409+
"",
5410+
"pm.test(\"Status code is 200\", function () {",
5411+
" pm.response.to.have.status(200);",
5412+
"});",
5413+
"",
5414+
"tests[\"Conversations is empty\"] = response.conversations.length == 2",
5415+
"tests[\"Message is not unseen because you send the message so it's not notified\"] = response.conversations[0].is_unseen == false",
5416+
"tests[\"Message content is correct\"] = response.conversations[1].last_message_content == \"Hello World 2 !\"",
5417+
"tests[\"With user is correct\"] = response.conversations[1].with_user.username == \"message_me2\""
5418+
],
5419+
"type": "text/javascript"
5420+
}
5421+
}
5422+
],
5423+
"request": {
5424+
"method": "GET",
5425+
"header": [],
5426+
"url": {
5427+
"raw": "{{host}}/conversations",
5428+
"host": [
5429+
"{{host}}"
5430+
],
5431+
"path": [
5432+
"conversations"
5433+
]
5434+
}
5435+
},
5436+
"response": []
52285437
}
52295438
],
52305439
"protocolProfileBehavior": {}
@@ -5387,92 +5596,92 @@
53875596
],
53885597
"variable": [
53895598
{
5390-
"id": "5fcfdcdb-328d-498f-8380-16a9b5bdca8a",
5599+
"id": "3e3e4438-8401-4003-abcf-5d074c05f462",
53915600
"key": "host",
53925601
"value": "http://127.0.0.1:5000"
53935602
},
53945603
{
5395-
"id": "dab86578-2e2b-41a2-88d4-409e525be120",
5604+
"id": "474531ad-c989-4d92-8542-337ce9b010e1",
53965605
"key": "user_id",
53975606
"value": ""
53985607
},
53995608
{
5400-
"id": "c7febd70-a041-480e-90e1-0d6ea277d21f",
5609+
"id": "072156e0-a96d-451f-abf8-f77280d4ffda",
54015610
"key": "user_email",
54025611
"value": "foo@example.org"
54035612
},
54045613
{
5405-
"id": "5e40a0df-d248-4a66-9e7f-d3a1a103b283",
5614+
"id": "3f4e4d49-011e-453c-9117-b0a38d6adcb3",
54065615
"key": "user_username",
54075616
"value": "foo"
54085617
},
54095618
{
5410-
"id": "38c7c7a1-e11a-4b48-8c0c-86eba67b559d",
5619+
"id": "e9a11cb6-74ce-42a5-8450-47fd021358e8",
54115620
"key": "user_password",
54125621
"value": "admin"
54135622
},
54145623
{
5415-
"id": "ac4bd9d8-eb4a-4eab-b5cf-18cfc0570ba3",
5624+
"id": "1075fff5-b05b-4050-922d-00549dd85896",
54165625
"key": "user_firstname",
54175626
"value": "Foo"
54185627
},
54195628
{
5420-
"id": "62ba5bdf-3d88-47e4-ab81-3cb55c5afcc3",
5629+
"id": "f792f8dc-f93f-422d-af8e-aadf547442a3",
54215630
"key": "user_lastname",
54225631
"value": "Bar"
54235632
},
54245633
{
5425-
"id": "735e4af6-1136-4c7a-b26f-d872b3054d5a",
5634+
"id": "9b71ed57-93df-404e-baf0-35ec160bf68d",
54265635
"key": "debug_token",
54275636
"value": "xX69jules69Xx"
54285637
},
54295638
{
5430-
"id": "c3bf9057-c4fd-47f4-9be3-870e097c5d27",
5639+
"id": "da9ec2ea-a081-49e1-862b-95b0dc2b2bb7",
54315640
"key": "user_access_token",
54325641
"value": ""
54335642
},
54345643
{
5435-
"id": "4c6d5f6a-6502-4a17-ae46-6f8d197b66d9",
5644+
"id": "66dd29f6-acb0-4886-8391-b0c6f20d3956",
54365645
"key": "user_refresh_token",
54375646
"value": ""
54385647
},
54395648
{
5440-
"id": "e15b42ce-f7a7-4c84-b95c-4a276ac81dbb",
5649+
"id": "d6e6a5c5-4d70-465c-8d89-b8845a7a6d20",
54415650
"key": "expired_token",
54425651
"value": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpYXQiOjE1OTAyNDIyNjQsIm5iZiI6MTU5MDI0MjI2NCwianRpIjoiNTM0ZGI5NzQtOWE4Ni00MGViLWE1NDEtMDg3N2ZmNzQ3NDVhIiwiZXhwIjoxNTkwMjQyMzI0LCJpZGVudGl0eSI6eyJpZCI6NTEyLCJlbWFpbCI6ImZvb0BleGFtcGxlLm9yZyIsInVzZXJuYW1lIjoiYmFyIiwiaXNfb25saW5lIjp0cnVlLCJkYXRlX2xhc3RzZWVuIjoiU2F0LCAyMyBNYXkgMjAyMCAxMzo1Nzo0NCBHTVQifSwiZnJlc2giOnRydWUsInR5cGUiOiJhY2Nlc3MifQ.NTp2P0WNkXDwzuzrcNIQdeAfizQ57HQgkzBLSvY1yHU"
54435652
},
54445653
{
5445-
"id": "e800e15b-b380-45bc-92b8-a03ddd47c2af",
5654+
"id": "e7b3105e-0c77-41bf-9444-d83010cb5edf",
54465655
"key": "user_orientation",
54475656
"value": "heterosexual"
54485657
},
54495658
{
5450-
"id": "62dae0ab-ab8c-41e2-8d0d-d8becc86493a",
5659+
"id": "35bff664-ee13-4ad1-84b8-ceec64e1115f",
54515660
"key": "user_bio",
54525661
"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."
54535662
},
54545663
{
5455-
"id": "c001f9e7-1711-4126-83a1-8a7429e24484",
5664+
"id": "7dc06bee-b732-42b7-9323-d00a15906a34",
54565665
"key": "user_gender",
54575666
"value": "male"
54585667
},
54595668
{
5460-
"id": "811072c0-a31a-4f0a-a62b-6b2e485bfb5a",
5669+
"id": "070c3cca-ff6a-48da-8adc-aef32fc0ef32",
54615670
"key": "user_birthdate",
54625671
"value": "06/04/1998"
54635672
},
54645673
{
5465-
"id": "bf3cd0e3-4f1f-45f3-ba16-c376b3f50d28",
5674+
"id": "1f84e84c-4b02-4fa9-8e80-21988282ee29",
54665675
"key": "user_lat",
54675676
"value": "44.8404"
54685677
},
54695678
{
5470-
"id": "8bcf8b8c-798d-497b-a3d7-e92639ed55d1",
5679+
"id": "bc34d6a4-ca83-4f7a-b3de-e62290c1084d",
54715680
"key": "user_lng",
54725681
"value": "-0.5805"
54735682
},
54745683
{
5475-
"id": "688313b7-700a-4f16-bafe-c0ecb27ef1b6",
5684+
"id": "51ec8aee-c8a3-4bae-8fdb-b40aba5dabad",
54765685
"key": "user_ip",
54775686
"value": "77.205.46.181"
54785687
}

backend/PyMatcha/routes/api/messages.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,6 @@
3636

3737
messages_bp = Blueprint("messages", __name__)
3838

39-
"""
40-
test more than one conv
41-
conv with user route
42-
"""
43-
4439

4540
@messages_bp.route("/conversations", methods=["GET"])
4641
@jwt_required
@@ -87,6 +82,10 @@ def get_conversation_messsages(with_uid):
8782
with_user = get_user(with_uid)
8883
except NotFoundError:
8984
raise NotFoundError("With user {} not found")
85+
86+
if with_user.id == current_user.id:
87+
raise BadRequestError("Cannot get conversation with yourself. Get a life...")
88+
9089
message_list = current_user.get_messages_with_user(with_user.id)
9190
message_list = [m.to_dict() for m in message_list]
9291
return SuccessOutput("messages", message_list)

0 commit comments

Comments
 (0)