internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: fossasia/open-event-server

Issue:
Add event topic 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/event_topic.py b/app/factories/event_topic.py
new file mode 100644
--- /dev/null
+++ b/app/factories/event_topic.py
@@ -0,0 +1,12 @@
+import factory
+from app.models.event_topic import db, EventTopic
+import app.factories.common as common
+
+
+class EventTopicFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = EventTopic
+        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
@@ -23,6 +23,7 @@
 from app.factories.page import PageFactory
 from app.factories.event_type import EventTypeFactory
 from app.factories.discount_code import DiscountCodeFactory
+from app.factories.event_topic import EventTopicFactory
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -1191,7 +1192,10 @@ def event_topic_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_topic = EventTopicFactory()
+        db.session.add(event_topic)
+        db.session.commit()
 
 
 @hooks.before("Event Topics > Event Topics Collection > Create Event Topic")
@@ -1201,7 +1205,7 @@ def event_topic_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    pass
 
 
 @hooks.before("Event Topics > Event Topic Details > Event Topic Details")
@@ -1211,7 +1215,10 @@ def event_topic_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_topic = EventTopicFactory()
+        db.session.add(event_topic)
+        db.session.commit()
 
 
 @hooks.before("Event Topics > Event Topic Details > Update Event Topic")
@@ -1221,7 +1228,10 @@ def event_topic_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_topic = EventTopicFactory()
+        db.session.add(event_topic)
+        db.session.commit()
 
 
 @hooks.before("Event Topics > Event Topic Details > Delete Event Topic")
@@ -1231,7 +1241,10 @@ def event_topic_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event_topic = EventTopicFactory()
+        db.session.add(event_topic)
+        db.session.commit()
 
 
 # ------------------------- Event Sub Topics -------------------------
Repository: fossasia/open-event-server

Issue:
Add sponsors api to dredd testing
parent issue: #3870 


Discussion:

Resolving patch:
diff --git a/app/factories/sponsor.py b/app/factories/sponsor.py
new file mode 100644
--- /dev/null
+++ b/app/factories/sponsor.py
@@ -0,0 +1,18 @@
+import factory
+from app.models.sponsor import db, Sponsor
+from app.factories.event import EventFactoryBasic
+import app.factories.common as common
+
+
+class SponsorFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Sponsor
+        sqlalchemy_session = db.session
+
+    event = factory.RelatedFactory(EventFactoryBasic)
+    name = common.string_
+    description = common.string_
+    url = common.url_
+    level = 1
+    logo_url = common.imageUrl_
+    type = 'Gold'


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -26,6 +26,7 @@
 from app.factories.event_topic import EventTopicFactory
 from app.factories.event_invoice import EventInvoiceFactory
 from app.factories.event_sub_topic import EventSubTopicFactory
+from app.factories.sponsor import SponsorFactory
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -631,7 +632,10 @@ def sponsor_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        sponsor = SponsorFactory()
+        db.session.add(sponsor)
+        db.session.commit()
 
 
 @hooks.before("Sponsors > Sponsors Collection > Create Sponsor")
@@ -641,7 +645,10 @@ def sponsor_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Sponsors > Sponsor Details > Sponsor Details")
@@ -651,7 +658,10 @@ def sponsor_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        sponsor = SponsorFactory()
+        db.session.add(sponsor)
+        db.session.commit()
 
 
 @hooks.before("Sponsors > Sponsor Details > Update Sponsor")
@@ -661,7 +671,10 @@ def sponsor_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        sponsor = SponsorFactory()
+        db.session.add(sponsor)
+        db.session.commit()
 
 
 @hooks.before("Sponsors > Sponsor Details > Delete Sponsor")
@@ -671,7 +684,10 @@ def sponsor_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        sponsor = SponsorFactory()
+        db.session.add(sponsor)
+        db.session.commit()
 
 
 # ------------------------- Tax -------------------------
Repository: fossasia/open-event-server

Issue:
Ensure basic endpoints are accessible without authentication
### Event-related endpoints

