-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9a09176
commit 15f018c
Showing
4 changed files
with
162 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
import typing | ||
from unittest import TestCase | ||
from src.micromodel import model | ||
from pymongo import MongoClient | ||
|
||
client = MongoClient('mongodb://%s:%s/test' % ( | ||
os.getenv('MONGODB_HOST'), | ||
int(os.getenv('MONGODB_PORT', '0')) | ||
)) | ||
|
||
db = client.get_default_database() | ||
|
||
Animal = typing.TypedDict('Animal', { | ||
'name': str, | ||
'specie': typing.Literal[ | ||
'dog', | ||
'bird' | ||
] | ||
}) | ||
|
||
db.drop_collection('animals') | ||
m = model(Animal, coll=db['animals']) | ||
|
||
class TestMongodb(TestCase): | ||
def test_object_equality(self): | ||
m.insert_one({ | ||
'name': 'thor', | ||
'specie': 'dog' | ||
}) | ||
|
||
result = m.find_one({ | ||
'name': 'thor' | ||
}) | ||
|
||
if not result: | ||
raise ValueError() | ||
|
||
self.assertEqual(result['name'], 'thor') | ||
self.assertEqual(result['specie'], 'dog') | ||
|
||
|
||
def test_upsert(self): | ||
m.upsert({ | ||
'name': 'thor', | ||
'specie': 'bird' | ||
}, ['name']) | ||
|
||
result = m.find_one({ | ||
'name': 'thor' | ||
}) | ||
|
||
if not result: | ||
raise ValueError() | ||
|
||
self.assertEqual(result['name'], 'thor') | ||
self.assertEqual(result['specie'], 'bird') |