Skip to content

Commit 49ffdf6

Browse files
prabhupantdr0pdb
authored andcommitted
test: Add API blueprints for user favourite events (#5506)
1 parent 7ae3091 commit 49ffdf6

File tree

3 files changed

+248
-0
lines changed

3 files changed

+248
-0
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import factory
2+
3+
from app.factories.user import UserFactory
4+
from app.factories.event import EventFactoryBasic
5+
from app.models.user_favourite_event import db, UserFavouriteEvent
6+
7+
8+
class UserFavouriteEventFactory(factory.alchemy.SQLAlchemyModelFactory):
9+
class Meta:
10+
model = UserFavouriteEvent
11+
sqlalchemy_session = db.session
12+
13+
user = factory.RelatedFactory(UserFactory)
14+
event = factory.RelatedFactory(EventFactoryBasic)

docs/api/api_blueprint.apib

Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25337,3 +25337,183 @@ Get the details of the panel permission.
2533725337
"version": "1.0"
2533825338
}
2533925339
}
25340+
25341+
# Group Favourite Events
25342+
25343+
This Group's APIs can be used for adding a particular event to the favourite list of the user.
25344+
25345+
## Favourite Events Collection [/v1/user-favourite-events]
25346+
25347+
### List All Favourite Events [GET]
25348+
25349+
+ Request
25350+
25351+
+ Headers
25352+
25353+
Authorization: JWT <Auth Key>
25354+
25355+
+ Response 200 (application/vnd.api+json)
25356+
25357+
{
25358+
"data": [
25359+
{
25360+
"type": "user-favourite-event",
25361+
"id": "1",
25362+
"relationships": {
25363+
"event": {
25364+
"links": {
25365+
"self": "/v1/user-favourite-events/1/relationships/event",
25366+
"related": "/v1/user-favourite-events/1/event"
25367+
}
25368+
},
25369+
"user": {
25370+
"links": {
25371+
"self": "/v1/user-favourite-events/1/relationships/user",
25372+
"related": "/v1/favourite-events/1/user"
25373+
}
25374+
}
25375+
},
25376+
"attributes": {
25377+
"deleted-at": null
25378+
},
25379+
"links": {
25380+
"self": "/v1/user-favourite-events/1"
25381+
}
25382+
}
25383+
],
25384+
"links": {
25385+
"self": "/v1/user-favourite-events"
25386+
},
25387+
"meta": {
25388+
"count": 1
25389+
},
25390+
"jsonapi": {
25391+
"version": "1.0"
25392+
}
25393+
}
25394+
25395+
### Create a Favourite Event [POST]
25396+
25397+
+ Request
25398+
25399+
+ Headers
25400+
25401+
Authorization: JWT <Auth Key>
25402+
Content-Type: application/vnd.api+json
25403+
25404+
+ Body
25405+
25406+
{
25407+
"data": {
25408+
"type": "user-favourite-event",
25409+
"relationships": {
25410+
"event": {
25411+
"data": {
25412+
"id": "1",
25413+
"type": "event"
25414+
}
25415+
}
25416+
}
25417+
}
25418+
}
25419+
25420+
+ Response 201 (application/vnd.api+json)
25421+
25422+
{
25423+
"data": {
25424+
"type": "user-favourite-event",
25425+
"relationships": {
25426+
"user": {
25427+
"links": {
25428+
"self": "/v1/user-favourite-events/1/relationships/user",
25429+
"related": "/v1/favourite-events/1/user"
25430+
}
25431+
},
25432+
"event": {
25433+
"links": {
25434+
"self": "/v1/user-favourite-events/1/relationships/event",
25435+
"related": "/v1/user-favourite-events/1/event"
25436+
}
25437+
}
25438+
},
25439+
"attributes": {
25440+
"deleted-at": null
25441+
},
25442+
"id": "1",
25443+
"links": {
25444+
"self": "/v1/user-favourite-events/1"
25445+
}
25446+
},
25447+
"links": {
25448+
"self": "/v1/user-favourite-events/1"
25449+
},
25450+
"jsonapi": {
25451+
"version": "1.0"
25452+
}
25453+
}
25454+
25455+
## Favourite Events Detail [/v1/user-favourite-events/{user_favourite_event_id}]
25456+
+ Parameters
25457+
+ user_favourite_event_id: 1 (integer) - ID of the Favourite Event
25458+
25459+
### Get Details [GET]
25460+
25461+
+ Request
25462+
25463+
+ Headers
25464+
25465+
Authorization: JWT <Auth Key>
25466+
25467+
+ Response 200 (application/vnd.api+json)
25468+
25469+
{
25470+
"links": {
25471+
"self": "/v1/user-favourite-events/1"
25472+
},
25473+
"jsonapi": {
25474+
"version": "1.0"
25475+
},
25476+
"data": {
25477+
"type": "user-favourite-event",
25478+
"links": {
25479+
"self": "/v1/user-favourite-events/1"
25480+
},
25481+
"id": "1",
25482+
"attributes": {
25483+
"deleted-at": null
25484+
},
25485+
"relationships": {
25486+
"user": {
25487+
"links": {
25488+
"related": "/v1/favourite-events/1/user",
25489+
"self": "/v1/user-favourite-events/1/relationships/user"
25490+
}
25491+
},
25492+
"event": {
25493+
"links": {
25494+
"related": "/v1/user-favourite-events/1/event",
25495+
"self": "/v1/user-favourite-events/1/relationships/event"
25496+
}
25497+
}
25498+
}
25499+
}
25500+
}
25501+
25502+
### Delete Favourite Event [DELETE]
25503+
25504+
+ Request
25505+
25506+
+ Headers
25507+
25508+
Authorization: JWT <Auth Key>
25509+
25510+
+ Response 200 (application/vnd.api+json)
25511+
25512+
{
25513+
"meta": {
25514+
"message": "Object successfully deleted"
25515+
},
25516+
"jsonapi": {
25517+
"version": "1.0"
25518+
}
25519+
}

