Esempio n. 1
0
    def testMutlipleFriendChatInvite(self):
        print("MultipleFriendChatInvite")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })

        response = loadJson(response.content)
        chatid = response['chatid']

        friendids = [self.friend2.id, self.friend3.id]
        response = client.post(reverse('inviteToChatAPI'), {'userid': self.user.id,
                                                            'friendids': json.dumps(friendids),
                                                            'chatid': chatid})
        response = loadJson(response.content)

        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)

        conversation = Conversation.objects.get(pk=chatid)
        members = conversation.members.all()
        self.assertTrue(self.user in members)
        self.assertTrue(self.friend in members)
        self.assertTrue(self.friend2 in members)
        self.assertIn(self.friend3, members)
Esempio n. 2
0
    def testSendMessage(self):
        print("SendMessage")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })

        response = loadJson(response.content)
        chatid = response['chatid']

        response = client.post(reverse('sendMessageAPI'), {
            'userid': self.user.id,
            'chatid': chatid,
            'text': 'hello'
        })
        response = loadJson(response.content)

        self.assertEqual(response['success'], True)

        convo = Conversation.objects.get(pk=chatid)
        message = convo.messages.latest('created')

        self.assertEqual(message.user, self.user)
        self.assertEqual(message.text, 'hello')
        self.assertEqual(message.conversation, convo)
        self.assertIn('chats', response)
        self.assertIn('newsince', response)
Esempio n. 3
0
    def testFacebookLoginWithFriends(self):
        print("FacebookLoginWithFriends")
        client = Client()

        user = User.objects.create(username='******', password='******', email='user1', first_name='first', last_name='last')
        userprofile = UserProfile.objects.create(user=user)

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android',
            'lat': 42.151515,
            'lng': -87.498989
        })
        response = loadJson(response.content)

        self.assertEqual(response['success'], True)
        self.assertIn('userid', response)

        myProfile = UserProfile.objects.get(pk=response['userid'])
        myProfile.friends.add(userprofile)
        myProfile.save()
        userprofile.friends.add(myProfile)
        userprofile.save()

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android'
        })
        response = loadJson(response.content)

        userprofileFriendData = {'userid': userprofile.id, 'firstname': user.first_name, 'lastname': user.last_name,
                                 'blocked': False}
        self.assertNotEqual(len(response['friends']), 0)
        for key, val in userprofileFriendData.items():
            self.assertEqual(val, userprofileFriendData[key])
Esempio n. 4
0
    def testCreateConversation(self):
        print("CreateConversation")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })

        response = loadJson(response.content)
        chatid = response['chatid']

        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)

        conversation = Conversation.objects.get(pk=chatid)
        members = conversation.members.all()
        self.assertTrue(self.user in members)
        self.assertTrue(self.friend in members)

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })
        response = loadJson(response.content)
        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)
        self.assertEqual(response['chatid'], chatid)

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend2.id
        })
        response = loadJson(response.content)
        self.assertEqual(response['success'], True)
        self.assertNotEqual(response['chatid'], chatid)
        chat2Id = response['chatid']

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendids': json.dumps([self.friend2.id, self.friend.id])
        })
        response = loadJson(response.content)
        self.assertEqual(response['success'], True)
        self.assertNotEqual(response['chatid'], chatid)
        self.assertNotEqual(response['chatid'], chat2Id)
        chat3Id = response['chatid']

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendids': json.dumps([self.friend2.id, self.friend.id])
        })
        response = loadJson(response.content)
        self.assertEqual(response['success'], True)
        self.assertNotEqual(response['chatid'], chatid)
        self.assertNotEqual(response['chatid'], chat2Id)
        self.assertEqual(response['chatid'], chat3Id)
Esempio n. 5
0
    def testFacebookLoginWithAllData(self):
        print("FacebookLoginWithAllData")
        client = Client()

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android',
            'lat': 42.151515,
            'lng': -87.498989
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])
        userid = response['userid']
        userProfile = UserProfile.objects.get(pk=userid)

        friend = User.objects.create(username='******', password='******', email='friend')
        friendProfile = UserProfile.objects.create(user=friend)

        userProfile.friends.add(friendProfile)
        friendProfile.friends.add(userProfile)

        group = Group.objects.create(name='group1', user=userProfile)
        group.members.add(friendProfile)
        group.save()

        lat = 42.341560
        lng = -83.501783
        address = '46894 spinning wheel'
        city = 'canton'
        state = 'MI'
        venue = "My house"
        expirationDate = datetime.utcnow() + timedelta(hours=1)

        location = Location.objects.create(lng=lng, lat=lat, point=Point(lng, lat), city=city, state=state, venue=venue,
                                           address=address)

        friendStatus = Status.objects.create(user=friendProfile, expires=expirationDate, text='Hang out1',
                                             location=location)

        myStatus = Status.objects.create(user=userProfile, expires=expirationDate, text='mystatus', location=location)

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android'
        })

        response = loadJson(response.content)

        self.assertTrue(response['success'])
        self.assertEqual(response['statuses'][0]['statusid'], friendStatus.id)
        self.assertEqual(response['groups'][1]['groupid'], group.id)
        self.assertEqual(response['mystatuses'][0]['statusid'], myStatus.id)
        self.assertEqual(response['friends'][0]['userid'], friendProfile.id)
        self.assertIn('chats', response)
        self.assertEqual(response['favoritesnotifications'], True)
