Skip to content
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

Group support #60

Merged
merged 2 commits into from
Jan 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ Options are included to filter by level, source, whether a notification has been
```
{
"global": {
"name": <full name of feed>,
"unseen": <number unseen>,
"feed": [ array of global notifications ]
},
"user": {
"name": <full name of user>,
"unseen": <number unseen>,
"feed": [ array of user's notifications ]
}
Expand All @@ -162,8 +164,12 @@ curl -X GET
returns
```
{
"global": [{note 1}, {note 2}, ...],
"user": [{note 1}, {note 2}, ... {note 10}]
"global": {
"name": <name>,
"unseen": <number unseen>,
"feed": [{note 1}, {note 2}, ...]
},
"user": { structure as above }
}
```
(they all return a structure like that, so the return is omitted for the remaining examples)
Expand Down
46 changes: 27 additions & 19 deletions feeds/entity/types/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,42 @@
)
from feeds.external_api.workspace import (
validate_workspace_id,
get_workspace_name,
get_workspace_names,
)
from feeds.exceptions import (
EntityNameError,
WorkspaceError
# get_workspace_name,
# get_workspace_names
)
# from feeds.exceptions import (
# EntityNameError,
# WorkspaceError
# )
from .narrative import NarrativeType


# 1/29/2019 - Workspaces and Narratives are effectively interchangeable right now
# so Workspace "names" should just be narrative names.
#
# But I'm leaving in the commented code, just in case.

class WorkspaceType(BaseType):
@staticmethod
def get_name_from_id(i: str, token: str) -> str:
try:
name = get_workspace_name(i, token)
if name is None:
raise EntityNameError(
"Unable to find name for workspace id: {}".format(i)
)
return name
except WorkspaceError as e:
raise EntityNameError(e)
return NarrativeType.get_name_from_id(i, token)
# try:
# name = get_workspace_name(i, token)
# if name is None:
# raise EntityNameError(
# "Unable to find name for workspace id: {}".format(i)
# )
# return name
# except WorkspaceError as e:
# raise EntityNameError(e)

@staticmethod
def get_names_from_ids(ids: List[str], token: str) -> Dict[str, str]:
try:
return get_workspace_names(ids, token)
except WorkspaceError as e:
raise EntityNameError(e)
return NarrativeType.get_names_from_ids(ids, token)
# try:
# return get_workspace_names(ids, token)
# except WorkspaceError as e:
# raise EntityNameError(e)

@staticmethod
def validate_id(i: str, token: str) -> bool:
Expand Down
2 changes: 1 addition & 1 deletion feeds/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
log_error
)

VERSION = "0.1.3"
VERSION = "0.1.4"

try:
from feeds import gitcommit
Expand Down
2 changes: 1 addition & 1 deletion test/api/test_admin_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ def test_admin_expire_service_auth(client, mock_valid_service_token):
def test_expire_notifications_admin(client, mongo_notes, mock_valid_admin_token, mock_valid_users, mock_workspace_info):
mock_valid_admin_token("kbase_admin", "KBase Admin")
mock_valid_users({"kbasetest": "KBase Test Account", "kbase": "KBase"})
mock_workspace_info(["123", "A_Workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
# make a notification
admin_cred = {"Authorization": "token-"+str(uuid4())}
note = {
Expand Down
16 changes: 8 additions & 8 deletions test/api/test_api_v1.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def test_get_notifications(client, mock_valid_user_token, mock_valid_users, mock
"test_unsee": "Test Unsee",
"_kbase_": "KBase Admin"
})
mock_workspace_info(["123", "A_Workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
response = client.get('/api/V1/notifications', headers={"Authorization": "token-"+str(uuid4())})
# Got the fake db in _data/mongo/notifications.json
data = json.loads(response.data)
Expand Down Expand Up @@ -67,7 +67,7 @@ def test_get_notifications_filtered(client, mock_valid_user_token, mock_valid_us
"test_unsee": "Test Unsee",
"_kbase_": "KBase Admin"
})
mock_workspace_info(["123", "A_Workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
route = '/api/V1/notifications?' + filters
response = client.get(route, headers={"Authorization": "token-"+str(uuid4())})
data = json.loads(response.data)
Expand Down Expand Up @@ -107,7 +107,7 @@ def test_get_notifications_groups(client, mock_valid_user_token, mock_valid_user
"_kbase_": "KBase",
"test_group_user": "Test Group User"
})
mock_workspace_info(["123", "A_Workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
response = client.get("/api/V1/notifications", headers={"Authorization": "token-"+str(uuid4())})
data = json.loads(response.data)
assert "user" in data
Expand All @@ -132,7 +132,7 @@ def test_post_notification_ok(client, mock_valid_service_token, mock_valid_user_
test_user = "test_note"
test_actor = "test_actor"
mock_valid_users({test_actor: "Test Actor", test_user: "Test User"})
mock_workspace_info(["stuff", "Some Workspace"])
mock_workspace_info(["stuff", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
mock_valid_service_token("user", "pw", service)
note = {
"actor": {"id": test_actor, "type": "user"},
Expand Down Expand Up @@ -189,7 +189,7 @@ def test_post_notification_invalid_auth(client, mock_invalid_user_token):

def test_get_global_notifications(client, mock_valid_users, mock_workspace_info):
mock_valid_users({"kbasetest": "KBase Test", "_kbase_": "KBase Admin"})
mock_workspace_info(["123", "Some_Workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
response = client.get('/api/V1/notifications/global')
data = json.loads(response.data)
assert len(data["feed"]) >= 1 and data["feed"][-1]["id"] == "global-1"
Expand All @@ -206,7 +206,7 @@ def test_get_single_notification(client, mock_valid_user_token, mock_valid_users
"test_user2": "Test User2",
"test_user3": "Test User3"
})
mock_workspace_info(["123", "Some_workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
mock_valid_user_token("test_user", "Test User")
auth = {"Authorization": "token-"+str(uuid4())}
for id_ in test_ids:
Expand Down Expand Up @@ -342,7 +342,7 @@ def test_mark_notifications_seen(client, mongo_notes, mock_valid_user_token, moc
assert data['notification']['id'] == note_id
assert data['notification']['seen'] == True
# validate with bulk notes endpoint
mock_workspace_info(["123", "Some_workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
response = client.get('/api/V1/notifications/?seen=1', headers=auth)
data = json.loads(response.data)
assert 'user' in data
Expand Down Expand Up @@ -420,7 +420,7 @@ def test_mark_notifications_unseen(client, mongo_notes, mock_valid_user_token, m
assert data['notification']['id'] == note_id
assert data['notification']['seen'] == False
# validate with bulk notes endpoint
mock_workspace_info(["123", "Some_workspace"])
mock_workspace_info(["123", "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "Some Narrative"}])
response = client.get('/api/V1/notifications/', headers=auth)
data = json.loads(response.data)
assert 'user' in data
Expand Down
5 changes: 3 additions & 2 deletions test/entity/test_entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,8 +335,9 @@ def test_entity_fetch_name_ws(mock_workspace_info):
info = [6, "A_Workspace", "owner", "Timestamp", 18, "a", "n", "unlocked", {"narrative": "1", "narrative_nice_name": "My Narrative"}]
mock_workspace_info(info)
e = Entity(ws_id, "workspace")
assert e.name == info[1]

# assert e.name == info[1]
# workspace == narrative now. so test that name.
assert e.name == info[8]['narrative_nice_name']

def test_entity_fetch_name_narr(mock_workspace_info):
ws_id = 7
Expand Down