tests/hook_main.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from app.factories.feedback import FeedbackFactory
6363
from app.factories.service import ServiceFactory
6464
from app.factories.message_setting import MessageSettingsFactory
65+
from app.factories.user_favourite_events import UserFavouriteEventFactory
6566

6667

6768

@@ -4353,3 +4354,56 @@ def panel_permissions_custom_system_role(transaction):
43534354
panel_permission = PanelPermissionFactory()
43544355
db.session.add(panel_permission)
43554356
db.session.commit()
4357+
4358+
# ------------------------- User Favourite Events -------------------------
4359+
4360+
@hooks.before("Favourite Events > Favourite Events Collection > List All Favourite Events")
4361+
def favourite_events_list_get(transaction):
4362+
"""
4363+
GET /user-favourite-events
4364+
:param transaction:
4365+
:return:
4366+
"""
4367+
with stash['app'].app_context():
4368+
user_fav_event = UserFavouriteEventFactory()
4369+
db.session.add(user_fav_event)
4370+
db.session.commit()
4371+
4372+
4373+
@hooks.before("Favourite Events > Favourite Events Collection > Create a Favourite Event")
4374+
def favourite_events_list_post(transaction):
4375+
"""
4376+
POST /user-favourite-events
4377+
:param transaction:
4378+
:return:
4379+
"""
4380+
with stash['app'].app_context():
4381+
user_fav_event = UserFavouriteEventFactory()
4382+
db.session.add(user_fav_event)
4383+
db.session.commit()
4384+
4385+
4386+
@hooks.before("Favourite Events > Favourite Events Detail > Get Details")
4387+
def favourite_event_details_get(transaction):
4388+
"""
4389+
GET /user-favourite-events/1
4390+
:param transaction:
4391+
:return:
4392+
"""
4393+
with stash['app'].app_context():
4394+
user_fav_event = UserFavouriteEventFactory()
4395+
db.session.add(user_fav_event)
4396+
db.session.commit()
4397+
4398+
4399+
@hooks.before("Favourite Events > Favourite Events Detail > Delete Favourite Event")
4400+
def favourite_event_delete(transaction):
4401+
"""
4402+
DELETE /user-favourite-events/1
4403+
:param transaction:
4404+
:return:
4405+
"""
4406+
with stash['app'].app_context():
4407+
user_fav_event = UserFavouriteEventFactory()
4408+
db.session.add(user_fav_event)
4409+
db.session.commit()

0 commit comments

Comments
 (0)