Repository: fossasia/open-event-server

Issue:
Add microlocations api to testing
parent issue: #3870 


Discussion:

Resolving patch:
diff --git a/app/factories/microlocation.py b/app/factories/microlocation.py
new file mode 100644
--- /dev/null
+++ b/app/factories/microlocation.py
@@ -0,0 +1,17 @@
+import factory
+from app.models.microlocation import db, Microlocation
+from app.factories.event import EventFactoryBasic
+import app.factories.common as common
+
+
+class MicrolocationFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Microlocation
+        sqlalchemy_session = db.session
+
+    event = factory.RelatedFactory(EventFactoryBasic)
+    name = common.string_
+    latitude = common.float_
+    longitude = common.float_
+    floor = common.int_
+    room = common.string_


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -17,6 +17,7 @@
 from app.factories.notification import NotificationFactory
 from app.factories.event import EventFactoryBasic
 from app.factories.social_link import SocialLinkFactory
+from app.factories.microlocation import MicrolocationFactory
 from app.factories.image_size import ImageSizeFactory
 from app.factories.page import PageFactory
 from app.factories.event_copyright import EventCopyrightFactory
@@ -358,7 +359,10 @@ def microlocation_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        microlocation = MicrolocationFactory()
+        db.session.add(microlocation)
+        db.session.commit()
 
 
 @hooks.before("Microlocations > Microlocation Collection > Create Microlocation")
@@ -368,7 +372,10 @@ def microlocation_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Microlocations > Microlocation Details > Mictolocation Details")
@@ -378,7 +385,10 @@ def microlation_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        microlocation = MicrolocationFactory()
+        db.session.add(microlocation)
+        db.session.commit()
 
 
 @hooks.before("Microlocations > Microlocation Details > Update Microlocation")
@@ -388,7 +398,10 @@ def microlocation_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        microlocation = MicrolocationFactory()
+        db.session.add(microlocation)
+        db.session.commit()
 
 
 @hooks.before("Microlocations > Microlocation Details > Delete Microlocation")
@@ -398,7 +411,10 @@ def microlocation_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        microlocation = MicrolocationFactory()
+        db.session.add(microlocation)
+        db.session.commit()
 
 
 # ------------------------- Sessions -------------------------