Skip to content

chore: add api docs and dredd tests for group follow/unfollow #8055

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 12 commits into
base: development
Choose a base branch
from
4 changes: 3 additions & 1 deletion docs/api/api_blueprint_source.apib
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ The Open Event API Server

<!-- include(blueprint/event/events.apib) -->

<!-- include(blueprint/groups.apib) -->
<!-- include(blueprint/group/groups.apib) -->

<!-- include(blueprint/group/followed_groups.apib) -->

<!-- include(blueprint/copyright.apib) -->

Expand Down
221 changes: 221 additions & 0 deletions docs/api/blueprint/group/followed_groups.apib
Original file line number Diff line number Diff line change
@@ -0,0 +1,221 @@
# Group Followed Groups

This Group's APIs can be used for adding a particular group to the followed group's list of the user.

## Followed Groups Collection [/v1/user-follow-groups]

### Create a Followed Group [POST]

+ Request

+ Headers

Authorization: JWT <Auth Key>
Content-Type: application/vnd.api+json

+ Body

{
"data": {
"type": "user-follow-group",
"relationships": {
"group": {
"data": {
"id": "1",
"type": "group"
}
}
}
}
}

+ Response 201 (application/vnd.api+json)

{
"data": {
"type": "user-follow-group",
"relationships": {
"group": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/group",
"related": "/v1/user-follow-groups/1/group"
}
},
"user": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/user",
"related": "/v1/user-follow-groups/1/user"
}
}
},
"id": "1",
"links": {
"self": "/v1/user-follow-groups/1"
}
},
"links": {
"self": "/v1/user-follow-groups/1"
},
"jsonapi": {
"version": "1.0"
}
}

## Followed Groups Collection List [/v1/users/1/followed-groups]

### List All Followed Groups of an User [GET]

+ Request

+ Headers

Content-Type: application/vnd.api+json

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"data": [
{
"type": "user-follow-group",
"relationships": {
"group": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/group",
"related": "/v1/user-follow-groups/1/group"
}
},
"user": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/user",
"related": "/v1/user-follow-groups/1/user"
}
}
},
"id": "1",
"links": {
"self": "/v1/user-follow-groups/1"
}
}
],
"links": {
"self": "/v1/users/1/followed-groups"
},
"meta": {
"count": 1
},
"jsonapi": {
"version": "1.0"
}
}

## Followed Users Collection List [/v1/groups/1/followers]

### List All Followed Users of a Group [GET]

+ Request

+ Headers

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"data": [
{
"type": "user-follow-group",
"relationships": {
"group": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/group",
"related": "/v1/user-follow-groups/1/group"
}
},
"user": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/user",
"related": "/v1/user-follow-groups/1/user"
}
}
},
"id": "1",
"links": {
"self": "/v1/user-follow-groups/1"
}
}
],
"links": {
"self": "/v1/groups/1/followers"
},
"meta": {
"count": 1
},
"jsonapi": {
"version": "1.0"
}
}

## Followed Groups Detail [/v1/user-follow-groups/{group_id}]
+ Parameters
+ group_id: 1 (integer) - ID of the User Group Followed in the form of an integer

### Get Details [GET]

+ Request

+ Headers

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"data": {
"type": "user-follow-group",
"relationships": {
"group": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/group",
"related": "/v1/user-follow-groups/1/group"
}
},
"user": {
"links": {
"self": "/v1/user-follow-groups/1/relationships/user",
"related": "/v1/user-follow-groups/1/user"
}
}
},
"id": "1",
"links": {
"self": "/v1/user-follow-groups/1"
}
},
"links": {
"self": "/v1/user-follow-groups/1"
},
"jsonapi": {
"version": "1.0"
}
}

### Unfollow Followed Group [DELETE]

+ Request

+ Headers

Authorization: JWT <Auth Key>

+ Response 200 (application/vnd.api+json)

{
"meta": {
"message": "Object successfully deleted"
},
"jsonapi": {
"version": "1.0"
}
}
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/api/blueprint/session/favourite_sessions.apib
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ This Group's APIs can be used for adding a particular session to the favourite l
}
}

