Skip to content

Commit

Permalink
Merge pull request #21 from CIAT-DAPA/develop
Browse files Browse the repository at this point in the history
created new entity for suscription
  • Loading branch information
CarlosNasayo authored Jan 14, 2024
2 parents 2350bf7 + 1858dc0 commit 2bb8400
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,7 @@
from .ormWP.models.watershed import Watershed
from .ormWP.models.wp_content import Wpcontent
from .ormWP.models.type_content import Typecontent
from .ormWP.models.waterpoint import Waterpoint
from .ormWP.models.monitored import Monitored
from .ormWP.models.ws_content import Wscontent
from .ormWP.models.suscription import Suscription, Boletin
3 changes: 2 additions & 1 deletion src/ormWP/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
from .models.type_content import Typecontent
from .models.waterpoint import Waterpoint
from .models.monitored import Monitored
from .models.ws_content import Wscontent
from .models.ws_content import Wscontent
from .models.suscription import Suscription, Boletin
2 changes: 2 additions & 0 deletions src/ormWP/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
from .ws_content import Wscontent
from .waterpoint import Waterpoint
from .type_content import Typecontent

from .suscription import Suscription, Boletin
41 changes: 41 additions & 0 deletions src/ormWP/models/suscription.py
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()
38 changes: 38 additions & 0 deletions src/tests/test_boletin.py
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()

0 comments on commit 2bb8400

Please sign in to comment.