-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
flattened json output with new metrics endpoints (#107)
- Loading branch information
Showing
4 changed files
with
152 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,19 +3,19 @@ | |
from __future__ import print_function | ||
from __future__ import unicode_literals | ||
|
||
from yelp_beans.logic.metrics import get_subscribed_users | ||
from yelp_beans.logic.metrics import get_subscribers | ||
from yelp_beans.models import MeetingSubscription | ||
|
||
|
||
def test_get_subscribed_users(database, fake_user): | ||
subscribed_users = get_subscribed_users() | ||
subscribed_users = get_subscribers() | ||
assert len(subscribed_users) == 1 | ||
assert subscribed_users[database.sub.key.urlsafe()] == ['[email protected]'] | ||
|
||
|
||
def test_get_subscribed_users_multiple(database, fake_user): | ||
subscription2 = MeetingSubscription(title='test1').put() | ||
subscribed_users = get_subscribed_users() | ||
subscribed_users = get_subscribers() | ||
|
||
assert len(subscribed_users) == 2 | ||
assert subscribed_users[subscription2.urlsafe()] == [] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,50 +5,82 @@ | |
|
||
import json | ||
|
||
from yelp_beans.models import MeetingSubscription | ||
from yelp_beans.routes.api.v1.metrics import metrics_api | ||
from yelp_beans.models import Meeting | ||
from yelp_beans.models import MeetingParticipant | ||
from yelp_beans.models import MeetingRequest | ||
from yelp_beans.models import User | ||
from yelp_beans.models import UserSubscriptionPreferences | ||
from yelp_beans.routes.api.v1.metrics import meeting_participants | ||
from yelp_beans.routes.api.v1.metrics import meeting_requests | ||
from yelp_beans.routes.api.v1.metrics import meeting_subscribers | ||
|
||
|
||
def test_get_metrics(app, minimal_database): | ||
def test_get_subscribers_none(app, minimal_database): | ||
with app.test_request_context('/v1/metrics/subscribers'): | ||
subscribed = json.loads(meeting_subscribers()) | ||
assert subscribed == [] | ||
|
||
with app.test_request_context('/v1/metrics'): | ||
response = metrics_api() | ||
assert response == '[]' | ||
|
||
new_subscription = MeetingSubscription(title='test1') | ||
new_subscription.put() | ||
def test_get_subscribers(app, database, subscription, fake_user): | ||
with app.test_request_context('/v1/metrics/subscribers'): | ||
subscribed = json.loads(meeting_subscribers()) | ||
assert subscribed == [{ | ||
'title': 'Yelp Weekly', | ||
'subscriber': '[email protected]' | ||
}] | ||
|
||
with app.test_request_context('/v1/metrics'): | ||
response = json.loads(metrics_api()) | ||
assert response[0]["title"] == new_subscription.title | ||
assert response[0]["key"] == new_subscription.key.urlsafe() | ||
assert response[0]["week_participants"] == 0 | ||
assert response[0]["subscribed"] == [] | ||
|
||
def test_get_meeting_participants(app, database): | ||
pref = UserSubscriptionPreferences(subscription=database.sub.key, preference=database.prefs[0].key) | ||
pref.put() | ||
user1 = User( | ||
email='[email protected]', | ||
metadata={'department': 'dept'}, | ||
subscription_preferences=[pref.key] | ||
) | ||
user1.put() | ||
user2 = User( | ||
email='[email protected]', | ||
metadata={'department': 'dept'}, | ||
subscription_preferences=[pref.key] | ||
) | ||
user2.put() | ||
meeting1 = Meeting(meeting_spec=database.specs[0].key, cancelled=False).put() | ||
MeetingParticipant(meeting=meeting1, user=user1.key).put() | ||
MeetingParticipant(meeting=meeting1, user=user2.key).put() | ||
with app.test_request_context('/v1/metrics/meeting_participants'): | ||
participants = json.loads(meeting_participants()) | ||
assert participants == [ | ||
{ | ||
'date': '2017-10-27T23:00:00', | ||
'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw', | ||
'meeting_title': 'Yelp Weekly', | ||
'participant': '[email protected]', | ||
'time': '04:00PM' | ||
}, | ||
{ | ||
'date': '2017-10-27T23:00:00', | ||
'meeting': 'agx0ZXN0YmVkLXRlc3RyDQsSB01lZXRpbmcYCgw', | ||
'meeting_title': 'Yelp Weekly', | ||
'participant': '[email protected]', | ||
'time': '04:00PM' | ||
} | ||
] | ||
|
||
def test_get_metrics_multiple(app, database, subscription, fake_user): | ||
with app.test_request_context('/v1/metrics'): | ||
response = json.loads(metrics_api()) | ||
assert len(response) == 1 | ||
response = response[0] | ||
assert response['key'] == database.sub.key.urlsafe() | ||
assert response['subscribed'] == ['[email protected]'] | ||
assert response['title'] == database.sub.title | ||
assert response['week_participants'] == 1 | ||
|
||
new_subscription = MeetingSubscription(title='test1') | ||
new_subscription.put() | ||
|
||
with app.test_request_context('/v1/metrics'): | ||
response = json.loads(metrics_api()) | ||
assert len(response) == 2 | ||
|
||
assert response[0]['key'] == database.sub.key.urlsafe() | ||
assert response[0]['subscribed'] == [fake_user.email] | ||
assert response[0]['title'] == database.sub.title | ||
assert response[0]['week_participants'] == 1 | ||
|
||
assert response[1]['key'] == new_subscription.key.urlsafe() | ||
assert response[1]['subscribed'] == [] | ||
assert response[1]['title'] == new_subscription.title | ||
assert response[1]['week_participants'] == 0 | ||
def test_get_meeting_requests(app, database): | ||
pref = UserSubscriptionPreferences(subscription=database.sub.key, preference=database.prefs[0].key) | ||
pref.put() | ||
user = User( | ||
email='[email protected]', | ||
metadata={'department': 'dept'}, | ||
subscription_preferences=[pref.key] | ||
) | ||
user.put() | ||
MeetingRequest(user=user.key, meeting_spec=database.specs[0].key).put() | ||
with app.test_request_context('/v1/metrics/meeting_requests'): | ||
requests = json.loads(meeting_requests()) | ||
assert requests == [{ | ||
'title': 'Yelp Weekly', | ||
'user': '[email protected]' | ||
}] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters