コード例 #1
0
ファイル: test_groups.py プロジェクト: angelo-romano/mycouch
    def test_this(self):
        group = {
            'title': 'Main Berlin Group',
            'description': 'Description',
            'city_id': 1,
        }
        subgroup = {
            'title': 'Main Berlin Subgroup',
            'description': 'Description',
            'city_id': 1,
        }
        # AUTHENTICATION here
        logged_user = auth_user(self.app, 'angelo', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        # group creation
        resp = send_call(self.app, 'post', '/groups',
                         group, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        # subgroup creation
        subgroup['parent_group_id'] = resp_data.get('id')
        resp = send_call(self.app, 'post', '/groups',
                         subgroup, token=token)
        self.assertEquals(resp.status[:3], '200')
コード例 #2
0
    def test_hospitality_requests(self):
        today = date.today()
        token, logged_user = self._sender_login()

        # message failure here - not allowed
        request = {
            'subject': 'A Hospitality Request',
            'text': 'A test text...',
            'recipient_list_ids': [2],
        }
        resp = send_call(self.app, 'post', '/messages/in/hospitality_requests',
                         request, token=token)
        self.assertEquals(resp.status[:3], '403')
        # message failure here - too many recipients
        request = {
            'subject': 'A Hospitality Request',
            'text': 'A test text...',
            'recipient_list_ids': [2, 3],
            'date_from': (today + timedelta(days=10)).strftime('%Y-%m-%d'),
            'date_to': (today + timedelta(days=12)).strftime('%Y-%m-%d'),
        }
        resp = send_call(self.app, 'post', '/messages/out/hospitality_requests',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')
        # message failure here - missing date_to
        request = {
            'subject': 'A Hospitality Request',
            'text': 'A test text...',
            'recipient_list_ids': [2],
            'date_from': (today + timedelta(days=10)).strftime('%Y-%m-%d'),
        }
        resp = send_call(self.app, 'post', '/messages/out/hospitality_requests',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')
        # message failure here - invalid date
        request = {
            'subject': 'A Hospitality Request',
            'text': 'A test text...',
            'recipient_list_ids': [2],
            'date_from': (today - timedelta(days=10)).strftime('%Y-%m-%d'),
            'date_to': (today + timedelta(days=12)).strftime('%Y-%m-%d'),
        }
        resp = send_call(self.app, 'post', '/messages/out/hospitality_requests',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')
        # message being sent here
        request = {
            'subject': 'A Hospitality Request',
            'text': 'A test text...',
            'recipient_list_ids': [2],
            'date_from': (today + timedelta(days=10)).strftime('%Y-%m-%d'),
            'date_to': (today + timedelta(days=12)).strftime('%Y-%m-%d'),
        }
        resp = send_call(self.app, 'post', '/messages/out/hospitality_requests',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertEquals(logged_user.get('id'), resp_data.get('sender_id'))
        msg_id = resp_data.get('id')
        self.assertIsNotNone(msg_id)
コード例 #3
0
    def test_this(self):
        data = {
            'rating': Decimal('1.41199860'),
            'name': 'Hobro',
            'country_id': 11,  # Germany
            'latitude': Decimal('56.6332999999999984'),
            'timezone': 1,
            'slug': 'hobro',
            'longitude': Decimal('9.8000000000000007'),
            'wikiname': 'Hobro',
            'type': 'cities'}
        data2 = {
            'rating': Decimal('1.80019736'),
            'name': 'Hoddesdon',
            'country_id': 11,  # Germany
            'latitude': Decimal('51.7500000000000000'),
            'timezone': 0,
            'type': 'cities',
            'slug': 'hoddesdon',
            'longitude': Decimal('0E-16'),
            'wikiname': 'Hoddesdon'}
        # CREATING CITY [ERROR]
        logged_user = auth_user(self.app, 'angelo', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        data['type'] = 'not_a_cities'
        resp = send_call(self.app, 'post', '/locations/%s' % data['type'],
                         data, token=token)
        self.assertEquals(resp.status[:3], '400')
        # CREATING CITY [ERROR]
        data['type'] = 'cities'
        resp = send_call(self.app, 'post', '/locations/%s' % data['type'],
                         data, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(resp_data['id'] > 0)
        # GET EXPLICIT LOCATION - NOW WORKS
        resp = send_call(self.app, 'get', '/locations/%s/%s' % (
            resp_data['type'], resp_data['id']), token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        # GET EXPLICIT LOCATION - NOW WORKS
        resp = send_call(self.app, 'get', '/locations/%s/%s' % (
            resp_data['type'], resp_data['id'] + 100000), token=token)
        self.assertEquals(resp.status[:3], '404')
コード例 #4
0
    def test_activity(self):
        # AUTHENTICATION here
        logged_user = auth_user(self.app, 'angelo', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        today = datetime.now().replace(
            hour=0, minute=0, second=0, microsecond=0)

        # message failure(s) here
        # 1. invalid status
        request = {
            'city_id': 1,
            'location': 'A location',
            'title': 'Activity name',
            'description': 'Activity description',
            'scheduled_from': today - timedelta(days=3, hours=19),
            'scheduled_until': today + timedelta(days=3, hours=22),
        }
        resp = send_call(self.app, 'post', '/activities',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 2. invalid city
        request = {
            'city_id': 3353335,  # non existing city
            'location': 'A location',
            'title': 'Activity name',
            'description': 'Activity description',
            'scheduled_from': today + timedelta(days=3, hours=19),
            'scheduled_until': today + timedelta(days=3, hours=22),
        }
        resp = send_call(self.app, 'post', '/activities',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 3. missing name
        request = {
            'city_id': 3353335,  # non existing city
            'location': 'A location',
            'description': 'Activity description',
            'scheduled_from': today + timedelta(days=3, hours=19),
            'scheduled_until': today + timedelta(days=3, hours=22),
        }
        resp = send_call(self.app, 'post', '/activities',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 4. valid - success
        request = {
            'city_id': 1,  # Berlin
            'location': 'A location',
            'title': 'Activity name',
            'description': 'Activity description',
            'scheduled_from': today + timedelta(days=3, hours=19),
            'scheduled_until': today + timedelta(days=3, hours=22),
        }
        resp = send_call(self.app, 'post', '/activities',
                         request, token=token)
        resp_data = json_loads(resp.data)
        self.assertEquals(resp.status[:3], '200')
        self.assertTrue(all(v == resp_data[k] for k, v in request.iteritems()))

        # fetching all activities - token not needed
        resp = send_call(self.app, 'get', '/activities')
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, list))
        self.assertEquals(len(resp_data), 1)
        this_one = resp_data[0]
        this_one_id = resp_data[0].get('id')
        self.assertTrue(this_one_id > 0)
        self.assertTrue(all(v == this_one[k] for k, v in request.iteritems()))

        attending_count = this_one.get('attending_count')
        self.assertTrue(isinstance(attending_count, dict))
        self.assertTrue(all(
            k in attending_count for k in ('yes', 'no', 'maybe')))
        self.assertEquals(attending_count['yes'], 1)
        self.assertEquals(attending_count['maybe'], 0)
        self.assertEquals(attending_count['no'], 0)
コード例 #5
0
ファイル: test_users.py プロジェクト: angelo-romano/mycouch
    def test_this(self):
        today = date.today()
        data = {
            'username': '******',
            'password': '******',
            'first_name': 'Angelo',
            'last_name': 'Romano',
            'email': '*****@*****.**',
            'gender': '1',
            'birth_date': date(today.year - 21, today.month, today.day),
        }
        data2 = {
            'username': '******',
            'password': '******',
            'first_name': 'Angelo1',
            'last_name': 'Romano1',
            'email': '*****@*****.**',
            'gender': '1',
            'birth_date': date(today.year - 31, today.month, today.day),
        }
        # CREATING ACCOUNT 1
        resp = send_call(self.app, 'post', '/users', data)
        resp_data = json_loads(resp.data)
        self.assertTrue(all(data.get(key) == resp_data.get(key)
                            for key in data.iterkeys()
                            if key != 'password'))
        id_one = resp_data['id']
        self.assertTrue(id_one > 0)
        # CREATING ACCOUNT 2
        resp = send_call(self.app, 'post', '/users', data2)
        resp_data2 = json_loads(resp.data)
        self.assertTrue(all(data2[key] == resp_data2[key]
                            for key in data.iterkeys()
                            if key != 'password'))
        id_two = resp_data2['id']
        self.assertTrue(id_two > 0)
        # GET EXPLICIT USER - AUTH FAILURE
        resp = send_call(self.app, 'get', '/current_user')
        self.assertEquals(resp.status[:3], '401')
        # AUTHENTICATION COMES HERE
        resp = auth_user(self.app, data['username'], data['password'] + 'no')
        self.assertIsNone(resp)

        resp = auth_user(self.app, data['username'], data['password'])
        self.assertIsNotNone(resp)
        token = resp.get('token')

        # GET EXPLICIT CURRENT USER - NOW WORKS
        resp = send_call(self.app, 'get', '/current_user', token=token)
        resp_data = json_loads(resp.data)
        self.assertEquals(resp.status[:3], '200')
        self.assertEquals(resp_data.get('id'), id_one)

        # GET EXPLICIT USERS
        resp = send_call(self.app, 'get', '/users/%s' % id_one, token=token)
        resp_data = json_loads(resp.data)
        self.assertEquals(resp.status[:3], '200')
        self.assertTrue(all(data[key] == resp_data[key]
                            for key in data.iterkeys()
                            if key != 'password'))
        resp = send_call(self.app, 'get', '/users/%s' % id_two, token=token)
        resp_data = json_loads(resp.data)
        self.assertEquals(resp.status[:3], '200')
        self.assertTrue(all(data2[key] == resp_data[key]
                            for key in data.iterkeys()
                            if key != 'password'))

        # UPDATE USER
        patch_data = {
            'details': {
                'websites': ['http://www.angeloromano.com'],
                'sections': {
                    'summary': 'This is a summary.',
                    'couch_info': 'This is my couch info.',
                },
                'profile_details': {
                    'occupation': 'My occupation.',
                },
            },
        }
        resp = send_call(self.app, 'patch', '/current_user',
                         patch_data, token=token)
        resp_data = json_loads(resp.data)
        self.assertEquals(resp.status[:3], '200')
        self.assertTrue(all(data[key] == resp_data[key]
                            for key in data.iterkeys()
                            if key != 'password'))
        self.assertEquals(resp_data.get('details'), patch_data['details'])
コード例 #6
0
    def test_private_messages(self):
        request = {
            'subject': 'A Test Message',
            'text': 'A test text...',
            'recipient_list_ids': [2],
        }
        token, logged_user = self._sender_login()

        # message failure here
        resp = send_call(self.app, 'post', '/messages/in/privates',
                         request, token=token)
        self.assertEquals(resp.status[:3], '403')
        # message being sent here
        resp = send_call(self.app, 'post', '/messages/out/privates',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        msg_id = resp_data.get('id')
        self.assertEquals(logged_user.get('id'), resp_data.get('sender_id'))
        self.assertIsNotNone(msg_id)
        # message retrieval
        resp = send_call(self.app, 'get', '/messages/out/privates',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, list) and len(resp_data) == 1)
        resp_data = resp_data[0]
        self.assertTrue(all(
            v == resp_data.get(k)
            for (k, v) in request.iteritems()))
        self.assertEquals(logged_user.get('id'), resp_data.get('sender_id'))
        # message retrieval (explicit ID)
        resp = send_call(self.app, 'get',
                         '/messages/out/privates/%s' % msg_id,
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, dict))
        self.assertTrue(all(
            v == resp_data.get(k)
            for (k, v) in request.iteritems()))
        self.assertEquals(logged_user.get('id'),
                          resp_data.get('sender_id'))
        # changing message status is allowed only for the recipients
        resp = send_call(self.app, 'patch',
                         '/messages/out/privates/%s' % msg_id,
                         {'message_status': 'read'}, token=token)
        self.assertEquals(resp.status[:3], '403')
        # ensures the other user has successfully received the message
        # -- 1. authentication
        sender_user_id = logged_user.get('id')
        token, logged_user = self._recipient_login()
        # -- 2. retrieval
        resp = send_call(self.app, 'get',
                         '/messages/in/privates',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, list) and len(resp_data) == 1)
        resp_data = resp_data[0]
        self.assertTrue(all(
            v == resp_data.get(k)
            for (k, v) in request.iteritems()))
        self.assertEquals(sender_user_id, resp_data.get('sender_id'))
        self.assertEquals(resp_data.get('message_status'), 'unread')
        msg_id = resp_data.get('id')
        # changing message status is not allowed here - token must be passed
        resp = send_call(self.app, 'patch',
                         '/messages/in/privates/%s' % msg_id,
                         {'message_status': 'read'})
        self.assertEquals(resp.status[:3], '401')
        # changing message status is allowed here
        resp = send_call(self.app, 'patch',
                         '/messages/in/privates/%s' % msg_id,
                         {'message_status': 'read'}, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertEquals(resp_data.get('message_status'), 'read')
        # changing message status is not allowed here - wrong value
        resp = send_call(self.app, 'patch',
                         '/messages/in/privates/%s' % msg_id,
                         {'message_status': 'misread'}, token=token)
        self.assertEquals(resp.status[:3], '400')

        # writes a reply
        request = {
            'subject': 'A Test Message',
            'text': 'A test text...',
            'recipient_list_ids': [1],
            'reply_to_id': msg_id,
        }
        resp = send_call(self.app, 'post', '/messages/out/privates',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        msg_id = resp_data.get('id')
        self.assertEquals(logged_user.get('id'), resp_data.get('sender_id'))
        self.assertTrue(all(
            v == resp_data.get(k)
            for (k, v) in request.iteritems()))

        # time to read the reply
        token, logged_user = self._sender_login()
        resp = send_call(self.app, 'get',
                         '/messages/in/privates/%s' % msg_id)
        # no token - 401
        self.assertEquals(resp.status[:3], '401')
        # token specified - 200
        resp = send_call(self.app, 'get',
                         '/messages/in/privates/%s' % msg_id,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(all(
            v == resp_data.get(k)
            for (k, v) in request.iteritems()))
        self.assertEquals(resp_data.get('message_status'), 'unread')
コード例 #7
0
    def test_friendship(self):
        # AUTHENTICATION here
        logged_user = auth_user(self.app, 'angelo', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        # message failure(s) here
        # 1. invalid status
        request = {
            'description': 'A friend',
            'user_id': 2,
            'friendship_level': 'invalid',
        }
        resp = send_call(self.app, 'post', '/connections/friendships',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 2. invalid user
        request = {
            'description': 'A friend',
            'user_id': 666666,
            'friendship_level': 'friend',
        }
        resp = send_call(self.app, 'post', '/connections/friendships',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 3. missing description
        request = {
            'description': '',
            'user_id': 2,
            'friendship_level': 'friend',
        }
        resp = send_call(self.app, 'post', '/connections/friendships',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # SUCCESSFUL HERE
        request = {
            'description': 'A friend.',
            'user_id': 2,
            'friendship_level': 'friend',
        }
        resp = send_call(self.app, 'post', '/connections/friendships',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')

        # fetching all friendship requests
        resp = send_call(self.app, 'get', '/connections/friendships',
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, list))
        self.assertEquals(len(resp_data), 1)
        this_one = resp_data[0]
        this_one_id = resp_data[0].get('id')
        self.assertTrue(this_one_id > 0)
        self.assertTrue(all(v == this_one[k] for k, v in request.iteritems()))

        # fetching this friendship request
        resp = send_call(self.app, 'get',
                         '/connections/friendships/%s' % this_one_id,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, dict))
        self.assertTrue(all(v == this_one[k] for k, v in resp_data.iteritems()))

        # trying to "approve" friendship status (can be done only by the other
        # counterpart)
        patch_request = {'type_status': 'accepted'}
        resp = send_call(self.app, 'patch',
                         '/connections/friendships/%s' % this_one_id,
                         patch_request,
                         token=token)
        self.assertEquals(resp.status[:3], '405')

        # fetching a non-existing friendship request (404 expected)
        resp = send_call(self.app, 'get',
                         '/connections/friendships/%s' % (this_one_id + 1000),
                         token=token)
        self.assertEquals(resp.status[:3], '404')

        # AUTHENTICATION for other user here
        logged_user = auth_user(self.app, 'delgog', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        # fetching this friendship request
        resp = send_call(self.app, 'get',
                         '/connections/friendships/%s' % this_one_id,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, dict))
        self.assertTrue(all(v == this_one[k] for k, v in resp_data.iteritems()
                            if k != 'user_id'))
        self.assertEquals(resp_data.get('user_id'), 1)

        # trying to "approve" friendship status (can be done only by the other
        # counterpart)
        # 1. invalid type status
        patch_request = {'type_status': 'invalid'}
        resp = send_call(self.app, 'patch',
                         '/connections/friendships/%s' % this_one_id,
                         patch_request,
                         token=token)
        self.assertEquals(resp.status[:3], '400')
        # 2. valid type status - success
        patch_request = {'type_status': 'accepted'}
        resp = send_call(self.app, 'patch',
                         '/connections/friendships/%s' % this_one_id,
                         patch_request,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertEquals(resp_data.get('type_status'), 'accepted')
コード例 #8
0
    def test_reference(self):
        # AUTHENTICATION here
        logged_user = auth_user(self.app, 'angelo', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        # message failure(s) here
        # 1. invalid status
        request = {
            'text': 'A reference',
            'user_id': 2,
            'reference_type': 'invalid',
        }
        resp = send_call(self.app, 'post', '/connections/references',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 2. invalid user
        request = {
            'text': 'A reference',
            'user_id': 66666,
            'reference_type': 'positive',
        }
        resp = send_call(self.app, 'post', '/connections/references',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # 3. missing description
        request = {
            'text': '',
            'user_id': 2,
            'reference_type': 'positive',
        }
        resp = send_call(self.app, 'post', '/connections/references',
                         request, token=token)
        self.assertEquals(resp.status[:3], '400')

        # SUCCESSFUL HERE
        request = {
            'text': 'A reference',
            'user_id': 2,
            'reference_type': 'positive',
        }
        resp = send_call(self.app, 'post', '/connections/references',
                         request, token=token)
        self.assertEquals(resp.status[:3], '200')

        # fetching all friendship requests
        resp = send_call(self.app, 'get', '/connections/references',
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, list))
        self.assertEquals(len(resp_data), 1)
        this_one = resp_data[0]
        this_one_id = this_one.get('id')
        self.assertTrue(this_one_id > 0)
        self.assertTrue(all(v == this_one[k] for k, v in request.iteritems()))

        # fetching this friendship request
        resp = send_call(self.app, 'get',
                         '/connections/references/%s' % this_one_id,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, dict))
        self.assertTrue(all(v == this_one[k] for k, v in resp_data.iteritems()))

        # fetching a non-existing friendship request (404 expected)
        resp = send_call(self.app, 'get',
                         '/connections/references/%s' % (this_one_id + 1000),
                         token=token)
        self.assertEquals(resp.status[:3], '404')

        # AUTHENTICATION for other user here
        logged_user = auth_user(self.app, 'delgog', 'ciao')
        self.assertIsNotNone(logged_user)
        token = logged_user.get('token')

        # fetching this friendship request
        resp = send_call(self.app, 'get',
                         '/connections/references/%s' % this_one_id,
                         token=token)
        self.assertEquals(resp.status[:3], '200')
        resp_data = json_loads(resp.data)
        self.assertTrue(isinstance(resp_data, dict))
        self.assertTrue(all(v == this_one[k] for k, v in resp_data.iteritems()
                            if k != 'user_id'))
        self.assertEquals(resp_data.get('user_id'), 1)