Exemple #1
0
 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"}}}'  # 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"]})
Exemple #2
0
 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})
Exemple #3
0
    def createGroup(self, group):
        """ Creates a new Group.

        Args:
            group(:obj:`splitwise.group.Group`): Splitwise Group Object.

        Returns:
            tuple: tuple containing:
              group(:obj:`splitwise.group.Group`): Object with Group detail

              errors(:obj:`splitwise.error.SplitwiseError`): Object representing errors
        """
        # 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
Exemple #4
0
    def getGroup(self, id=0):
        """ Gets the detail of particular group a user is part of.

        Args:
            id(long, optional): ID of the group. Default value is 0, and means non-group expenses

        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
Exemple #5
0
 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)
Exemple #6
0
    def getGroup(self,id=0):

        content = self.__makeRequest(Splitwise.GET_GROUP_URL+"/"+str(id))
        content = json.loads(content.decode("utf-8"))
        group = None
        if "group" in content:
            group = Group(content["group"])

        return group
Exemple #7
0
    def getGroups(self):

        content = self.__makeRequest(Splitwise.GET_GROUPS_URL)
        content = json.loads(content.decode("utf-8"))
        
        groups = []
        if "groups" in content:
            for g in content["groups"]:
                groups.append(Group(g))

        return groups
Exemple #8
0
    def create_group_if_not_exists(self):
        current_user_id = SplitwiseApiUtils.splitwise_obj.getCurrentUser().id

        group_from_redis = self.client.get(f"sw-${current_user_id}")

        if not group_from_redis:
            group = Group()
            group.setName("Auto-Splitwise")
            friend_obj = self.get_friend(
                SplitwiseApiUtils.splitwise_obj.getFriends())

            friend1 = User()
            friend1.setId(friend_obj.id)

            current_user_id = SplitwiseApiUtils.splitwise_obj.getCurrentUser(
            ).id

            user1 = User()
            user1.setId(current_user_id)

            users = [user1, friend1]
            group.setMembers(users)

            group_created = SplitwiseApiUtils.splitwise_obj.createGroup(group)
            group_id = group_created.id
            self.store_group_id_for_user(group_id, current_user_id)
Exemple #9
0
 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())
Exemple #10
0
    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
Exemple #11
0
    def createGroup(self, 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.decode("utf-8"))
        group_detail = None

        if "group" in content:
            group_detail = Group(content["group"])

        return group_detail
Exemple #12
0
def createGroup(info,groupName):
    # info contains, list of lists which have name and email
    sObj = Splitwise(consumer_key, secret_key)
    sObj.setAccessToken(session['access_token'])
    group = Group()
    group.setName(groupName)
    users = []
    for data in info:
        newUser = createUser(data[0], data[1], data[2])
        users.append(newUser)
    group.setMembers(users)
    sObj.createGroup(group)
 def create_group(self, name):
     access_token = self.sauth.get_access_token()
     self.sauth.splitwise_handle.setAccessToken(access_token)
     group_obj = Group()
     group_obj.setName(name)
     return self.sauth.splitwise_handle.createGroup(group_obj)
Exemple #14
0
 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":"*****@*****.**","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":"*****@*****.**","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"}}}'  # 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": "test Whiteboard",
             "group_type": "apartment"
         })
     self.assertIsNone(error)
     self.assertEqual(groupRes.getId(), 19481273)
     self.assertEqual(groupRes.getName(), "TestName")
     self.assertEqual(groupRes.getCreatedAt(), "2020-06-24T05:02:06Z")
     self.assertEqual(groupRes.getUpdatedAt(), "2020-06-24T05:02:06Z")
     self.assertEqual(len(groupRes.getMembers()), 2)
     self.assertEqual(groupRes.getMembers()[0].getId(), 79774)
     self.assertEqual(groupRes.getMembers()[0].getFirstName(), "Naman")
     self.assertEqual(groupRes.getMembers()[0].getLastName(), "Aggarwal")
     self.assertEqual(
         groupRes.getMembers()[0].getPicture().getSmall(),
         "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/small_mypic.jpg"
     )
     self.assertEqual(
         groupRes.getMembers()[0].getPicture().getMedium(),
         "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/medium_mypic.jpg"
     )
     self.assertEqual(
         groupRes.getMembers()[0].getPicture().getLarge(),
         "https://splitwise.s3.amazonaws.com/uploads/user/avatar/79774/large_mypic.jpg"
     )
     self.assertEqual(groupRes.getMembers()[0].getEmail(),
                      "*****@*****.**")
     self.assertEqual(groupRes.getMembers()[0].getRegistrationStatus(),
                      "confirmed")
     self.assertEqual(len(groupRes.getMembers()[0].getBalances()), 0)
     self.assertEqual(groupRes.getMembers()[1].getId(), 784241)
     self.assertEqual(groupRes.getMembers()[1].getFirstName(), "ruks")
     self.assertEqual(groupRes.getMembers()[1].getLastName(), None)
     self.assertEqual(
         groupRes.getMembers()[1].getPicture().getSmall(),
         "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-50px.png"
     )
     self.assertEqual(
         groupRes.getMembers()[1].getPicture().getMedium(),
         "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-100px.png"
     )
     self.assertEqual(
         groupRes.getMembers()[1].getPicture().getLarge(),
         "https://s3.amazonaws.com/splitwise/uploads/user/default_avatars/avatar-ruby47-200px.png"
     )
     self.assertEqual(groupRes.getMembers()[1].getEmail(),
                      "*****@*****.**")
     self.assertEqual(groupRes.getMembers()[1].getRegistrationStatus(),
                      "confirmed")
     self.assertEqual(len(groupRes.getMembers()[1].getBalances()), 0)
     self.assertEqual(len(groupRes.getOriginalDebts()), 0)
     self.assertEqual(len(groupRes.getSimplifiedDebts()), 0)
     self.assertEqual(groupRes.getWhiteBoard(), None)
     self.assertEqual(groupRes.getType(), "apartment")
     self.assertEqual(groupRes.getInviteLink(),
                      "https://www.splitwise.com/join/1EUrTyyCHj7+1pjy")