예제 #1
0
    def test_update_meta(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_groups):
            initial = self.get_account_meta()

            meta = {'Test': 'tost', 'Ping': 'pong'}
            kwargs = dict(('HTTP_X_ACCOUNT_META_%s' % k, str(v))
                          for k, v in meta.items())
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 202)

            meta.update(initial)
            account_meta = self.get_account_meta()
            self.assertEqual(account_meta, meta)

            # test metadata limit
            limit = pithos_settings.RESOURCE_MAX_METADATA
            kwargs = dict(('HTTP_X_ACCOUNT_META_%s' % i, str(i))
                          for i in range(limit - len(meta) + 1))
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 400)

            meta.update(initial)
            account_meta = self.get_account_meta()
            self.assertEqual(account_meta, meta)
예제 #2
0
    def test_reset_account_groups(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_meta):
            groups = {
                'pithosdev': ['verigak', 'gtsouk', 'chazapis'],
                'clientsdev': ['pkanavos', 'mvasilak']
            }
            headers = dict(('HTTP_X_ACCOUNT_GROUP_%s' % k, ','.join(v))
                           for k, v in groups.iteritems())
            r = self.post('%s?update=' % url, **headers)
            self.assertEqual(r.status_code, 202)

            groups = {
                'pithosdev': ['verigak', 'gtsouk', 'chazapis', 'papagian']
            }
            headers = dict(('HTTP_X_ACCOUNT_GROUP_%s' % k, ','.join(v))
                           for k, v in groups.iteritems())
            account_meta = self.get_account_meta()
            headers.update(
                dict(
                    ('HTTP_X_ACCOUNT_META_%s' % k.upper().replace('-', '_'), v)
                    for k, v in account_meta.iteritems()))
            r = self.post(url, **headers)
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in account_groups)
            self.assertTrue('Clientsdev' not in account_groups)
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(groups['pithosdev'])))
예제 #3
0
    def test_set_account_groups(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_meta):
            limit = pithos_settings.ACC_MAX_GROUPS
            # too many groups
            kwargs = dict(('HTTP_X_ACCOUNT_GROUP_%s' % i, unicode(i))
                          for i in range(limit + 1))
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 400)

            pithosdevs = ['chazapis'] * 2
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_PITHOSDEV=','.join(pithosdevs))
            self.assertEqual(r.status_code, 202)
            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in self.get_account_groups())
            self.assertEqual(account_groups['Pithosdev'], 'chazapis')

            pithosdevs = ['verigak', 'gtsouk', 'chazapis']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_PITHOSDEV=','.join(pithosdevs))
            self.assertEqual(r.status_code, 202)
            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in self.get_account_groups())
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))

            clientdevs = ['pkanavos', 'mvasilak']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_CLIENTSDEV=','.join(clientdevs))
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in account_groups)
            self.assertTrue('Clientsdev' in account_groups)
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))
            self.assertEqual(account_groups['Clientsdev'],
                             ','.join(sorted(clientdevs)))

            clientdevs = ['mvasilak']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_CLIENTSDEV=''.join(clientdevs))
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in account_groups)
            self.assertTrue('Clientsdev' in account_groups)
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))
            self.assertEqual(account_groups['Clientsdev'],
                             ','.join(sorted(clientdevs)))

            long_list = [unicode(i) for i in xrange(33)]
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_TEST=','.join(long_list))
            self.assertEqual(r.status_code, 400)
예제 #4
0
    def test_delete_meta(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_groups):
            meta = {'test': 'tost', 'ping': 'pong'}
            self.update_account_meta(meta)

            kwargs = dict(
                ('HTTP_X_ACCOUNT_META_%s' % k, '') for k, v in meta.items())
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 202)

            account_meta = self.get_account_meta()

            (self.assertTrue(k not in account_meta) for k in meta.keys())
예제 #5
0
    def test_update_meta(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_groups):
            initial = self.get_account_meta()

            meta = {'test': 'tost', 'ping': 'pong'}
            kwargs = dict(('HTTP_X_ACCOUNT_META_%s' % k, str(v))
                          for k, v in meta.items())
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 202)

            meta.update(initial)
            account_meta = self.get_account_meta()
            (self.assertTrue(k in account_meta) for k in meta.keys())
            (self.assertEqual(account_meta[k], v) for k, v in meta.items())
예제 #6
0
    def test_delete_account_groups(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_meta):
            groups = {
                'pithosdev': ['verigak', 'gtsouk', 'chazapis'],
                'clientsdev': ['pkanavos', 'mvasilak']
            }
            headers = dict(('HTTP_X_ACCOUNT_GROUP_%s' % k, ','.join(v))
                           for k, v in groups.iteritems())
            self.post('%s?update=' % url, **headers)

            kwargs = dict(
                ('HTTP_X_ACCOUNT_GROUP_%s' % k, '') for k, v in groups.items())
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' not in account_groups)
            self.assertTrue('Clientsdev' not in account_groups)
예제 #7
0
    def test_set_account_groups(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_meta):
            pithosdevs = ['verigak', 'gtsouk', 'chazapis']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_PITHOSDEV=','.join(pithosdevs))
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in self.get_account_groups())
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))

            clientdevs = ['pkanavos', 'mvasilak']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_CLIENTSDEV=','.join(clientdevs))
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in account_groups)
            self.assertTrue('Clientsdev' in account_groups)
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))
            self.assertEqual(account_groups['Clientsdev'],
                             ','.join(sorted(clientdevs)))

            clientdevs = ['mvasilak']
            r = self.post('%s?update=' % url,
                          HTTP_X_ACCOUNT_GROUP_CLIENTSDEV=''.join(clientdevs))
            self.assertEqual(r.status_code, 202)

            account_groups = self.get_account_groups()
            self.assertTrue('Pithosdev' in account_groups)
            self.assertTrue('Clientsdev' in account_groups)
            self.assertEqual(account_groups['Pithosdev'],
                             ','.join(sorted(pithosdevs)))
            self.assertEqual(account_groups['Clientsdev'],
                             ','.join(sorted(clientdevs)))
예제 #8
0
    def test_reset_meta(self):
        url = join_urls(self.pithos_path, self.user)
        with AssertMappingInvariant(self.get_account_groups):
            meta = {'test': 'tost', 'ping': 'pong'}
            self.update_account_meta(meta)

            new_meta = {'test': 'test33'}
            kwargs = dict(('HTTP_X_ACCOUNT_META_%s' % k, str(v))
                          for k, v in new_meta.items())
            r = self.post(url, **kwargs)
            self.assertEqual(r.status_code, 202)

            account_meta = self.get_account_meta()
            (self.assertTrue(k in account_meta) for k in new_meta.keys())
            (self.assertEqual(account_meta[k], v) for k, v in new_meta.items())

            (self.assertTrue(k not in account_meta) for k in meta.keys())

            # test metadata limit
            limit = pithos_settings.RESOURCE_MAX_METADATA
            kwargs = dict(('HTTP_X_ACCOUNT_META_%s' % i, str(i))
                          for i in range(limit + 1))
            r = self.post('%s?update=' % url, **kwargs)
            self.assertEqual(r.status_code, 400)