Repository: fossasia/open-event-server

Issue:
Add Event Type API to dredd testing
Parent issue #3870.


Discussion:
Hi @magdalenesuo!

Looks like you're missing some information we'll need to replicate this issue.

The easier it is for us to decipher an issue with the info provided,
the more likely it is that we'll be able to help.

Please make sure you have the following information in this issue:

1. The current (incorrect) behavior you're seeing.
2. The behavior you expect.
3. The OS version, browser, app, device you use.
4. A [short, self-contained example](http://sscce.org/).

Resolving patch:
diff --git a/app/factories/common.py b/app/factories/common.py
--- a/app/factories/common.py
+++ b/app/factories/common.py
@@ -10,6 +10,7 @@
 currency_ = 'USD'
 float_ = '1.23456789'
 timezone_ = 'UTC'
+slug_ = 'camp-trip-retreat'
 
 def socialUrl_(name):
     return 'https://{}.com/{}'.format(name, name)
diff --git a/app/factories/event_type.py b/app/factories/event_type.py
new file mode 100644
--- /dev/null
+++ b/app/factories/event_type.py
@@ -0,0 +1,12 @@
+import factory
+from app.models.event_type import db, EventType
+import app.factories.common as common
+
+
+class EventTypeFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = EventType
+        sqlalchemy_session = db.session
+
+    name = common.string_
+    slug = common.slug_


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -21,6 +21,7 @@
 from app.factories.social_link import SocialLinkFactory
 from app.factories.image_size import ImageSizeFactory
 from app.factories.page import PageFactory
+from app.factories.event_type import EventTypeFactory
 from app.factories.discount_code import DiscountCodeFactory
 
 stash = {}
@@ -1126,7 +1127,10 @@ def event_type_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_type = EventTypeFactory()
+        db.session.add(event_type)
+        db.session.commit()
 
 
 @hooks.before("Event Types > Event Types Collection > Create Event Type")
@@ -1136,7 +1140,7 @@ def event_type_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    pass
 
 
 @hooks.before("Event Types > Event Type Details > Event Type Details")
@@ -1146,7 +1150,10 @@ def event_type_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_type = EventTypeFactory()
+        db.session.add(event_type)
+        db.session.commit()
 
 
 @hooks.before("Event Types > Event Type Details > Update Event Type")
@@ -1156,7 +1163,10 @@ def event_type_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_type = EventTypeFactory()
+        db.session.add(event_type)
+        db.session.commit()
 
 
 @hooks.before("Event Types > Event Type Details > Delete Event Type")
@@ -1166,7 +1176,10 @@ def event_type_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_type = EventTypeFactory()
+        db.session.add(event_type)
+        db.session.commit()
 
 
 # ------------------------- Event Topics -------------------------