-
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.
Merge pull request #21 from CIAT-DAPA/develop
created new entity for suscription
- Loading branch information
Showing
5 changed files
with
87 additions
and
1 deletion.
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,41 @@ | ||
from mongoengine import Document, DateTimeField, StringField, DictField, EnumField, ListField, ReferenceField | ||
from enum import Enum | ||
|
||
class Boletin(Enum): | ||
"""" | ||
Represents the Boletin | ||
""" | ||
ALERT = 'alert' | ||
WEEKLY = 'weekly' | ||
|
||
|
||
|
||
|
||
class Suscription(Document): | ||
"""" | ||
Represents a suscription in the database. | ||
Attributes: | ||
---------- | ||
userId: str | ||
Id of the user suscribed. | ||
boletin: str | ||
type of boletin. | ||
waterpoint: str | ||
id of the waterpoint | ||
trace: dict | ||
manage the trace of the suscription | ||
Methids: | ||
------- | ||
save() | ||
save the object in the database. | ||
delete() | ||
delete the object of the database. | ||
""" | ||
meta = { 'collection': 'suscription'} | ||
|
||
userId = StringField(max_length=150, required=True) | ||
boletin = EnumField(Boletin, required=True) | ||
waterpoint = StringField(max_length=150, required=True) | ||
trace = DictField() |
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,38 @@ | ||
import unittest | ||
from mongoengine import connect, disconnect | ||
import sys | ||
import os | ||
dir_path = os.path.dirname(os.path.realpath(__file__)) | ||
orm_dir_path = os.path.abspath(os.path.join(dir_path, '..')) | ||
sys.path.append(orm_dir_path) | ||
from ormWP.models.suscription import Suscription, Boletin | ||
from datetime import datetime | ||
|
||
# Conectarse a la base de datos de prueba | ||
|
||
|
||
class TestBoletin(unittest.TestCase): | ||
|
||
def setUp(self): | ||
disconnect() | ||
connect('test_water_points', host='mongomock://localhost') | ||
self.suscription = Suscription( | ||
userId='sjcne92929', | ||
boletin=Boletin.ALERT, | ||
waterpoint='1828291jsjsj', | ||
trace={"created": datetime.now(), "updated": datetime.now(), "enabled": True} | ||
) | ||
|
||
def test_create_suscription(self): | ||
self.suscription.save() | ||
self.assertIsNotNone(self.suscription.id) | ||
|
||
print(self.suscription) | ||
|
||
suscription = Suscription.objects(id=self.suscription.id).first() | ||
self.assertEqual(suscription.userId, 'sjcne92929') | ||
self.assertEqual(suscription.boletin, Boletin.ALERT) | ||
self.assertEqual(suscription.waterpoint, '1828291jsjsj') | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |