Skip to content

Commit

Permalink
feat(events): Filter event by location: (#262)
Browse files Browse the repository at this point in the history
- Add location field in the events model.
- make location column enum type.
- create a query to filter the events location.

[#166887602]
  • Loading branch information
kizzanaome authored and andrewinsoul committed Sep 2, 2019
1 parent 1740790 commit 87ce144
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 64 deletions.
2 changes: 1 addition & 1 deletion server/api/fixtures/initial.json
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,4 @@
"follower_category": 1
}
}
]
]
20 changes: 20 additions & 0 deletions server/api/migrations/0026_event_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.5 on 2019-08-13 11:36
from __future__ import unicode_literals

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('api', '0025_auto_20190711_1357'),
]

operations = [
migrations.AddField(
model_name='event',
name='location',
field=models.CharField(choices=[('Egypt', 'Egypt'), ('Nigeria', 'Nigeria'), ('Uganda', 'Uganda'), ('Kenya', 'Kenya'), ('San-Fransisco', 'San-Fransisco'), ('Kigali', 'Kigali')], default='San-Fransisco', max_length=50),
),
]
35 changes: 34 additions & 1 deletion server/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,21 @@ class RecurrenceEvent(BaseInfo):

class Event(BaseInfo):
"""Message model defined."""
EG = 'Egypt'
NG = 'Nigeria'
UG = 'Uganda'
KE = 'Kenya'
SF = 'San-Fransisco'
KG = 'Kigali'

EVENTS_LOCATION = (
(EG, 'Egypt'),
(NG, 'Nigeria'),
(UG, 'Uganda'),
(KE, 'Kenya'),
(SF, 'San-Fransisco'),
(KG, 'Kigali'),
)

title = models.CharField(max_length=100)
event_id_in_calendar = models.CharField(max_length=150, default='')
Expand All @@ -220,6 +235,8 @@ class Event(BaseInfo):
active = models.BooleanField(default=1)
timezone = models.CharField(max_length=80, blank=True)
slack_channel = models.CharField(max_length=80, blank=True)
location = models.CharField(max_length=50,
choices=EVENTS_LOCATION, default=SF)

@property
def attendees(self):
Expand All @@ -234,7 +251,23 @@ def get_count(self):
attendees_count = property(get_count)

def __str__(self):
return "Event: {}" .format(self.title)
return "Event: {}{}" .format(self.title, self.location)

def save(self, *args, **kwargs):
"""This method is modified to check if event value is
valid before a user event is created.
:param args: Tuple of arguments
:param kwargs: key word arguments
:return: None
"""

if self.location not in (self.EG, self.NG, self.UG,
self.KE, self.SF, self.KG):
raise ValidationError(
f'{self.location} is not a valid location'
)
super(Event, self).save(*args, **kwargs)


class Interest(BaseInfo):
Expand Down
15 changes: 10 additions & 5 deletions server/graphql_schemas/event/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ class Meta:
model = Event
fields = {'start_date': ['exact', 'istartswith'],
'social_event': ['exact'], 'venue': ['exact'],
'title': ['exact', 'istartswith'], 'creator': ['exact']}
'title': ['exact', 'istartswith'], 'creator': ['exact'],
'location': ['icontains'], }


class EventNode(DjangoObjectType):
attendSet = AttendNode()
Expand All @@ -89,7 +91,8 @@ class Meta:
model = Event
filter_fields = {'start_date': ['exact', 'istartswith'],
'social_event': ['exact'], 'venue': ['exact'],
'title': ['exact', 'istartswith'], 'creator': ['exact']}
'title': ['exact', 'istartswith'], 'creator': ['exact'],
'location': ['icontains'], }
interfaces = (relay.Node,)


Expand Down Expand Up @@ -117,6 +120,7 @@ class Input:
recurring = graphene.Boolean(required=False)
recurrence_end_date = graphene.DateTime(required=False)
add_to_calendar = graphene.Boolean(required=False)
location = graphene.String(required=False)

new_event = graphene.Field(EventNode)
slack_token = graphene.Boolean()
Expand Down Expand Up @@ -240,7 +244,7 @@ def create_recurrent_event(**input):
frequency=frequency,
start_date=start_date,
end_date=end_date
)
)
return recurrence_event

@staticmethod
Expand Down Expand Up @@ -383,7 +387,7 @@ def mutate_and_get_payload(cls, root, info, **input):
updated_event=updated_event
)
except Exception as e:
# return an error if something wrong happens
""" return an error if something wrong happens """
logging.warn(e)
raise GraphQLError("An Error occurred. Please try again")

Expand Down Expand Up @@ -424,7 +428,8 @@ def mutate_and_get_payload(cls, root, info, **input):
remove_event_from_all_calendars, (andela_user, event))

BackgroundTaskWorker.start_work(
send_bulk_update_message, (event, message, "An event you are attending has been cancelled"))
send_bulk_update_message,
(event, message, "An event you are attending has been cancelled"))

return cls(action_message="Event deactivated")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,36 @@
]
}

snapshots['MutateEventTestCase::test_event_with_an_existing_location 1'] = {
'data': {
'eventsList': {
'edges': [
{
'node': {
'id': 'RXZlbnROb2RlOjU='
}
}
]
}
}
}

snapshots['MutateEventTestCase::test_event_with_non_exixting_location 1'] = {
'data': {
'eventsList': {
'edges': [
]
}
}
}