Esempio n. 6
0
    def testGetChatPage(self):
        NUMBER_OF_MESSAGES = 30

        print("Test Chat Paging")
        client = Client()

        chat = Conversation.objects.create()
        chat.members.add(self.user, self.friend, self.friend2)
        chat.save()

        for x in range(0, NUMBER_OF_MESSAGES):
            Message.objects.create(user=self.friend, conversation=chat, text="a")

        latestMessage = chat.messages.latest('id')

        response = client.post(reverse('getChatPageAPI'), {
            'userid': self.user.id,
            'earliestmessageid': latestMessage.id,
            'chatid': chat.id
        })
        response = loadJson(response.content)

        self.assertNotIn('error', response)
        self.assertTrue(response['success'])
        chatData = response['chat']
        messages = chatData['messages']

        self.assertEqual(len(messages), CHAT_MESSAGE_PER_PAGE)

        earliestId = 999999999

        for msg in messages:
            newId = msg['messageid']
            if newId < earliestId:
                earliestId = newId

        response = client.post(reverse('getChatPageAPI'), {
            'userid': self.user.id,
            'earliestmessageid': earliestId,
            'chatid': chat.id
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])
        chatData = response['chat']
        messages = chatData['messages']

        self.assertEqual(len(messages), NUMBER_OF_MESSAGES - CHAT_MESSAGE_PER_PAGE - 1)
Esempio n. 7
0
    def testGetSingleMessage(self):
        print("GetSingleMessage")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })

        response = loadJson(response.content)
        chatid = response['chatid']

        client.post(reverse('sendMessageAPI'), {
            'userid': self.user.id,
            'chatid': chatid,
            'text': 'hello'
        })

        since = datetime.utcnow() - timedelta(hours=1)

        response = client.post(reverse('getMessagesAPI'), {
            'userid': self.friend.id,
            'since': since.strftime(MICROSECOND_DATETIME_FORMAT)
        })

        response = loadJson(response.content)

        self.assertEqual(len(response['chats']), 1)
        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)
        self.assertIn('members', response['chats'][0])

        convo = Conversation.objects.get(pk=chatid)
        convoMessage = convo.messages.latest('created')

        chatResponse = response['chats'][0]
        messageResponse = chatResponse['messages'][0]

        self.assertEqual(messageResponse['messageid'], convoMessage.id)
        self.assertEqual(chatResponse['chatid'], convo.id)
        self.assertEqual(messageResponse['text'], convoMessage.text)
        self.assertEqual(messageResponse['userid'], convoMessage.user.id)
Esempio n. 8
0
    def testCreateTestUser(self):
        print("Create Test User")
        client = Client()

        response = client.post(reverse('createTestUserAPI'), {
            'numfriends': 100
        })

        response = loadJson(response.content)

        self.assertTrue(response['success'])
Esempio n. 9
0
    def testGetSettingsOnLogin(self):
        print("FacebookLoginWithSettings")
        client = Client()

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android',
            'lat': 42.151515,
            'lng': -87.498989
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])

        user = UserProfile.objects.get(pk=response['userid'])

        client.post(reverse('setSettingAPI'), {
            'userid': user.id,
            'key': 'statusradius',
            'value': 'value1'
        })

        client.post(reverse('setSettingAPI'), {
            'userid': user.id,
            'key': 'imboredtext',
            'value': 'value2'
        })

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android'
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])
        self.assertEqual(len(response['settings']), 2)
        setting1 = response['settings']['statusradius']
        setting2 = response['settings']['imboredtext']

        self.assertEqual(setting1, 'value1')
        self.assertEqual(setting2, 'value2')
Esempio n. 10
0
    def testCreateConverationWithNonFriend(self):
        print("CreateConversationWithNonFriend")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.nonFriend.id
        })

        response = loadJson(response.content)
        self.assertEqual(response['success'], False)
        self.assertIn('error', response)
Esempio n. 11
0
    def testChatInviteBlockedFriend(self):
        print("ChatInviteBlockedFriend")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })

        response = loadJson(response.content)
        chatid = response['chatid']

        response = client.post(reverse('inviteToChatAPI'), {
            'userid': self.user.id,
            'friendid': self.blockedFriend.id,
            'chatid': chatid
        })

        response = loadJson(response.content)
        self.assertEqual(response['success'], False)
        self.assertIn('error', response)
