def test_get_invites(self):
        user = create_logged_user()
        friend1 = create_user(last_name='test_get_invites-1',
                              first_name='test_get_invites-1',
                              username='******')
        friend2 = create_user(last_name='test_get_invites-2',
                              first_name='test_get_invites-2',
                              username='******')

        invite1 = create_invite(user, friend1)
        invite2 = create_invite(user, friend2)

        self.http_client.fetch(
            self.get_url('/invite/get.json?auth=should-be-user-auth'),
            self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            '{"invite": [{"username": "******", "first_name": "test_get_invites-1", "last_name": "test_get_invites-1", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}, {"username": "******", "first_name": "test_get_invites-2", "last_name": "test_get_invites-2", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}]}'
        )

        invite1.delete()
        invite2.delete()
        user.delete()
        friend1.delete()
        friend2.delete()
    def test_search_user(self):
        user = create_logged_user(username="******")
        user2 = create_user(username="******")
        user3 = create_user(username="******")

        self.http_client.fetch(self.get_url('/search/users.json?username=%s&auth=should-be-user-auth' % "test_"), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, simplejson.dumps({'users': [user2.as_dict(), user3.as_dict()]}))

        user.delete()
        user2.delete()
        user3.delete()
    def test_accept_invite(self):
        user = create_logged_user(username="******")
        friend = create_user(last_name='test_accept_invite',
                             first_name='test_accept_invite',
                             username='******')

        create_invite(friend, user)

        self.http_client.fetch(
            self.get_url(
                '/invite/accept?username=%s&auth=should-be-user-auth' %
                friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            '{"status": "ok", "msg": "User test_accept_invite is now your friend!"}'
        )

        invite = self.session.query(Invite).filter(
            Invite.user_id == user.id).first()

        self.assertEqual(invite, None)

        friendship = self.session.query(Friendship).filter(
            Friendship.user_id == user.id).first()

        assert friendship.user_id == user.id
        assert friendship.friend_id == friend.id

        friendship.delete()
        friend.delete()
        user.delete()
    def test_accept_invite(self):
        user = create_logged_user(username="******")
        friend = create_user(last_name='test_accept_invite', first_name='test_accept_invite',  username='******')

        create_invite(friend, user)

        self.http_client.fetch(self.get_url('/invite/accept?username=%s&auth=should-be-user-auth' % friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "ok", "msg": "User test_accept_invite is now your friend!"}')

        invite = self.session.query(Invite).filter(Invite.user_id == user.id).first()

        self.assertEqual(invite, None)

        friendship = self.session.query(Friendship).filter(Friendship.user_id == user.id).first()

        assert friendship.user_id == user.id
        assert friendship.friend_id == friend.id

        friendship.delete()
        friend.delete()
        user.delete()
    def test_accept_duplicated_invite(self):
        user = create_logged_user(username='******')
        friend = create_user(last_name='test_accept_invite',
                             first_name='test_accept_invite',
                             username='******')

        friendship = create_friendship(user, friend)
        invite = create_invite(friend, user)

        self.http_client.fetch(
            self.get_url(
                '/invite/accept?username=%s&auth=should-be-user-auth' %
                friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            simplejson.dumps({
                "status":
                "error",
                "msg":
                "You and %s are already friend!" % friend.first_name
            }))

        invite.delete()
        friendship.delete()
        user.delete()
        friend.delete()
    def test_send_invite(self):
        user = create_logged_user()
        user2 = create_user(last_name='test_send_invite',
                            first_name='test_send_invite',
                            username='******')

        self.http_client.fetch(
            self.get_url('/invite/send?username=%s&auth=should-be-user-auth' %
                         user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            '{"status": "ok", "msg": "Your invite has been sent."}')

        invite = self.session.query(Invite).filter(
            Invite.user_id == user.id).first()

        assert invite.user_id == user.id
        assert invite.friend_id == user2.id

        invite.delete()
        user.delete()
        user2.delete()
示例#7
0
    def test_get_friendship(self):
        user = create_logged_user()
        user2 = create_user(last_name='test_get_friendship-2', first_name='test_get_friendship-2',  username='******')
        user3 = create_user(last_name='test_get_friendship-3', first_name='test_get_friendship-3',  username='******')

        friendship = create_friendship(user, user2)
        friendship2 = create_friendship(user, user3)

        self.http_client.fetch(self.get_url('/friendship/get.json?auth=should-be-user-auth'), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"friend": [{"username": "******", "first_name": "test_get_friendship-2", "last_name": "test_get_friendship-2", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}, {"username": "******", "first_name": "test_get_friendship-3", "last_name": "test_get_friendship-3", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}]}')

        friendship.delete()
        friendship2.delete()
        user3.delete()
        user2.delete()
        user.delete()
    def test_get_invites(self):
        user = create_logged_user()
        friend1 = create_user(last_name='test_get_invites-1', first_name='test_get_invites-1', username='******')
        friend2 = create_user(last_name='test_get_invites-2', first_name='test_get_invites-2', username='******')

        invite1 = create_invite(user, friend1)
        invite2 = create_invite(user, friend2)

        self.http_client.fetch(self.get_url('/invite/get.json?auth=should-be-user-auth'), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"invite": [{"username": "******", "first_name": "test_get_invites-1", "last_name": "test_get_invites-1", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}, {"username": "******", "first_name": "test_get_invites-2", "last_name": "test_get_invites-2", "gender": "M", "is_active": true, "is_superuser": false, "is_staff": false, "email": "should-be-email"}]}')

        invite1.delete()
        invite2.delete()
        user.delete()
        friend1.delete()
        friend2.delete()
    def test_create_existent_user(self):

        user = create_user(username="******", email="*****@*****.**")

        self.http_client.fetch(self.get_url('/login/create') + '?username=%s&email=%s&firstName=%s&lastName=%s&gender=M' % (user.username, user.email, user.first_name, user.last_name) , self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "error", "msg": "Username already exists."}')

        user.delete()
示例#10
0
    def test_search_user(self):
        user = create_logged_user(username="******")
        user2 = create_user(username="******")
        user3 = create_user(username="******")

        self.http_client.fetch(
            self.get_url(
                '/search/users.json?username=%s&auth=should-be-user-auth' %
                "test_"), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            simplejson.dumps({'users': [user2.as_dict(),
                                        user3.as_dict()]}))

        user.delete()
        user2.delete()
        user3.delete()
示例#11
0
    def test_remove_inexistent_friendship(self):
        user = create_logged_user(username='******')
        user2 = create_user(last_name='remove_inexistent_friendship-2', first_name='remove_inexistent_friendship-2',  username='******')

        self.http_client.fetch(self.get_url('/friendship/remove?username=%s&auth=should-be-user-auth' % user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "error", "msg": "This user are not your friend!"}')

        user.delete()
        user2.delete()
    def test_accept_inexistent_invite(self):
        user = create_logged_user(username="******")
        friend = create_user(last_name='test_accept_invite', first_name='test_accept_invite', username='******')

        self.http_client.fetch(self.get_url('/invite/accept?username=%s&auth=should-be-user-auth' % friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "error", "msg": "Invite not found."}')

        user.delete()
        friend.delete()
    def test_get_other_user(self):
        user = create_logged_user(username="******")
        user2 = create_user(username="******")

        self.http_client.fetch(self.get_url('/user.json?username=%s&auth=should-be-user-auth' % user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, simplejson.dumps({'user': user2.as_dict()}))

        user.delete()
        user2.delete()
    def test_can_login(self):

        user = create_user(username='******')

        self.http_client.fetch(self.get_url('/login') + '?username=%s&password=should-be-password' % user.username, self.stop)

        response = self.wait()

        cache = get_cache()
        username = cache.get(simplejson.loads(response.body)['msg'])

        assert username == user.username

        user.delete()
示例#15
0
    def test_get_other_user(self):
        user = create_logged_user(username="******")
        user2 = create_user(username="******")

        self.http_client.fetch(
            self.get_url('/user.json?username=%s&auth=should-be-user-auth' %
                         user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body,
                         simplejson.dumps({'user': user2.as_dict()}))

        user.delete()
        user2.delete()
示例#16
0
    def test_can_login(self):

        user = create_user(username='******')

        self.http_client.fetch(
            self.get_url('/login') +
            '?username=%s&password=should-be-password' % user.username,
            self.stop)

        response = self.wait()

        cache = get_cache()
        username = cache.get(simplejson.loads(response.body)['msg'])

        assert username == user.username

        user.delete()
示例#17
0
    def test_remove_friendship(self):
        user = create_logged_user()
        user2 = create_user(last_name='test_remove_friendship-2', first_name='test_remove_friendship-2',  username='******')

        create_friendship(user, user2)

        self.http_client.fetch(self.get_url('/friendship/remove?username=%s&auth=should-be-user-auth' % user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "ok", "msg": "Your friendship has been removed!"}')
        friendship_db = self.session.query(Friendship).filter(Friendship.user_id == user.id).first()

        self.assertEqual(friendship_db, None)

        user.delete()
        user2.delete()
    def test_accept_duplicated_invite(self):
        user = create_logged_user(username='******')
        friend = create_user(last_name='test_accept_invite', first_name='test_accept_invite',  username='******')

        friendship = create_friendship(user, friend)
        invite = create_invite(friend, user)

        self.http_client.fetch(self.get_url('/invite/accept?username=%s&auth=should-be-user-auth' % friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, simplejson.dumps({"status": "error", "msg": "You and %s are already friend!" % friend.first_name}))

        invite.delete()
        friendship.delete()
        user.delete()
        friend.delete()
    def test_send_invite(self):
        user = create_logged_user()
        user2 = create_user(last_name='test_send_invite', first_name='test_send_invite', username='******')

        self.http_client.fetch(self.get_url('/invite/send?username=%s&auth=should-be-user-auth' % user2.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body, '{"status": "ok", "msg": "Your invite has been sent."}')

        invite = self.session.query(Invite).filter(Invite.user_id == user.id).first()

        assert invite.user_id == user.id
        assert invite.friend_id == user2.id

        invite.delete()
        user.delete()
        user2.delete()
示例#20
0
    def test_create_existent_user(self):

        user = create_user(username="******",
                           email="*****@*****.**")

        self.http_client.fetch(
            self.get_url('/login/create') +
            '?username=%s&email=%s&firstName=%s&lastName=%s&gender=M' %
            (user.username, user.email, user.first_name, user.last_name),
            self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(
            response.body,
            '{"status": "error", "msg": "Username already exists."}')

        user.delete()
    def test_accept_inexistent_invite(self):
        user = create_logged_user(username="******")
        friend = create_user(last_name='test_accept_invite',
                             first_name='test_accept_invite',
                             username='******')

        self.http_client.fetch(
            self.get_url(
                '/invite/accept?username=%s&auth=should-be-user-auth' %
                friend.username), self.stop)

        response = self.wait()

        self.failIf(response.error)
        self.assertEqual(response.body,
                         '{"status": "error", "msg": "Invite not found."}')

        user.delete()
        friend.delete()