## Favourite Sessions Collection List [/v1/user/1/favourite-sessions]
## Favourite Sessions Collection List [/v1/users/1/favourite-sessions]

### List All Favourite Sessions of an User [GET]

Expand Down
7 changes: 7 additions & 0 deletions tests/factories/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from app.models.group import Group
from tests.factories.base import BaseFactory
from tests.factories.event import EventFactoryBasic
from tests.factories.user import UserFactory


Expand All @@ -17,5 +18,11 @@ class GroupFactory(GroupFactoryBase):
user_id = 1


class GroupFactoryBasic(GroupFactoryBase):
user_id = 1
event_id = 1


class GroupSubFactory(GroupFactoryBase):
user = factory.SubFactory(UserFactory)
event = factory.RelatedFactory(EventFactoryBasic)
14 changes: 14 additions & 0 deletions tests/factories/user_follow_group.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import factory

from app.models.user import User
from app.models.user_follow_group import UserFollowGroup
from tests.factories.base import BaseFactory
from tests.factories.group import GroupFactoryBasic


class UserFollowGroupFactory(BaseFactory):
class Meta:
model = UserFollowGroup

user = factory.LazyAttribute(lambda a: User.query.first())
group = factory.SubFactory(GroupFactoryBasic)
69 changes: 69 additions & 0 deletions tests/hook_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from tests.factories.event import EventFactoryBasic
from tests.factories.group import GroupFactory
from tests.factories.social_link import SocialLinkFactory
from tests.factories.user_follow_group import UserFollowGroupFactory
from tests.factories.microlocation import MicrolocationFactory
from tests.factories.image_size import EventImageSizeFactory, SpeakerImageSizeFactory
from tests.factories.page import PageFactory
Expand All @@ -49,6 +50,7 @@
from tests.factories.speakers_call import SpeakersCallFactory
from tests.factories.tax import TaxFactory
from tests.factories.session import SessionFactory, SessionFactoryBasic
from tests.factories.group import GroupFactory, GroupFactoryBasic
from tests.factories.speaker import SpeakerFactory
from tests.factories.ticket import TicketFactory
from tests.factories.attendee import AttendeeFactory, AttendeeOrderSubFactory
Expand Down Expand Up @@ -4809,6 +4811,73 @@ def favourite_session_delete(transaction):
db.session.commit()


# ------------------------- User Follow Group -------------------------


@hooks.before("Follow Groups > Follow Groups Collection List > List All Followed Groups")
def follow_groupss_list_get(transaction):
"""
GET /user-follow-groups
:param transaction:
:return:
"""
with stash['app'].app_context():
user_follow_group = UserFollowGroupFactory()
db.session.add(user_follow_group)
db.session.commit()


@hooks.before("Followed Groups > Follow Groups Collection > Create a Followed Groups")
def followed_groups_list_post(transaction):
"""
POST /user-follow-groups
:param transaction:
:return:
"""
with stash['app'].app_context():
group = GroupFactoryBasic()
db.session.add(group)
db.session.commit()


@hooks.before("Followed Groups > Followed Groups Detail > Get Details")
def follow_group_details_get(transaction):
"""
GET /user-follow-groups/1
:param transaction:
:return:
"""
with stash['app'].app_context():
user_follow_group = UserFollowGroupFactory()
db.session.add(user_follow_group)
db.session.commit()

@hooks.before("Followed Groups > Followed Users Collection List > Followed Users Collection List")
def list_group_followers(transaction):
"""
GET /groups/1/followers
:param transaction:
:return:
"""
with stash['app'].app_context():
user_follow_group = UserFollowGroupFactory()
db.session.add(user_follow_group)
db.session.commit()


@hooks.before("Follow Groups > Follow Groups Detail > Delete Followed Groups")
def follow_group_delete(transaction):
"""
DELETE /user-follow-groups/1
:param transaction:
:return:
"""
with stash['app'].app_context():
user_follow_group = UserFollowGroupFactory()
db.session.add(user_follow_group)
db.session.commit()


# ------------------------- Admin Statistics -------------------------


Expand Down