Esempio n. 12
0
    def testLeaveInvalidChat(self):
        print("LeaveInvalidChat")
        client = Client()

        response = client.post(reverse('leaveChatAPI'), {
            'userid': self.user.id,
            'chatid': 1
        })
        response = loadJson(response.content)

        self.assertEqual(response['success'], False)
        self.assertIn('error', response)
Esempio n. 13
0
    def testGetDetails(self):
        print("Get User Details")
        client = Client()

        response = client.get(reverse('getUserDetailsAPI'), {
            'userid': self.userProfile.id
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])
        self.assertEqual(response['firstname'], self.userProfile.user.first_name)
        self.assertEqual(response['lastname'], self.userProfile.user.last_name)
        self.assertEqual(response['facebookid'], self.userProfile.facebookUID)
Esempio n. 14
0
    def testSetFavNotifications(self):
        print("Set Fav Notifs")
        client = Client()

        response = client.get(reverse('setFavNotificationsAPI'), {
            'userid': self.user.id,
            'value': False
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])

        user = UserProfile.objects.get(pk=self.user.id)
        self.assertFalse(user.favoritesNotifications)
Esempio n. 15
0
    def testLeaveChat(self):
        print("LeaveChat")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.friend.id
        })
        response = loadJson(response.content)
        chatid = response['chatid']

        convo = Conversation.objects.get(pk=chatid)
        convo.members.add(self.friend2)

        response = client.post(reverse('leaveChatAPI'), {
            'userid': self.user.id,
            'chatid': chatid
        })
        response = loadJson(response.content)

        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)

        members = convo.members.all()
        self.assertTrue(self.user not in members)
        self.assertTrue(self.friend in members)

        response = client.post(reverse('leaveChatAPI'), {
            'userid': self.friend.id,
            'chatid': chatid
        })
        response = loadJson(response.content)

        members = convo.members.all()
        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)
        self.assertTrue(self.friend in members)
Esempio n. 16
0
    def testGetMultipleDetails(self):
        print("Get Multiple user details")
        client = Client()

        response = client.get(reverse('getUserDetailsAPI'), {
            'userids': json.dumps([self.userProfile.id, self.userProfile2.id])
        })
        response = loadJson(response.content)

        self.assertTrue(response['success'])
        self.assertEqual(len(response['users']), 2)

        userA = response['users'][0]
        userB = response['users'][1]

        self.assertTrue(userA['firstname'] == self.userProfile.user.first_name or userA['firstname'] == self.userProfile2.user.first_name)
        self.assertTrue(userB['lastname'] == self.userProfile.user.last_name or userB['lastname'] == self.userProfile2.user.last_name)
Esempio n. 17
0
    def testCreateConversationWithBlockedFriend(self):
        print("CreateConversationWithBlockedFriend")
        client = Client()

        response = client.post(reverse('createChatAPI'), {
            'userid': self.user.id,
            'friendid': self.blockedFriend.id
        })

        response = loadJson(response.content)
        self.assertEqual(response['success'], True)

        chatid = response['chatid']

        chat = Conversation.objects.get(pk=chatid)

        self.assertEqual(len(chat.members.all()), 1)
        self.assertNotIn(self.blockedFriend, chat.members.all())
Esempio n. 18
0
    def testRefreshFacebookFriends(self):
        print("refresh fb friends")

        client = Client()

        user = User.objects.create(email="*****@*****.**", password=0)
        userProfile = UserProfile.objects.create(user=user)

        response = client.post(reverse('refreshFacebookFriendsAPI'), {
            'userid': userProfile.id,
            'accesstoken': self.authKey
        })
        response = loadJson(response.content)

        self.assertIn('users', response)
        friends = response['users']

        for friend in friends:
            self.assertIn('userid', friend)
            self.assertIn('facebookid', friend)
            self.assertIn('firstname', friend)
            self.assertIn('lastname', friend)
Esempio n. 19
0
    def testRegister(self):
        print("Register")
        client = Client()

        response = client.post(reverse('facebookLoginAPI'), {
            'fbauthkey': self.authKey,
            'device': 'android',
            'lat': 42.151515,
            'lng': -87.498989
        })
        response = loadJson(response.content)
        self.assertEqual(response['success'], True)
        self.assertNotIn('error', response)
        self.assertEqual(response['firstname'], self.firstName)
        self.assertEqual(response['lastname'], self.lastName)

        userProfile = UserProfile.objects.get(pk=response['userid'])
        self.assertEqual(userProfile.user.first_name, self.firstName)
        self.assertEqual(userProfile.user.last_name, self.lastName)

        try:
            group = Group.objects.get(user=userProfile, name="Favorites")
        except Group.DoesNotExist:
            self.assertTrue(False)