snapshots['MutateEventTestCase::test_query_updated_event 1'] = {
'data': {
'event': {
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'socialEvent': {
'id': 'Q2F0ZWdvcnlOb2RlOjQz'
'id': 'Q2F0ZWdvcnlOb2RlOjQ1'
},
'title': 'test title default'
}
Expand Down Expand Up @@ -234,52 +257,52 @@
}
}

snapshots['MutateEventTestCase::test_validate_invite_link_invalid_event 1'] = {
snapshots['MutateEventTestCase::test_validate_invite_link_expired_event 1'] = {
'data': {
'validateEventInvite': {
'event': None,
'isValid': False,
'message': 'Not Found: Invalid event/user in invite'
'message': 'Expired Invite: Event has ended'
}
}
}

snapshots['MutateEventTestCase::test_validate_invite_link_invalid_hash 1'] = {
snapshots['MutateEventTestCase::test_validate_invite_link_invalid_event 1'] = {
'data': {
'validateEventInvite': {
'event': None,
'isValid': False,
'message': 'Bad Request: Invalid invite URL'
'message': 'Not Found: Invalid event/user in invite'
}
}
}

snapshots['MutateEventTestCase::test_validate_invite_link_invalid_sender 1'] = {
snapshots['MutateEventTestCase::test_validate_invite_link_invalid_hash 1'] = {
'data': {
'validateEventInvite': {
'event': None,
'isValid': False,
'message': 'Expired Invite: Event has ended'
'message': 'Bad Request: Invalid invite URL'
}
}
}

snapshots['MutateEventTestCase::test_validate_invite_link_unauthorized_user 1'] = {
snapshots['MutateEventTestCase::test_validate_invite_link_invalid_sender 1'] = {
'data': {
'validateEventInvite': {
'event': None,
'isValid': False,
'message': 'Forbidden: Unauthorized access'
'message': 'Expired Invite: Event has ended'
}
}
}

snapshots['MutateEventTestCase::test_validate_invite_link_expired_event 1'] = {
snapshots['MutateEventTestCase::test_validate_invite_link_unauthorized_user 1'] = {
'data': {
'validateEventInvite': {
'event': None,
'isValid': False,
'message': 'Expired Invite: Event has ended'
'message': 'Forbidden: Unauthorized access'
}
}
}
63 changes: 20 additions & 43 deletions server/graphql_schemas/tests/events/snapshots/snap_test_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,35 +7,16 @@

snapshots = Snapshot()

snapshots['QueryEventTestCase::test_query_deactivated_event 1'] = {
snapshots['QueryEventTestCase::test_filter_event_list_by_non_existing_venue_returns_empty_list 1'] = {
'data': {
'eventsList': {
'edges': [
{
'node': {
'active': True,
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'title': 'test title default'
}
}
]
}
}
}

snapshots['QueryEventTestCase::test_query_single_event 1'] = {
'data': {
'event': {
'active': True,
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'title': 'test title default'
}
}
}

snapshots['QueryEventTestCase::test_get_event_list 1'] = {
snapshots['QueryEventTestCase::test_filter_event_list_by_valid_venue_is_successful 1'] = {
'data': {
'eventsList': {
'edges': [
Expand All @@ -45,7 +26,7 @@
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'socialEvent': {
'id': 'Q2F0ZWdvcnlOb2RlOjU5',
'id': 'Q2F0ZWdvcnlOb2RlOjYw',
'name': 'social event'
},
'startDate': '2018-11-20 20:08:07.127325+00:00',
Expand All @@ -58,7 +39,7 @@
}
}

snapshots['QueryEventTestCase::test_filter_event_list 1'] = {
snapshots['QueryEventTestCase::test_get_event_list 1'] = {
'data': {
'eventsList': {
'edges': [
Expand All @@ -68,10 +49,10 @@
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'socialEvent': {
'id': 'Q2F0ZWdvcnlOb2RlOjM1',
'id': 'Q2F0ZWdvcnlOb2RlOjYx',
'name': 'social event'
},
'startDate': '2018-11-20T20:08:07.127325+00:00',
'startDate': '2018-11-20 20:08:07.127325+00:00',
'title': 'test title default',
'venue': 'test venue'
}
Expand All @@ -81,34 +62,30 @@
}
}

snapshots['QueryEventTestCase::test_filter_event_list_by_non_existing_venue_returns_empty_list 1'] = {
'data': {
'eventsList': {
'edges': [
]
}
}
}

snapshots['QueryEventTestCase::test_filter_event_list_by_valid_venue_is_successful 1'] = {
snapshots['QueryEventTestCase::test_query_deactivated_event 1'] = {
'data': {
'eventsList': {
'edges': [
{
'cursor': 'YXJyYXljb25uZWN0aW9uOjA=',
'node': {
'active': True,
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'socialEvent': {
'id': 'Q2F0ZWdvcnlOb2RlOjU4',
'name': 'social event'
},
'startDate': '2018-11-20 20:08:07.127325+00:00',
'title': 'test title default',
'venue': 'test venue'
'title': 'test title default'
}
}
]
}
}
}

snapshots['QueryEventTestCase::test_query_single_event 1'] = {
'data': {
'event': {
'active': True,
'description': 'test description default',
'id': 'RXZlbnROb2RlOjU=',
'title': 'test title default'
}
}
}
Loading

0 comments on commit 87ce144

Please sign in to comment.