Skip to content

Commit b826f57

Browse files
committed
Merge branch 'master' into development
# Conflicts: # Makefile
2 parents f1fc9e9 + 9f990ae commit b826f57

File tree

8 files changed

+91
-103
lines changed

8 files changed

+91
-103
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
sudo: false
2+
language: python
3+
python:
4+
- "2.7"
5+
- "3.5"
6+
- "3.6"
7+
install: "make init"
8+
script: "make ci"
9+
cache: pip

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ update : clean-venv init versioneer.py
2929
.PHONY : tests
3030
tests: toxtest lint ;
3131

32+
.PHONY : ci
33+
ci :
34+
pytest
35+
3236
.PHONY : toxtest
3337
toxtest : local/environment.sh tox.ini
34-
source local/environment.sh
35-
tox
38+
source local/environment.sh && tox
3639

3740
.PHONY : pytest
3841
pytest : local/environment.sh

ciscosparkapi/api/teammemberships.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,8 @@ def __init__(self, session):
101101
self._session = session
102102

103103
@generator_container
104-
def list(self, teamId=None, max=None):
105-
"""Lists all team memberships.
106-
107-
By default, lists memberships for teams to which the authenticated user
108-
belongs.
109-
110-
Use teamId to list memberships for a team, by ID.
104+
def list(self, teamId, max=None):
105+
"""List team memberships for a team, by ID.
111106
112107
This method supports Cisco Spark's implementation of RFC5988 Web
113108
Linking to provide pagination support. It returns a generator
@@ -135,11 +130,10 @@ def list(self, teamId=None, max=None):
135130
136131
"""
137132
# Process args
138-
assert teamId is None or isinstance(teamId, basestring)
133+
assert isinstance(teamId, basestring)
139134
assert max is None or isinstance(max, int)
140135
params = {}
141-
if teamId:
142-
params['teamId'] = teamId
136+
params['teamId'] = teamId
143137
if max:
144138
params['max'] = max
145139
# API request - get items

ciscosparkapi/api/teams.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ def update(self, teamId, **update_attributes):
190190
"argument must be specified."
191191
raise ciscosparkapiException(error_message)
192192
# API request
193-
json_obj = self._session.post('teams/' + teamId,
194-
json=update_attributes)
193+
json_obj = self._session.put('teams/' + teamId,
194+
json=update_attributes)
195195
# Return a Team object created from the response JSON data
196196
return Team(json_obj)
197197

tests/api/test_messages.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,10 @@ def group_room_markdown_message(group_room, send_group_room_message, me,
106106
# Uses / depends on group_room_text_message to ensure this message is
107107
# created after group_room_text_message, so that we can be sure that a
108108
# message exists 'before' this one - used to test 'before' list filters.
109-
mention_email = me.emails[0]
110-
markdown = create_string("<personEmail:{}>, This is **markdown** with a "
111-
"mention.".format(mention_email))
109+
markdown = create_string("<@personEmail:{email}|{name}>, This is "
110+
"**markdown** with a mention."
111+
"".format(email=me.emails[0],
112+
name=me.displayName))
112113
return send_group_room_message(group_room.id, markdown=markdown)
113114

114115

@@ -204,9 +205,9 @@ def test_list_messages_with_paging(self, api, group_room,
204205
assert len(messages_list) == num_messages
205206
assert are_valid_messages(messages_list)
206207

207-
# TODO: Investigate API list messages with 'me' mentions not working
208-
# def test_list_messages_with_me_mention(self, api, group_room, me):
209-
# messages = list_messages(api, group_room.id, mentionedPeople=["me"])
210-
# messages_list = list(messages)
211-
# assert len(messages_list) >= 1
212-
# assert are_valid_messages(messages_list)
208+
def test_list_messages_mentioning_me(self, api, group_room,
209+
group_room_markdown_message):
210+
messages = list_messages(api, group_room.id, mentionedPeople=["me"])
211+
messages_list = list(messages)
212+
assert len(messages_list) >= 1
213+
assert are_valid_messages(messages_list)

tests/api/test_people.py

Lines changed: 56 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -45,56 +45,63 @@ def create_person(api, emails, **person_attributes):
4545

4646

4747
def update_person(api, person, **person_attributes):
48-
return api.people.update(person.id, **person_attributes)
48+
# Get a copy of the person's current attributes
49+
new_attributes = person._json.copy()
50+
51+
# Merge in attribute updates
52+
for attribute, value in person_attributes.items():
53+
new_attributes[attribute] = value
54+
55+
return api.people.update(person.id, **new_attributes)
4956

5057

5158
def delete_person(api, person):
52-
# Temporarily disabling test account deletion to workon account
53-
# capabilities issues.
54-
# TODO: Enable test account clean-up.
55-
# api.people.delete(person.id)
56-
pass
57-
58-
59-
def get_new_test_person(api, get_new_email_address, licenses_dict):
60-
person_email = get_new_email_address()
61-
person = get_person_by_email(api, person_email)
62-
if person:
63-
return person
64-
else:
65-
emails = [person_email]
66-
display_name = "ciscosparkapi"
67-
first_name = "ciscosparkapi"
68-
last_name = "ciscosparkapi"
69-
licenses = [licenses_dict["Messaging"].id]
70-
person = create_person(api, emails,
71-
displayName=display_name,
72-
firstName=first_name,
73-
lastName=last_name,
74-
licenses=licenses)
75-
assert is_valid_person(person)
76-
return person
59+
api.people.delete(person.id)
60+
61+
62+
# pytest Fixtures
63+
64+
@pytest.fixture(scope="session")
65+
def me(api):
66+
return api.people.me()
7767

68+
@pytest.fixture(scope="session")
69+
def get_new_test_person(api, get_new_email_address, me, licenses_dict):
70+
71+
def inner_function():
72+
person_email = get_new_email_address()
73+
person = get_person_by_email(api, person_email)
74+
if person:
75+
return person
76+
else:
77+
person = create_person(api,
78+
emails=[person_email],
79+
displayName="ciscosparkapi",
80+
firstName="ciscosparkapi",
81+
lastName="ciscosparkapi",
82+
orgId=me.orgId,
83+
licenses=[licenses_dict["Messaging"].id],
84+
)
85+
assert is_valid_person(person)
86+
return person
7887

79-
# Helper Classes
88+
return inner_function
8089

81-
class TestPeople(object):
90+
91+
class PeopleManager(object):
8292
"""Creates, tracks and manages test accounts 'people' used by the tests."""
8393

84-
def __init__(self, api, get_new_email_address, licenses_dict):
85-
super(TestPeople, self).__init__()
94+
def __init__(self, api, get_new_test_person):
95+
super(PeopleManager, self).__init__()
8696
self._api = api
87-
self._get_new_email_address = get_new_email_address
88-
self._licenses_dict = licenses_dict
97+
self._get_new_test_person = get_new_test_person
8998
self.test_people = {}
9099

91100
def __getitem__(self, item):
92101
if self.test_people.get(item):
93102
return self.test_people[item]
94103
else:
95-
new_test_person = get_new_test_person(self._api,
96-
self._get_new_email_address,
97-
self._licenses_dict)
104+
new_test_person = self._get_new_test_person()
98105
self.test_people[item] = new_test_person
99106
return new_test_person
100107

@@ -111,26 +118,18 @@ def __iter__(self):
111118
def __del__(self):
112119
for person in self.test_people.values():
113120
delete_person(self._api, person)
114-
pass
115-
116-
117-
# pytest Fixtures
118-
119-
@pytest.fixture(scope="session")
120-
def me(api):
121-
return api.people.me()
122121

123122

124123
@pytest.fixture(scope="session")
125-
def test_people(api, get_new_email_address, licenses_dict):
126-
test_people = TestPeople(api, get_new_email_address, licenses_dict)
124+
def test_people(api, get_new_test_person):
125+
test_people = PeopleManager(api, get_new_test_person)
127126
yield test_people
128127
del test_people
129128

130129

131130
@pytest.fixture()
132-
def temp_person(api, get_new_email_address, licenses_dict):
133-
person = get_new_test_person(api, get_new_email_address, licenses_dict)
131+
def temp_person(api, get_new_test_person):
132+
person = get_new_test_person()
134133
yield person
135134
delete_person(api, person)
136135

@@ -150,24 +149,16 @@ def test_create_person(self, test_people):
150149
person = test_people["not_a_member"]
151150
assert is_valid_person(person)
152151

153-
# TODO: Investigate update person API not working
154-
# def test_update_person(self, api, temp_person, roles_dict, licenses_dict,
155-
# get_new_email_address):
156-
# # Note: Not testing updating orgId
157-
# updated_attributes = {
158-
# "emails": [get_new_email_address()],
159-
# "displayName": temp_person.displayName + " Updated",
160-
# "firstName": temp_person.firstName + " Updated",
161-
# "lastName": temp_person.lastName + " Updated",
162-
# "avatar": TEST_FILE_URL,
163-
# "roles": [roles_dict["Read-only administrator"].id],
164-
# "licenses": [licenses_dict["Messaging"].id,
165-
# licenses_dict["Meeting 25 party"].id],
166-
# }
167-
# updated_person = update_person(api, temp_person, **updated_attributes)
168-
# assert is_valid_person(updated_person)
169-
# for attribute, value in updated_attributes:
170-
# assert getattr(updated_person, attribute, default=None) == value
152+
def test_update_person(self, api, temp_person):
153+
update_attributes = {
154+
"displayName": temp_person.displayName + " Updated",
155+
"firstName": temp_person.firstName + " Updated",
156+
"lastName": temp_person.lastName + " Updated",
157+
}
158+
updated_person = update_person(api, temp_person, **update_attributes)
159+
assert is_valid_person(updated_person)
160+
for attribute, value in update_attributes.items():
161+
assert getattr(updated_person, attribute) == value
171162

172163
def test_get_my_details(self, me):
173164
assert is_valid_person(me)

tests/api/test_teammemberships.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,6 @@ def my_team_membership(api, me, team):
7676
if membership.personId == me.id:
7777
return membership
7878

79-
# Cisco Spark API Documentation says that you should be able to retrieve a list
80-
# of all of your team memberships; however, calling the API endpoint without
81-
# specifying a teamId returns an error (and the docs say that a teamId is
82-
# required). #DocumentationBug
83-
# TODO: Report documentation / API bug on retrieving a user's team memberships
84-
# @pytest.fixture(scope="session")
85-
# def authenticated_user_team_memberships(api, team):
86-
# return list(api.team_memberships.list())
87-
8879

8980
@pytest.fixture(scope="session")
9081
def make_me_team_moderator(api, my_team_membership):

tests/api/test_teams.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,11 @@ def test_get_team_details(self, api, team):
9595
team = get_team_details_by_id(api, team.id)
9696
assert is_valid_team(team)
9797

98-
# TODO: Investigate update team name API not working
99-
# def test_update_team_name(self, api, team):
100-
# new_name = create_string("Updated Team")
101-
# team = api.teams.update(team.id, name=new_name)
102-
# assert is_valid_team(team)
103-
# assert team.title == new_name
98+
def test_update_team_name(self, api, team):
99+
new_name = create_string("Updated Team")
100+
team = api.teams.update(team.id, name=new_name)
101+
assert is_valid_team(team)
102+
assert team.name == new_name
104103

105104
def test_delete_team(self, api, temp_team):
106105
api.teams.delete(temp_team.id)

0 commit comments

Comments
 (0)