-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
47 lines (30 loc) · 1.34 KB
/
test.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import json
from bson import ObjectId
from pymongo import MongoClient
from app import app
client = app.test_client()
connection = MongoClient(app.config['MONGO_URI'])
db = connection.get_database()
def test_object_id_account():
res = client.post("object_id_accounts", json={"name": "my_name"})
val = json.loads(res.get_data().decode("utf-8"))
_id = val["_id"]
assert res.status_code == 201
result = db["object_id_accounts_versions"].count_documents({"_id_document": ObjectId(_id)})
assert result == 1
res = client.patch(f"object_id_accounts/{_id}", json={"name": "my_name_modified"})
assert res.status_code == 200
result = db["object_id_accounts_versions"].count_documents({"_id_document": ObjectId(_id)})
assert result == 2
def test_string_accounts():
_id = str(ObjectId())
res = client.post("string_id_accounts", json={"_id": _id, "name": "my_name"})
val = json.loads(res.get_data().decode("utf-8"))
assert _id == val["_id"]
assert res.status_code == 201
result = db["string_id_accounts_versions"].count_documents({"_id_document": _id})
assert result == 1
res = client.patch(f"string_id_accounts/{_id}", json={"name": "my_name_modified"})
assert res.status_code == 200
result = db["string_id_accounts_versions"].count_documents({"_id_document": _id})
assert result == 2