Repository: fossasia/open-event-server

Issue:
Add events api for dredd testing
parent issue: #3870 


Discussion:

Resolving patch:
diff --git a/app/factories/common.py b/app/factories/common.py
--- a/app/factories/common.py
+++ b/app/factories/common.py
@@ -5,7 +5,11 @@
 url_ = 'http://example.com'
 imageUrl_ = 'http://example.com/example.png'
 date_ = '2016-12-13T23:59:59.123456+00:00'
-
+dateEnd_ = '2016-12-14T23:59:59.123456+00:00'
+country_ = 'US'
+currency_ = 'USD'
+float_ = '1.23456789'
+timezone_ = 'UTC'
 
 def socialUrl_(name):
     return 'https://{}.com/{}'.format(name, name)
diff --git a/app/factories/event.py b/app/factories/event.py
new file mode 100644
--- /dev/null
+++ b/app/factories/event.py
@@ -0,0 +1,47 @@
+import factory
+from app.models.event import db, Event
+import app.factories.common as common
+
+
+class EventFactoryBasic(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Event
+        sqlalchemy_session = db.session
+
+    name = common.string_
+    event_url = common.url_
+    starts_at = common.date_
+    ends_at = common.dateEnd_
+    timezone = common.timezone_
+    latitude = common.float_
+    longitude = common.float_
+    logo_url = common.imageUrl_
+    location_name = common.string_
+    searchable_location_name = common.string_
+    description = common.string_
+    original_image_url = common.imageUrl_
+    organizer_name = common.string_
+    is_map_shown = True
+    organizer_description = common.string_
+    is_sessions_speakers_enabled = True
+    privacy = "public"
+    state = common.string_
+    ticket_url = common.url_
+    code_of_conduct = common.string_
+    is_ticketing_enabled = True
+    payment_country = common.country_
+    payment_currency = common.currency_
+    paypal_email = common.email_
+    is_tax_enabled = True
+    can_pay_by_paypal = True
+    can_pay_by_stripe = True
+    can_pay_by_cheque = True
+    can_pay_by_bank = True
+    can_pay_onsite = True
+    cheque_details = common.string_
+    bank_details = common.string_
+    onsite_details = common.string_
+    is_sponsors_enabled = False
+    pentabarf_url = common.url_
+    ical_url = common.url_
+    xcal_url = common.url_


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -15,6 +15,7 @@
 # imports from factories
 from app.factories.user import UserFactory
 from app.factories.notification import NotificationFactory
+from app.factories.event import EventFactoryBasic
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -161,7 +162,10 @@ def event_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Events > Events Collection > Create Event")
@@ -181,7 +185,10 @@ def event_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Events > Event Details > Update Event")
@@ -191,7 +198,10 @@ def event_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Events > Event Details > Delete Event")
@@ -201,7 +211,10 @@ def event_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 # ------------------------- Copyright -------------------------