- [x] Getting a list of events & details about a single event
- [x] Getting a list of sessions of an event and the details about a single session
- [x] Getting a list of microlocations of an event and the details about a single microlocation
- [x] Getting a list of tracks of an event and the details about a single track
- ~Getting a list of speakers of an event and the details about a single speaker~ [ Edited by Piyush: This need to be done separately since speakers API isn't ready yet ]
- [x] Getting a list of tickets of an event and the details about a single tickets
- [x] Getting call for speakers info of an event
- [x] Getting copyright info of an event


### Other endpoints
- [x] Getting settings (all fields except all client IDs, access tokens, secrets, passwords, email settings). But note, `stripe-publishable-key` is required.
- [x] Getting pages list & detail


Discussion:
I think it requires the permission manager to be completed before this. 
@poush updated the description
@poush what is the progres on this ?
Almost complete. Just need to check some end points. Also, since ~sessions~ speakers API isn't implemented yet so that part is left.
Cool, so we have now `has-PR` label :D
@poush looks like this hasn't been done for event relationships ? 

Eg. like `https://api.eventyay.com/v1/events/1/microlocations`
@poush any updates ?

Resolving patch:
diff --git a/app/api/microlocations.py b/app/api/microlocations.py
--- a/app/api/microlocations.py
+++ b/app/api/microlocations.py
@@ -71,11 +71,10 @@ def before_create_object(self, data, view_kwargs):
         event = self.session.query(Event).filter_by(id=view_kwargs['event_id']).one()
         data['event_id'] = event.id
 
-    decorators = (api.has_permission('is_coorganizer', fetch='event_id', fetch_as="event_id", methods="POST",
-                  check=lambda a: a.get('event_id') or a.get('event_identifier')),)
 
     view_kwargs = True
-    decorators = (jwt_required,)
+    decorators = (api.has_permission('is_coorganizer', fetch='event_id', fetch_as="event_id", methods="POST",
+                  check=lambda a: a.get('event_id') or a.get('event_identifier')),)
     schema = MicrolocationSchema
     data_layer = {'session': db.session,
                   'model': Microlocation,


Test patch:
Repository: fossasia/open-event-server

Issue:
Events routes not working on heroku instance
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->
`https://open-event-api.herokuapp.com/v1/events`
results in an 500 error code after recent PR merge



Discussion:

Resolving patch:
diff --git a/migrations/versions/c8561d8684da_.py b/migrations/versions/c8561d8684da_.py
--- a/migrations/versions/c8561d8684da_.py
+++ b/migrations/versions/c8561d8684da_.py
@@ -22,19 +22,19 @@ def upgrade():
     op.alter_column('sessions', 'audio', new_column_name='audio_url')
     op.alter_column('sessions', 'video', new_column_name='video_url')
 
-    op.alter_column('sessions_versions', 'slides', new_column_name='slides_url')
-    op.alter_column('sessions_versions', 'audio', new_column_name='audio_url')
-    op.alter_column('sessions_versions', 'video', new_column_name='video_url')
+    op.alter_column('sessions_version', 'slides', new_column_name='slides_url')
+    op.alter_column('sessions_version', 'audio', new_column_name='audio_url')
+    op.alter_column('sessions_version', 'video', new_column_name='video_url')
     # ### end Alembic commands ###
 
 
 def downgrade():
     # ### commands auto generated by Alembic - please adjust! ###
-    op.drop_column('sessions', 'video_url', new_column_name='video')
-    op.drop_column('sessions', 'slides_url', new_column_name='audio')
-    op.drop_column('sessions', 'audio_url', new_column_name='slides')
+    op.alter_column('sessions', 'video_url', new_column_name='video')
+    op.alter_column('sessions', 'audio_url', new_column_name='audio')
+    op.alter_column('sessions', 'slides_url', new_column_name='slides')
 
-    op.drop_column('sessions_version', 'video_url', new_column_name='video')
-    op.drop_column('sessions_version', 'slides_url', new_column_name='audio')
-    op.drop_column('sessions_version', 'audio_url', new_column_name='slides')
+    op.alter_column('sessions_version', 'video_url', new_column_name='video')
+    op.alter_column('sessions_version', 'slides_url', new_column_name='slides')
+    op.alter_column('sessions_version', 'audio_url', new_column_name='audio')
     # ### end Alembic commands ###


Test patch:
Repository: fossasia/open-event-server

Issue:
Add Track API to dredd testing
Parent issue #3870 


Discussion:

Resolving patch:
diff --git a/app/factories/track.py b/app/factories/track.py
new file mode 100644
--- /dev/null
+++ b/app/factories/track.py
@@ -0,0 +1,15 @@
+import factory
+from app.models.track import db, Track
+from app.factories.event import EventFactoryBasic
+import app.factories.common as common
+
+
+class TrackFactory(factory.alchemy.SQLAlchemyModelFactory):
+    class Meta:
+        model = Track
+        sqlalchemy_session = db.session
+
+    event = factory.RelatedFactory(EventFactoryBasic)
+    name = common.string_
+    description = common.string_
+    color = "#0f0f0f"


Test patch:
diff --git a/tests/hook_main.py b/tests/hook_main.py
--- a/tests/hook_main.py
+++ b/tests/hook_main.py
@@ -33,6 +33,7 @@
 from app.factories.session import SessionFactory
 from app.factories.ticket import TicketFactory
 from app.factories.attendee import AttendeeFactory
+from app.factories.track import TrackFactory
 
 stash = {}
 api_username = "open_event_test_user@fossasia.org"
@@ -924,7 +925,10 @@ def track_get_list(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        track = TrackFactory()
+        db.session.add(track)
+        db.session.commit()
 
 
 @hooks.before("Tracks > Tracks Collection > Create Track")
@@ -934,7 +938,10 @@ def track_post(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        event = EventFactoryBasic()
+        db.session.add(event)
+        db.session.commit()
 
 
 @hooks.before("Tracks > Track Detail > Get Details")
@@ -944,7 +951,10 @@ def track_get_detail(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        track = TrackFactory()
+        db.session.add(track)
+        db.session.commit()
 
 
 @hooks.before("Tracks > Track Detail > Update Track")
@@ -954,7 +964,10 @@ def track_patch(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        track = TrackFactory()
+        db.session.add(track)
+        db.session.commit()
 
 
 @hooks.before("Tracks > Track Detail > Delete Track")
@@ -964,7 +977,10 @@ def track_delete(transaction):
     :param transaction:
     :return:
     """
-    transaction['skip'] = True
+    with stash['app'].app_context():
+        track = TrackFactory()
+        db.session.add(track)
+        db.session.commit()
 
 
 # ------------------------- Notifications -------------------------
Repository: fossasia/open-event-server

Issue:
Make all query params accept the dasherized version of the attribute names.
Currently the query params, such as 
- [x] sort
- [ ] include
- [ ] filter
- [ ] sparse fieldsets

require the attribute names to be in `snake_case`. But that isn't right since as per our response, the attribute names are dasherized. So, ensure, dasherized attribute names are accepted.




Discussion:

Resolving patch:
diff --git a/config.py b/config.py
--- a/config.py
+++ b/config.py
@@ -56,6 +56,7 @@ class Config(object):
     DATABASE_QUERY_TIMEOUT = 0.1
     SOFT_DELETE = True
     PROPOGATE_ERROR = False
+    DASHERIZE_API = True
 
     if not SQLALCHEMY_DATABASE_URI:
         print('`DATABASE_URL` either not exported or empty')


Test patch:
Repository: fossasia/open-event-server

Issue:
Provide a proper error message HTTP Status code when trying to create a user who already exists.
Currently, if we try to create a user with an email ID that is already in the database, we get an `Internal Server Error` with a status code of `500`. 

Instead, provide a proper error message along with a status code of `409 Conflict`.


Discussion:
@niranjan94 This is specific to users table, right ?
If that's the case I'll simply put a check if the user with the given email exists or not and raise relevant exceptions.
Yep. Specific to the users table. 

Resolving patch:
diff --git a/app/api/helpers/exceptions.py b/app/api/helpers/exceptions.py
--- a/app/api/helpers/exceptions.py
+++ b/app/api/helpers/exceptions.py
@@ -4,3 +4,8 @@
 class UnprocessableEntity(JsonApiException):
     title = "Unprocessable Entity"
     status = 422
+
+
+class ConflictException(JsonApiException):
+    title = "Conflict"
+    status = 409
diff --git a/app/api/users.py b/app/api/users.py
--- a/app/api/users.py
+++ b/app/api/users.py
@@ -11,6 +11,7 @@
 from app.models.notification import Notification
 from app.models.event_invoice import EventInvoice
 from app.api.helpers.permissions import is_admin, is_user_itself, jwt_required
+from app.api.helpers.exceptions import ConflictException
 
 
 class UserSchema(Schema):
@@ -72,10 +73,15 @@ class UserList(ResourceList):
     """
     List and create Users
     """
+    def before_create_object(self, data, view_kwargs):
+        if db.session.query(User.id).filter_by(email=data['email']).scalar() is not None:
+            raise ConflictException({'pointer': '/data/attributes/email'}, "Email already exists")
+
     decorators = (api.has_permission('is_admin', methods="GET"),)
     schema = UserSchema
     data_layer = {'session': db.session,
-                  'model': User}
+                  'model': User,
+                  'methods': {'before_create_object': before_create_object}}
 
 
 class UserDetail(ResourceDetail):


Test patch:
Repository: fossasia/open-event-server

Issue:
Unable to request events using identifier. 
When requesting events using their identifier, it results in `500 Internal Server Error`. 

Eg: 
- https://api.eventyay.com/v1/events/b70d9fd1 
- https://open-event-api.herokuapp.com/v1/events/3d07e4f5

Please ensure such major regressions don't occur in future. It hard to work on clients, when such a major endpoint fails.


Discussion:

Resolving patch:
diff --git a/app/api/__init__.py b/app/api/__init__.py
--- a/app/api/__init__.py
+++ b/app/api/__init__.py
@@ -83,8 +83,9 @@
 api.route(EventList, 'event_list', '/events', '/event-types/<int:event_type_id>/events',
           '/event-topics/<int:event_topic_id>/events',
           '/event-sub-topics/<int:event_sub_topic_id>/events')
-api.route(EventDetail, 'event_detail', '/events/<int:id>', '/events/<identifier>', '/tickets/<int:ticket_id>/event',
-          '/microlocations/<int:microlocation_id>/event', '/social-links/<int:social_link_id>/event',
+api.route(EventDetail, 'event_detail', '/events/<int:id>', '/events/<identifier>',
+          '/tickets/<int:ticket_id>/event', '/microlocations/<int:microlocation_id>/event',
+          '/social-links/<int:social_link_id>/event',
           '/sponsors/<int:sponsor_id>/event', '/tracks/<int:track_id>/event',
           '/speakers-calls/<int:speakers_call_id>/event', '/session-types/<int:session_type_id>/event',
           '/event-copyright/<int:copyright_id>/event', '/tax/<int:tax_id>/event',
diff --git a/app/api/events.py b/app/api/events.py
--- a/app/api/events.py
+++ b/app/api/events.py
@@ -296,7 +296,7 @@ class EventDetail(ResourceDetail):
 
     def before_get_object(self, view_kwargs):
         if view_kwargs.get('identifier'):
-            event = safe_query(self, Event, 'identifier', view_kwargs['event_identifier'], 'event_identifier')
+            event = safe_query(self, Event, 'identifier', view_kwargs['identifier'], 'identifier')
             view_kwargs['id'] = event.id
 
         if view_kwargs.get('sponsor_id') is not None:
@@ -396,7 +396,7 @@ class EventRelationship(ResourceRelationship):
 
     def before_get_object(self, view_kwargs):
         if view_kwargs.get('identifier'):
-            event = self.session.query(Event).filter_by(identifier=view_kwargs['identifier']).one()
+            event = safe_query(self, Event, 'identifier', view_kwargs['identifier'], 'identifier')
             view_kwargs['id'] = event.id
 
     decorators = (jwt_required,)


Test patch:
Repository: fossasia/open-event-server

Issue:
Method to insert session-speaker relationship missing
**I'm submitting a ...**  (check one with "x")
- [x] bug report
- [ ] feature request
- [ ] support request => Please do not submit support requests here, instead ask your query in out Gitter channel at https://gitter.im/fossasia/open-event-orga-server

**Current behavior:**
<!-- Describe how the bug manifests. -->

**Expected behavior:**
Session must be updated with related speakers and data inserted in speakers-session table. 

**Steps to reproduce:**
<!-- If you are able to illustrate the bug or feature request with an example, please provide steps to reproduce -->

**Related code:**

```
insert any relevant code here else remove this section
```

**Other information:**
<!-- List any other information that is relevant to your issue. Stack traces, related issues, suggestions on how to fix, Stack Overflow links, forum links, etc. -->

**System information:** 





Discussion:

Resolving patch:
diff --git a/app/api/speakers.py b/app/api/speakers.py
--- a/app/api/speakers.py
+++ b/app/api/speakers.py
@@ -116,6 +116,9 @@ def before_create_object(self, data, view_kwargs):
         :param view_kwargs:
         :return:
         """
+        if view_kwargs.get('session_id'):
+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
+            data['event_id'] = session.event_id
         if view_kwargs.get('event_id'):
             event = safe_query(self, Event, 'id', view_kwargs['event_id'], 'event_id')
             data['event_id'] = event.id
@@ -124,6 +127,12 @@ def before_create_object(self, data, view_kwargs):
             data['event_id'] = event.id
         data['user_id'] = current_identity.id
 
+    def after_create_object(self, obj, data, view_kwargs):
+        if view_kwargs.get('session_id'):
+            session = safe_query(self, Session, 'id', view_kwargs['session_id'], 'session_id')
+            session.speakers.append(obj)
+            self.session.commit()
+
     view_kwargs = True
     decorators = (api.has_permission('accessible_role_based_events'),)
     schema = SpeakerSchema
@@ -132,7 +141,8 @@ def before_create_object(self, data, view_kwargs):
                   'methods': {
                       'query': query,
                       'before_create_object': before_create_object,
-                      'before_post': before_post
+                      'before_post': before_post,
+                      'after_create_object': after_create_object
                   }}
 
 


Test patch:
Repository: fossasia/open-event-server

Issue:
CommandError: Can't locate revision identified by '01a1fa5b87f5'
https://sentry.eventyay.com/eventyay/api/issues/12/

```
CommandError: Can't locate revision identified by '01a1fa5b87f5'
(21 additional frame(s) were not displayed)
...
  File "alembic/script/revision.py", line 641, in _iterate_revisions
    requested_lowers = self.get_revisions(lower)
  File "alembic/script/revision.py", line 298, in get_revisions
    return sum([self.get_revisions(id_elem) for id_elem in id_], ())
  File "alembic/script/revision.py", line 303, in get_revisions
    for rev_id in resolved_id)
  File "alembic/script/revision.py", line 303, in <genexpr>
    for rev_id in resolved_id)
  File "alembic/script/revision.py", line 358, in _revision_for_ident
    resolved_id)

CommandError: Can't locate revision identified by '01a1fa5b87f5'
```


Discussion:
While attempting to run migrations on a copy of the current production database.

Resolving patch:
diff --git a/migrations/versions/01a1fa5b87f5_.py b/migrations/versions/01a1fa5b87f5_.py
new file mode 100644
--- /dev/null
+++ b/migrations/versions/01a1fa5b87f5_.py
@@ -0,0 +1,26 @@
+"""empty message
+
+Revision ID: 01a1fa5b87f5
+Revises: 652f5bf2e030
+Create Date: 2017-06-26 22:58:10.215164
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '01a1fa5b87f5'
+down_revision = '652f5bf2e030'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.add_column('orders', sa.Column('is_reminder_mail_sent', sa.Boolean(), nullable=True))
+    ### end Alembic commands ###
+
+
+def downgrade():
+    ### commands auto generated by Alembic - please adjust! ###
+    op.drop_column('orders', 'is_reminder_mail_sent')
+    ### end Alembic commands ###
diff --git a/migrations/versions/a1c17effff1d_.py b/migrations/versions/a1c17effff1d_.py
--- a/migrations/versions/a1c17effff1d_.py
+++ b/migrations/versions/a1c17effff1d_.py
@@ -8,7 +8,7 @@
 
 # revision identifiers, used by Alembic.
 revision = 'a1c17effff1d'
-down_revision = '652f5bf2e030'
+down_revision = '01a1fa5b87f5'
 
 from alembic import op
 import sqlalchemy as sa


Test patch: