Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_group_flow(self):
group = Group()
group.setName("Splitwise_test_case")
# Create Group
group, error = self.sObj.createGroup(group)
self.assertIsNotNone(group.getId())
# Delete Group
self.sObj.deleteGroup(group.getId())
def test_createGroup_exception(self, mockMakeRequest):
mockMakeRequest.side_effect = Exception(
"Invalid response %s. Please check your consumer key and secret." % 404)
group = Group()
user = FriendGroup()
user.setId(784241)
group.addMember(user)
with self.assertRaises(Exception):
self.sObj.createGroup(group)
mockMakeRequest.assert_called_with(
"https://secure.splitwise.com/api/v3.0/create_group", "POST",
{"users__0__user_id": 784241})
def test_createGroup_error(self, mockMakeRequest):
mockMakeRequest.return_value = '{"group":{"id":null,"name":null,"created_at":null,"updated_at":null,"members":[],"simplify_by_default":false,"original_debts":[],"simplified_debts":[],"whiteboard":null,"group_type":"apartment","invite_link":"https://www.splitwise.com/join/vmz4CdiY3LM+1pjy","errors":{"name":["can\'t be blank"]},"avatar":{"original":null,"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-teal1-house-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-teal1-house-500px.png","large":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-teal1-house-200px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-teal1-house-100px.png","small":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-teal1-house-50px.png"},"custom_avatar":false,"cover_photo":{"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-teal-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-teal-500px.png"}}}'.encode('utf-8') # noqa: E501
group = Group()
user = FriendGroup()
user.setId(784241)
group.addMember(user)
groupRes, error = self.sObj.createGroup(group)
mockMakeRequest.assert_called_with(
"https://secure.splitwise.com/api/v3.0/create_group", "POST",
{"users__0__user_id": 784241})
self.assertEqual(error.getErrors(), {"name": ["can\'t be blank"]})
def test_createGroup_success(self, mockMakeRequest):
mockMakeRequest.return_value = '{"group":{"id":19481273,"name":"TestName","created_at":"2020-06-24T05:02:06Z","updated_at":"2020-06-24T05:02:06Z","members":[{"id":79774,"first_name":"Naman","last_name":"Aggarwal","picture":{"small":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg","medium":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg","large":"https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg"},"custom_picture":true,"email":"nam.aggarwal@yahoo.com","registration_status":"confirmed","balance":[]},{"id":784241,"first_name":"ruks","last_name":null,"picture":{"small":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-50px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-100px.png","large":"https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-200px.png"},"custom_picture":false,"email":"rukmanivaithy@gmail.com","registration_status":"confirmed","balance":[]}],"simplify_by_default":false,"original_debts":[],"simplified_debts":[],"whiteboard":null,"group_type":"apartment","invite_link":"https://www.splitwise.com/join/1EUrTyyCHj7+1pjy","avatar":{"original":null,"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-ruby9-house-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-ruby9-house-500px.png","large":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-ruby9-house-200px.png","medium":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-ruby9-house-100px.png","small":"https://s3.amazonaws.com/splitwise/uploads/group/default_avatars/avatar-ruby9-house-50px.png"},"custom_avatar":false,"cover_photo":{"xxlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-ruby-1000px.png","xlarge":"https://s3.amazonaws.com/splitwise/uploads/group/default_cover_photos/coverphoto-ruby-500px.png"}}}'.encode('utf-8') # noqa: E501
group = Group()
group.setName("TestName")
group.setWhiteBoard("test Whiteboard")
group.setType("apartment")
user = FriendGroup()
user.setId(784241)
group.addMember(user)
user2 = FriendGroup()
user2.setId(123)
group.addMember(user2)
groupRes, error = self.sObj.createGroup(group)
mockMakeRequest.assert_called_with(
"https://secure.splitwise.com/api/v3.0/create_group", "POST",
{
"users__0__user_id": 784241,
"users__1__user_id": 123,
"name": "TestName", "whiteboard":
def test_group_invalidkeys_fail(self):
sObj = Splitwise('consumerkey', 'consumersecret', {"oauth_token": "sdsd", "oauth_token_secret": "sdsdd"})
group = Group()
with self.assertRaises(SplitwiseUnauthorizedException):
sObj.createGroup(group)
def getGroups(self):
""" Gets the list of groups a user is part of.
Returns:
:obj:`list` of :obj:`splitwise.group.Group`: List of Groups
"""
content = self.__makeRequest(Splitwise.GET_GROUPS_URL)
content = json.loads(content)
groups = []
if "groups" in content:
for g in content["groups"]:
groups.append(Group(g))
return groups
Returns:
:obj:`splitwise.group.Group`: Object representing a group
"""
try:
content = self.__makeRequest(Splitwise.GET_GROUP_URL+"/"+str(id))
except SplitwiseNotAllowedException as e:
e.setMessage("You are not allowed to fetch group with id %d" % id)
raise
except SplitwiseNotFoundException as e:
e.setMessage("Group with id %d does not exist" % id)
raise
content = json.loads(content)
group = None
if "group" in content:
group = Group(content["group"])
return group
"""
# create group
group_info = group.__dict__
if "members" in group_info:
group_members = group.getMembers()
del group_info["members"]
Splitwise.setUserArray(group_members, group_info)
content = self.__makeRequest(
Splitwise.CREATE_GROUP_URL, "POST", group_info)
content = json.loads(content)
group_detail = None
errors = None
if "group" in content:
group_detail = Group(content["group"])
if "errors" in content["group"]:
if len(content["group"]['errors']) != 0:
errors = SplitwiseError(content["group"]["errors"])
return group_detail, errors