Repository: fossasia/open-event-server

Issue:
Add Attendee API to dredd test
parent issue #3870.


Discussion:

Resolving patch:
diff --git a/app/api/attendees.py b/app/api/attendees.py
--- a/app/api/attendees.py
+++ b/app/api/attendees.py
@@ -12,12 +12,12 @@
 
 class AttendeeSchema(Schema):
     """
-    Api schema for Attendee Model
+    Api schema for Ticket Holder Model
     """
 
     class Meta:
         """
-        Meta class for Session Api Schema
+        Meta class for Attendee API Schema
         """
         type_ = 'attendee'
         self_view = 'v1.attendee_detail'
diff --git a/app/api/tickets.py b/app/api/tickets.py
--- a/app/api/tickets.py
+++ b/app/api/tickets.py
@@ -136,7 +136,7 @@ def before_get_object(self, view_kwargs):
     schema = TicketSchema
     data_layer = {'session': db.session,
                   'model': Ticket,
-                  'methods':{
+                  'methods': {
                       'before_get_object': before_get_object
                   }}
 
diff --git a/app/factories/attendee.py b/app/factories/attendee.py
new file mode 100644
--- /dev/null
+++ b/app/factories/attendee.py
@@ -0,0 +1,19 @@
+import factory
+from app.models.ticket_holder import db, TicketHolder
+import app.factories.common as common
+
+
+class AttendeeFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = TicketHolder
+        sqlalchemy_session = db.session
+
+    firstname = common.string_
+    lastname = common.string_
+    email = common.email_
+    address = common.string_
+    city = common.string_
+    state = common.string_
+    country = "IN"
+    is_checked_in = True
+    pdf_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
@@ -30,6 +30,7 @@
 from app.factories.speakers_call import SpeakersCallFactory
 from app.factories.tax import TaxFactory
 from app.factories.ticket import TicketFactory
+from app.factories.attendee import AttendeeFactory
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -93,7 +94,6 @@ def after_each(transaction):
 
 
 # ------------------------- Authentication -------------------------
-
 @hooks.before("Authentication > JWT Authentication > Authenticate and generate token")
 def skip_auth(transaction):
     """
@@ -105,7 +105,6 @@ def skip_auth(transaction):
 
 
 # ------------------------- Users -------------------------
-
 @hooks.before("Users > Users Collection > List All Users")
 def user_get_list(transaction):
     """
@@ -169,7 +168,6 @@ def user_delete(transaction):
 
 
 # ------------------------- Events -------------------------
-
 @hooks.before("Events > Events Collection > List All Events")
 def event_get_list(transaction):
     """
@@ -233,7 +231,6 @@ def event_delete(transaction):
 
 
 # ------------------------- Copyright -------------------------
-
 @hooks.before("Copyright > Event Copyright > Create Event Copyright")
 def copyright_post(transaction):
     """
@@ -287,7 +284,6 @@ def copyright_delete(transaction):
 
 
 # ------------------------- Invoices -------------------------
-
 @hooks.before("Invoices > Event Invoices > Get Event Invoices")
 def invoice_get_list(transaction):
     """
@@ -354,7 +350,6 @@ def invoice_delete(transaction):
 
 
 # ------------------------- Microlocation -------------------------
-
 @hooks.before("Microlocations > Microlocation Collection > List All Microlocations")
 def microlocation_get_list(transaction):
     """
@@ -406,7 +401,6 @@ def microlocation_delete(transaction):
 
 
 # ------------------------- Sessions -------------------------
-
 @hooks.before("Sessions > Sessions Collection > List All Sessions")
 def session_get_list(transaction):
     """
@@ -458,7 +452,6 @@ def session_delete(transaction):
 
 
 # ------------------------- Session Type -------------------------
-
 @hooks.before("Session Type > Session Type Collection > List All Session Types")
 def session_type_get_list(transaction):
     """
@@ -510,7 +503,6 @@ def session_type_delete(transaction):
 
 
 # ------------------------- Social Links -------------------------
-
 @hooks.before("Social Links > Social Links Collection > List All Social Links")
 def social_link_get_list(transaction):
     """
@@ -577,7 +569,6 @@ def social_link_delete(transaction):
 
 
 # ------------------------- Speakers Calls -------------------------
-
 @hooks.before("Speakers Calls > Speakers Call Collection > Get Speakers Call")
 def speakers_call_get(transaction):
     """
@@ -644,7 +635,6 @@ def speakers_call_delete(transaction):
 
 
 # ------------------------- Sponsors -------------------------
-
 @hooks.before("Sponsors > Sponsors Collection > List All Sponsors")
 def sponsor_get_list(transaction):
     """
@@ -711,7 +701,6 @@ def sponsor_delete(transaction):
 
 
 # ------------------------- Tax -------------------------
-
 @hooks.before("Tax > Tax Collection > Create Tax")
 def tax_post(transaction):
     """
@@ -765,7 +754,6 @@ def tax_delete(transaction):
 
 
 # ------------------------- Tickets -------------------------
-
 @hooks.before("Tickets > Tickets Collection > List All Tickets")
 def ticket_get_list(transaction):
     """
@@ -834,9 +822,70 @@ def ticket_delete(transaction):
         db.session.commit()
 
 
+# ---------------------- Attendees (Ticket Holder) ---------------------
+@hooks.before("Attendees > Attendees Collection > List All Attendees")
+def attendee_get_list(transaction):
+    """
+    GET /attendees
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        attendee = AttendeeFactory()
+        db.session.add(attendee)
+        db.session.commit()
+
+
+@hooks.before("Attendees > Attendees Collection > Create Attendee")
+def attendee_post(transaction):
+    """
+    POST /attendees
+    :param transaction:
+    :return:
+    """
+    pass
 
-# ------------------------- Tracks -------------------------
 
+@hooks.before("Attendees > Attendee Details > Attendee Details")
+def attendee_get_detail(transaction):
+    """
+    GET /attendees/1
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        attendee = AttendeeFactory()
+        db.session.add(attendee)
+        db.session.commit()
+
+
+@hooks.before("Attendees > Attendee Details > Update Attendee")
+def attendee_patch(transaction):
+    """
+    PATCH /attendees/1
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        attendee = AttendeeFactory()
+        db.session.add(attendee)
+        db.session.commit()
+
+
+@hooks.before("Attendees > Attendee Details > Delete Attendee")
+def attendee_delete(transaction):
+    """
+    DELETE /attendees/1
+    :param transaction:
+    :return:
+    """
+    with stash['app'].app_context():
+        attendee = AttendeeFactory()
+        db.session.add(attendee)
+        db.session.commit()
+
+
+# ------------------------- Tracks -------------------------
 @hooks.before("Tracks > Tracks Collection > List All Tracks")
 def track_get_list(transaction):
     """
@@ -888,7 +937,6 @@ def track_delete(transaction):
 
 
 # ------------------------- Notifications -------------------------
-
 @hooks.before("Notifications > Notifications Collection > List All Notifications")
 def notification_get_list(transaction):
     """
@@ -955,7 +1003,6 @@ def notification_delete(transaction):
 
 
 # ------------------------- Image Size -------------------------
-
 @hooks.before("Image Size > Image Size Collection > List Image Sizes")
 def image_size_get_list(transaction):
     """
@@ -1019,7 +1066,6 @@ def image_size_delete(transaction):
 
 
 # ------------------------- Pages -------------------------
-
 @hooks.before("Pages > Page Collection > Page Sizes")
 def page_get_list(transaction):
     """
@@ -1083,7 +1129,6 @@ def page_delete(transaction):
 
 
 # ------------------------- Settings -------------------------
-
 @hooks.before("Settings > Settings Details > Show Settings")
 def settings_get_list(transaction):
     """
@@ -1111,7 +1156,6 @@ def settings_patch(transaction):
 
 
 # ------------------------- Discount Codes -------------------------
-
 @hooks.before("Discount Codes > Discount Code Collection > List All Discount Codes")
 def discount_code_get_list(transaction):
     """
@@ -1178,7 +1222,6 @@ def discount_delete(transaction):
 
 
 # ------------------------- Upload -------------------------
-
 @hooks.before("Upload > Image Upload > Upload an Image in temporary location")
 def image_upload_post(transaction):
     """
@@ -1200,7 +1243,6 @@ def file_upload_post(transaction):
 
 
 # ------------------------- Event Types -------------------------
-
 @hooks.before("Event Types > Event Types Collection > List All Event Types")
 def event_type_get_list(transaction):
     """
@@ -1264,7 +1306,6 @@ def event_type_delete(transaction):
 
 
 # ------------------------- Event Topics -------------------------
-
 @hooks.before("Event Topics > Event Topics Collection > List All Event Topics")
 def event_topic_get_list(transaction):
     """
@@ -1328,7 +1369,6 @@ def event_topic_delete(transaction):
 
 
 # ------------------------- Event Sub Topics -------------------------
-
 @hooks.before("Event Sub Topics > Event Sub Topics Collection > List All Event Sub Topics")
 def event_sub_topic_get_list(transaction):
     """
@@ -1394,8 +1434,6 @@ def event_sub_topic_delete(transaction):
         db.session.commit()
 
 # ------------------------- Ticket Fees -------------------------
-
-
 @hooks.before("Ticket Fees > Ticket Fees Collection > List Ticket Fees")
 def ticket_fees_get_list(transaction):
     """