コード例 #1
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_existing_properties(self):
        user = user_backend.create(username2, property_backend=property_backend)
        property_backend.create(user, propkey1, propval3)  # propval1 is in json file

        path = os.path.join(self.base, 'users1.json')
        with capture() as (stdout, stderr):
            cmd = [path]
            restauth_import(cmd)
            self.assertItemsEqual(user_backend.list(), [username1, username2, username3])
            user = user_backend.get(username2)

            pattern = '^%s: Property "%s" already exists\.$' % (username2, propkey1)
            self.assertHasLine(stdout, pattern)
            self.assertHasLine(stdout, '^%s: Property "date joined" already exists\.$' % username2)

            expected_props = {
                propkey1: propval3,  # propva1 is in json-file - we don't overwrite!
                propkey2: propval2,
                u'last login': u'2013-12-01 19:27:44',  # date from json file
            }

            props = property_backend.list(user)
            # delete 'date joined' prop because it was created by the user_backend and
            # restauth-import doesn't overwrite in this invocation:
            del props['date joined']

            self.assertEqual(props, expected_props)
コード例 #2
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_delete_property(self):
        property_backend.create(user=self.user1, key=propkey1, value=propval1)
        property_backend.create(user=self.user1, key=propkey2, value=propval2)

        resp = self.delete('/users/%s/props/%s/' % (username1, propkey1),)
        self.assertEqual(resp.status_code, http_client.NO_CONTENT)
        self.assertProperties(self.user1, {propkey2: propval2, })
コード例 #3
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_create_existing_property(self):
        property_backend.create(self.user, propkey1, propval1)

        url = '/test/users/%s/props/' % self.user.username
        resp = self.post(url, {'prop': propkey1, 'value': propval2})
        self.assertEqual(resp.status_code, http_client.CONFLICT)

        self.assertProperties(self.user, {propkey1: propval1})
コード例 #4
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_set_existing_property(self):
        property_backend.create(user=self.user1, key=propkey1, value=propval1)

        # set a property again and assert that it returns the old value:
        resp = self.put('/users/%s/props/%s/' % (username1, propkey1), {'value': propval2, })
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertEqual(self.parse(resp, 'str'), propval1)
        self.assertEqual(property_backend.get(self.user1, propkey1), propval2)
        self.assertRaises(PropertyNotFound, property_backend.get, self.user2, propkey1)
コード例 #5
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_cross_user(self):
        # two users have properties with the same key, we verify that deleting
        # one doesn't delete the other:
        property_backend.create(user=self.user1, key=propkey1, value=propval1)
        property_backend.create(user=self.user2, key=propkey1, value=propval1)

        resp = self.delete('/users/%s/props/%s/' % (username1, propkey1),)
        self.assertEqual(resp.status_code, http_client.NO_CONTENT)
        self.assertProperties(self.user1, {})
        self.assertProperties(self.user2, {propkey1: propval1, })
コード例 #6
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_get_single_property(self):
        property_backend.create(user=self.user1, key=propkey1, value=propval1)

        resp = self.get('/users/%s/props/' % username1)
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertDictEqual(self.parse(resp, 'dict'), {propkey1: propval1, })

        resp = self.get('/users/%s/props/' % username2)
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertDictEqual(self.parse(resp, 'dict'), {})
コード例 #7
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_get_property(self):
        property_backend.create(user=self.user1, key=propkey1, value=propval1)

        resp = self.get('/users/%s/props/%s/' % (username1, propkey1))
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertEqual(self.parse(resp, 'str'), propval1)

        # check that user2 doesn't have it:
        resp = self.get('/users/%s/props/%s/' % (username2, propkey1))
        self.assertEqual(resp.status_code, http_client.NOT_FOUND)
        self.assertEqual(resp['Resource-Type'], 'property')
コード例 #8
0
ファイル: tests.py プロジェクト: lokpratap/bus-booking-api
    def test_get_multiple_properties(self):
        property_backend.create(user=self.user1, key=propkey1, value=propval1)
        property_backend.create(user=self.user1, key=propkey2, value=propval2)
        property_backend.create(user=self.user2, key=propkey3, value=propval3)

        resp = self.get('/users/%s/props/' % username1)
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertDictEqual(self.parse(resp, 'dict'), {propkey1: propval1, propkey2: propval2, })

        resp = self.get('/users/%s/props/' % username2)
        self.assertEqual(resp.status_code, http_client.OK)
        self.assertDictEqual(self.parse(resp, 'dict'), {propkey3: propval3, })