Exemplo n.º 1
0
 def testGetUserIgnoresCase(self):
     """L{FacadeUserMixin.getUser} ignores case for the username."""
     UserAPI().create([(u'user', u'secret', u'User', u'*****@*****.**')])
     self.store.commit()
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         result = yield self.facade.getUser(session, u'uSeR')
         self.assertEqual(u'user', result.username)
Exemplo n.º 2
0
    def testGetObjectAllPathsAreDenied(self):
        """
        L{FacadeObjectAPI.getObject} returns a L{TObjectInfo} with the
        L{Tag.path}s for which the L{User} has L{Operation.READ_TAG_VALUE}, if
        all of them are denied, L{FacadeObjectAPI.getObject} must return an
        empty L{TObjectInfo}.
        """
        SecureTagAPI(self.user).create([(u'username/tag1', u'description'),
                                        (u'username/tag2', u'description')])
        objectID = uuid4()
        values = {
            objectID: {
                u'username/tag1': 16
            },
            objectID: {
                u'username/tag2': 16
            }
        }
        SecureTagValueAPI(self.user).set(values)
        self.permissions.set([
            (u'username/tag1', Operation.READ_TAG_VALUE, Policy.CLOSED, []),
            (u'username/tag2', Operation.READ_TAG_VALUE, Policy.CLOSED, [])
        ])
        self.store.commit()

        with login(self.user.username, uuid4(), self.transact) as session:
            objectInfo = yield self.facade.getObject(session, str(objectID))
            self.assertEqual([], objectInfo.tagPaths)
            self.assertEqual(None, objectInfo.about)
Exemplo n.º 3
0
    def testRenderWithUnknownConsumer(self):
        """
        A C{BAD_REQUEST} HTTP status code is returned if an
        L{OAuthRenewalToken} for an unknown L{OAuthConsumer} is used in a
        renewal request.
        """
        UserAPI().create(
            [(u'consumer', 'secret', u'Consumer', u'*****@*****.**'),
             (u'user', 'secret', u'User', u'*****@*****.**')])
        consumer = getUser(u'consumer')
        user = getUser(u'consumer')
        api = OAuthConsumerAPI()
        api.register(consumer)
        token = api.getRenewalToken(consumer, user)
        headers = {'X-FluidDB-Renewal-Token': [token.encrypt()]}
        self.store.find(OAuthConsumer).remove()
        self.store.commit()

        request = FakeRequest(headers=Headers(headers))
        with login(u'consumer', consumer.objectID, self.transact) as session:
            resource = RenewOAuthTokenResource(session)
            self.assertEqual(NOT_DONE_YET, resource.render_GET(request))
            yield resource.deferred
            headers = dict(request.responseHeaders.getAllRawHeaders())
            self.assertEqual(
                {'X-Fluiddb-Error-Class': ['UnknownConsumer'],
                 'X-Fluiddb-Username': ['consumer'],
                 'X-Fluiddb-Request-Id': [session.id]},
                headers)
            self.assertEqual(BAD_REQUEST, request.code)
Exemplo n.º 4
0
 def testRenderRecentUsersActivity(self):
     """
     L{RecentUsersActivityResource.deferred_render_GET} renders a response
     with recent activity data by the users returned by the given query.
     """
     objectID = ObjectAPI(self.user).create(u'object1')
     self.store.commit()
     TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}})
     runDataImportHandler(self.client.url)
     request = FakeRequest(
         args={'query': ['fluiddb/users/username = "******"']})
     with login(u'username', self.user.objectID, self.transact) as session:
         resource = RecentUsersActivityResource(self.facade, session)
         body = yield resource.deferred_render_GET(request)
         body = json.loads(body)
         expected = [{
             u'about': u'object1',
             u'id': str(objectID),
             u'tag': u'username/tag1',
             u'username': u'username',
             u'value': u'A'
         }]
         # Clean up timestamps.
         for item in body:
             del item['updated-at']
         self.assertEqual(expected, body)
         self.assertEqual(http.OK, request.code)
Exemplo n.º 5
0
 def testRenderRecentUserActivity(self):
     """
     L{RecentUserActivityResource.deferred_render_GET} renders a response
     with recent activity data for the given user.
     """
     objectID = ObjectAPI(self.user).create(u'object1')
     TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}})
     self.store.commit()
     TagValueAPI(self.user).set({objectID: {u'username/tag2': u'B'}})
     self.store.commit()
     request = FakeRequest()
     with login(u'username', self.user.objectID, self.transact) as session:
         resource = RecentUserActivityResource(self.facade, session,
                                               u'username')
         body = yield resource.deferred_render_GET(request)
         body = json.loads(body)
         expected = [{
             u'username': u'username',
             u'about': u'object1',
             u'id': str(objectID),
             u'tag': u'username/tag2',
             u'value': u'B'
         }, {
             u'username': u'username',
             u'about': u'object1',
             u'id': str(objectID),
             u'tag': u'username/tag1',
             u'value': u'A'
         }]
         # Clean up timestamps.
         for item in body:
             del item['updated-at']
         self.assertEqual(expected, body)
         self.assertEqual(http.OK, request.code)
Exemplo n.º 6
0
 def testRenderRecentUsersActivity(self):
     """
     L{RecentUsersActivityResource.deferred_render_GET} renders a response
     with recent activity data by the users returned by the given query.
     """
     objectID = ObjectAPI(self.user).create(u'object1')
     self.store.commit()
     TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}})
     runDataImportHandler(self.client.url)
     request = FakeRequest(
         args={'query': ['fluiddb/users/username = "******"']})
     with login(u'username', self.user.objectID, self.transact) as session:
         resource = RecentUsersActivityResource(self.facade, session)
         body = yield resource.deferred_render_GET(request)
         body = json.loads(body)
         expected = [{u'about': u'object1',
                      u'id': str(objectID),
                      u'tag': u'username/tag1',
                      u'username': u'username',
                      u'value': u'A'}]
         # Clean up timestamps.
         for item in body:
             del item['updated-at']
         self.assertEqual(expected, body)
         self.assertEqual(http.OK, request.code)
Exemplo n.º 7
0
    def testRenderWithUserConflict(self):
        """
        A C{CONFLICT} HTTP status code is returned if the authorization is
        successfully verified by the service provider, but the username
        clashes with an existing L{User} that isn't linked to the Twitter UID.
        The offending username is returned UTF-8 and base64 encoded.
        """
        username = u'john\N{HIRAGANA LETTER A}'
        UserAPI().create([(username, 'secret', u'John', u'*****@*****.**')])
        self.store.commit()

        self.agent._connect = self._connect
        headers = {'X-Verify-Credentials-Authorization': ['OAuth ...'],
                   'X-Auth-Service-Provider': [TWITTER_URL]}
        request = FakeRequest(headers=Headers(headers))
        with login(u'anon', self.anonymous.objectID, self.transact) as session:
            resource = OAuthEchoResource(session, self.agent)
            self.assertEqual(NOT_DONE_YET, resource.render_GET(request))

            [(_, responseDeferred)] = self.protocol.requests
            data = {'id': 1984245, 'screen_name': username, 'name': u'John'}
            response = FakeResponse(ResponseDone(), dumps(data))
            responseDeferred.callback(response)
            yield resource.deferred
            self.assertEqual(CONFLICT, request.code)
            headers = dict(request.responseHeaders.getAllRawHeaders())
            encodedUsername = b64encode(username.encode('utf-8'))
            self.assertEqual(
                {'X-Fluiddb-Error-Class': ['UsernameConflict'],
                 'X-Fluiddb-Username': [encodedUsername],
                 'X-Fluiddb-Request-Id': [session.id]},
                headers)
Exemplo n.º 8
0
    def testRenderWithUserConflict(self):
        """
        A C{CONFLICT} HTTP status code is returned if the authorization is
        successfully verified by the service provider, but the username
        clashes with an existing L{User} that isn't linked to the Twitter UID.
        The offending username is returned UTF-8 and base64 encoded.
        """
        username = u'john\N{HIRAGANA LETTER A}'
        UserAPI().create([(username, 'secret', u'John', u'*****@*****.**')])
        self.store.commit()

        self.agent._connect = self._connect
        headers = {
            'X-Verify-Credentials-Authorization': ['OAuth ...'],
            'X-Auth-Service-Provider': [TWITTER_URL]
        }
        request = FakeRequest(headers=Headers(headers))
        with login(u'anon', self.anonymous.objectID, self.transact) as session:
            resource = OAuthEchoResource(session, self.agent)
            self.assertEqual(NOT_DONE_YET, resource.render_GET(request))

            [(_, responseDeferred)] = self.protocol.requests
            data = {'id': 1984245, 'screen_name': username, 'name': u'John'}
            response = FakeResponse(ResponseDone(), dumps(data))
            responseDeferred.callback(response)
            yield resource.deferred
            self.assertEqual(CONFLICT, request.code)
            headers = dict(request.responseHeaders.getAllRawHeaders())
            encodedUsername = b64encode(username.encode('utf-8'))
            self.assertEqual(
                {
                    'X-Fluiddb-Error-Class': ['UsernameConflict'],
                    'X-Fluiddb-Username': [encodedUsername],
                    'X-Fluiddb-Request-Id': [session.id]
                }, headers)
Exemplo n.º 9
0
 def testGetUserIgnoresCase(self):
     """L{FacadeUserMixin.getUser} ignores case for the username."""
     UserAPI().create([(u'user', u'secret', u'User', u'*****@*****.**')])
     self.store.commit()
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         result = yield self.facade.getUser(session, u'uSeR')
         self.assertEqual(u'user', result.username)
Exemplo n.º 10
0
 def testRenderRecentUserActivity(self):
     """
     L{RecentUserActivityResource.deferred_render_GET} renders a response
     with recent activity data for the given user.
     """
     objectID = ObjectAPI(self.user).create(u'object1')
     TagValueAPI(self.user).set({objectID: {u'username/tag1': u'A'}})
     self.store.commit()
     TagValueAPI(self.user).set({objectID: {u'username/tag2': u'B'}})
     self.store.commit()
     request = FakeRequest()
     with login(u'username', self.user.objectID, self.transact) as session:
         resource = RecentUserActivityResource(self.facade, session,
                                               u'username')
         body = yield resource.deferred_render_GET(request)
         body = json.loads(body)
         expected = [{u'username': u'username',
                      u'about': u'object1',
                      u'id': str(objectID),
                      u'tag': u'username/tag2',
                      u'value': u'B'},
                     {u'username': u'username',
                      u'about': u'object1',
                      u'id': str(objectID),
                      u'tag': u'username/tag1',
                      u'value': u'A'}]
         # Clean up timestamps.
         for item in body:
             del item['updated-at']
         self.assertEqual(expected, body)
         self.assertEqual(http.OK, request.code)
Exemplo n.º 11
0
    def testRenderWithSuccessfulVerification(self):
        """
        An C{OK} HTTP status code is returned, along with new access and
        renewal tokens, if a renewal request is successful.
        """
        UserAPI().create(
            [(u'consumer', 'secret', u'Consumer', u'*****@*****.**'),
             (u'user', 'secret', u'User', u'*****@*****.**')])
        consumer = getUser(u'consumer')
        user = getUser(u'consumer')
        api = OAuthConsumerAPI()
        api.register(consumer)
        token = api.getRenewalToken(consumer, user)
        self.store.commit()

        headers = {'X-FluidDB-Renewal-Token': [token.encrypt()]}
        request = FakeRequest(headers=Headers(headers))
        with login(u'consumer', consumer.objectID, self.transact) as session:
            resource = RenewOAuthTokenResource(session)
            self.assertEqual(NOT_DONE_YET, resource.render_GET(request))

            yield resource.deferred
            headers = dict(request.responseHeaders.getAllRawHeaders())
            self.assertTrue(headers['X-Fluiddb-Access-Token'])
            self.assertTrue(headers['X-Fluiddb-Renewal-Token'])
            self.assertEqual(OK, request.code)
Exemplo n.º 12
0
    def testRenderWithExpiredRenewalToken(self):
        """
        An C{UNAUTHORIZED} HTTP status code is returned if an expired
        L{OAuthRenewalToken} is used in a renewal request.
        """
        UserAPI().create(
            [(u'consumer', 'secret', u'Consumer', u'*****@*****.**'),
             (u'user', 'secret', u'User', u'*****@*****.**')])
        consumer = getUser(u'consumer')
        user = getUser(u'consumer')
        api = OAuthConsumerAPI()
        api.register(consumer)
        creationTime = datetime.utcnow() - timedelta(hours=200)
        token = api.getRenewalToken(consumer, user, now=lambda: creationTime)
        self.store.commit()

        headers = {'X-FluidDB-Renewal-Token': [token.encrypt()]}
        request = FakeRequest(headers=Headers(headers))
        with login(u'consumer', consumer.objectID, self.transact) as session:
            resource = RenewOAuthTokenResource(session)
            self.assertEqual(NOT_DONE_YET, resource.render_GET(request))
            yield resource.deferred
            headers = dict(request.responseHeaders.getAllRawHeaders())
            self.assertEqual(
                {'X-Fluiddb-Error-Class': ['ExpiredOAuth2RenewalToken'],
                 'X-Fluiddb-Username': ['consumer'],
                 'X-Fluiddb-Request-Id': [session.id]},
                headers)
            self.assertEqual(UNAUTHORIZED, request.code)
Exemplo n.º 13
0
 def testGetRecentUserActivityForQueryWithBadQuery(self):
     """
     L{FacadeRecentActivityMixin.getRecentUserActivityForQuery} raises
     L{TParseError} if the given query can't be parsed.
     """
     with login(self.user.username, uuid4(), self.transact) as session:
         result = self.facade.getRecentUserActivityForQuery(session, 'bad')
         yield self.assertFailure(result, TParseError)
Exemplo n.º 14
0
 def testGetRecentUserActivityWithUnkownUser(self):
     """
     L{FacadeRecentActivityMixin.getRecentUserActivity} raises
     L{TNoSuchUser} if the given user doesn't exist.
     """
     with login(self.user.username, uuid4(), self.transact) as session:
         result = self.facade.getRecentUserActivity(session, 'unknown')
         yield self.assertFailure(result, TNoSuchUser)
Exemplo n.º 15
0
 def testGetWithInvalidCategory(self):
     """
     L{FacadePermissionMixin.getPermission} raises a L{TBadRequest} error if
     the given C{category} is invalid.
     """
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.getPermission(session, u'invalid',
                                              u'create', u'username')
         yield self.assertFailure(deferred, TBadRequest)
Exemplo n.º 16
0
 def testGetWithUnknownTag(self):
     """
     L{FacadePermissionMixin.getPermission} raises a L{TNonexistentTag}
     error if the given L{Tag} path does not exist.
     """
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.getPermission(
             session, u'tags', u'update', u'username/unknown')
         yield self.assertFailure(deferred, TNonexistentTag)
Exemplo n.º 17
0
 def testGetRecentUserActivityForQueryWithIllegalQuery(self):
     """
     L{FacadeRecentActivityMixin.getRecentUserActivityForQuery} raises
     L{TBadRequest} if the given query contains illegal sub queries.
     """
     with login(self.user.username, uuid4(), self.transact) as session:
         result = self.facade.getRecentUserActivityForQuery(
             session, 'has fluiddb/about')
         yield self.assertFailure(result, TBadRequest)
Exemplo n.º 18
0
 def testGetRecentAboutActivityWithUnkownAboutValue(self):
     """
     L{FacadeRecentActivityMixin.getRecentAboutActivity} returns an empty
     C{list} if the about value doesn't exist.
     """
     with login(self.user.username, uuid4(), self.transact) as session:
         result = yield self.facade.getRecentAboutActivity(session,
                                                           'unknown')
         self.assertEqual([], result)
Exemplo n.º 19
0
 def testGetTagWithoutData(self):
     """
     L{FacadeTagMixin.getTag} raises a L{TNonexistentTag} exception if the
     requested L{Tag.path} doesn't exist.
     """
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.getTag(session, u'username/unknown', False)
         yield self.assertFailure(deferred, TNonexistentTag)
Exemplo n.º 20
0
    def testDeleteTag(self):
        """L{FacadeTagMixin.deleteTag} deletes a L{Tag}."""
        tags = TagAPI(self.user)
        tags.create([(u'username/name', u'A tag.')])
        self.store.commit()
        with login(u'username', uuid4(), self.transact) as session:
            yield self.facade.deleteTag(session, u'username/name')

        self.store.rollback()
        self.assertEqual({}, tags.get([u'username/name']))
Exemplo n.º 21
0
 def testUpdateUserWithBadRole(self):
     """
     If an invalid L{User.role} is passed to L{FacadeUserMixin.updateUser}
     a L{TBadRequest} exception is raised.
     """
     info = TUserUpdate(u'user', u's3cr3t', u'new-name', '*****@*****.**',
                        'BAD_ROLE')
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         deferred = self.facade.updateUser(session, info)
         yield self.assertFailure(deferred, TBadRequest)
Exemplo n.º 22
0
 def testCreateTagWithUnknownParent(self):
     """
     L{FacadeTagMixin.createTag} raises a L{TNonexistentTag} exception if a
     non-existent parent L{Tag} is specified.
     """
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.createTag(
             session, u'unknown', u'name', u'A tag.', 'ignored', 'ignored')
         yield self.assertFailure(deferred, TNonexistentTag)
Exemplo n.º 23
0
 def testUpdateTagWithUnknownPath(self):
     """
     L{FacadeTagMixin.updateTag} raises a L{TNonexistentTag} exception if
     the requested L{Tag.path} doesn't exist.
     """
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.updateTag(session, u'username/unknown',
                                          u'A new description.')
         yield self.assertFailure(deferred, TNonexistentTag)
Exemplo n.º 24
0
    def testCreateObjectWithoutAboutValue(self):
        """
        L{FacadeObjectAPI.createObject} always returns a valid C{UUID} in a
        C{str} for a new object ID if an about value is not given.
        """
        self.store.commit()

        with login(u'username', uuid4(), self.transact) as session:
            objectID = yield self.facade.createObject(session)
            self.assertEqual(objectID, str(UUID(objectID)))
Exemplo n.º 25
0
 def testCreateTagWithInvalidPath(self):
     """
     L{FacadeTagMixin.createTag} raises a L{TInvalidPath} exception if the
     path of the L{Tag} is not well formed.
     """
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.createTag(session, u'username', u'bad name',
                                          u'A tag.', 'ignored', 'ignored')
         yield self.assertFailure(deferred, TInvalidPath)
Exemplo n.º 26
0
 def testGetUserWithoutData(self):
     """
     L{FacadeUserMixin.getUser} raises a L{TNoSuchUser} exception if the
     requested L{User.username} doesn't exist.
     """
     self.store.commit()
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         deferred = self.facade.getUser(session, u'unknown')
         error = yield self.assertFailure(deferred, TNoSuchUser)
         self.assertEqual(u'unknown', error.name)
Exemplo n.º 27
0
    def testCreateObjectPermissionDenied(self):
        """
        L{FacadeObjectMixin.createObject} raises a
        L{TUnauthorized} exception if the user is the anonymous user.
        """
        self.store.commit()

        with login(u'anon', uuid4(), self.transact) as session:
            deferred = self.facade.createObject(session)
            yield self.assertFailure(deferred, TUnauthorized)
Exemplo n.º 28
0
    def testCreateObjectWithoutAboutValue(self):
        """
        L{FacadeObjectAPI.createObject} always returns a valid C{UUID} in a
        C{str} for a new object ID if an about value is not given.
        """
        self.store.commit()

        with login(u'username', uuid4(), self.transact) as session:
            objectID = yield self.facade.createObject(session)
            self.assertEqual(objectID, str(UUID(objectID)))
Exemplo n.º 29
0
    def testCreateObjectPermissionDenied(self):
        """
        L{FacadeObjectMixin.createObject} raises a
        L{TUnauthorized} exception if the user is the anonymous user.
        """
        self.store.commit()

        with login(u'anon', uuid4(), self.transact) as session:
            deferred = self.facade.createObject(session)
            yield self.assertFailure(deferred, TUnauthorized)
Exemplo n.º 30
0
 def testGetWithUnknownNamespace(self):
     """
     L{FacadePermissionMixin.getPermission} raises a
     L{TNonexistentNamespace} error if the given L{Namespace} path does not
     exist.
     """
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.getPermission(session, u'namespaces',
                                              u'create', u'unknown')
         yield self.assertFailure(deferred, TNonexistentNamespace)
Exemplo n.º 31
0
    def testDeleteUser(self):
        """L{FacadeUserMixin.deleteUser} deletes a L{User}."""
        UserAPI().create([(u'test', u'secret', u'name', u'*****@*****.**')],
                         createPrivateNamespace=False)
        self.store.commit()
        with login(u'fluiddb', self.admin.objectID, self.transact) as session:
            yield self.facade.deleteUser(session, u'test')

        self.store.rollback()
        self.assertIdentical(None, getUser(u'test'))
Exemplo n.º 32
0
 def testGetTagWithDescription(self):
     """
     L{FacadeTagMixin.getTag} includes the L{Tag.description}, if it was
     requested.
     """
     TagAPI(self.user).create([(u'username/tag', u'A tag.')])
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         result = yield self.facade.getTag(session, u'username/tag', True)
         self.assertEqual(u'A tag.', result.description)
Exemplo n.º 33
0
    def testDeleteUser(self):
        """L{FacadeUserMixin.deleteUser} deletes a L{User}."""
        UserAPI().create([(u'test', u'secret', u'name', u'*****@*****.**')],
                         createPrivateNamespace=False)
        self.store.commit()
        with login(u'fluiddb', self.admin.objectID, self.transact) as session:
            yield self.facade.deleteUser(session, u'test')

        self.store.rollback()
        self.assertIdentical(None, getUser(u'test'))
Exemplo n.º 34
0
 def testGetUserWithoutData(self):
     """
     L{FacadeUserMixin.getUser} raises a L{TNoSuchUser} exception if the
     requested L{User.username} doesn't exist.
     """
     self.store.commit()
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         deferred = self.facade.getUser(session, u'unknown')
         error = yield self.assertFailure(deferred, TNoSuchUser)
         self.assertEqual(u'unknown', error.name)
Exemplo n.º 35
0
 def testUpdateUserWithBadRole(self):
     """
     If an invalid L{User.role} is passed to L{FacadeUserMixin.updateUser}
     a L{TBadRequest} exception is raised.
     """
     info = TUserUpdate(u'user', u's3cr3t', u'new-name', '*****@*****.**',
                        'BAD_ROLE')
     with login(u'fluiddb', self.admin.objectID, self.transact) as session:
         deferred = self.facade.updateUser(session, info)
         yield self.assertFailure(deferred, TBadRequest)
Exemplo n.º 36
0
    def testDeleteNamespace(self):
        """L{Facade.deleteNamespace} deletes a L{Namespace}."""
        namespaces = NamespaceAPI(self.user)
        namespaces.create([(u'username/name', u'A namespace.')])
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            yield self.facade.deleteNamespace(session, u'username/name')

        self.store.rollback()
        self.assertEqual({}, namespaces.get([u'username/name']))
Exemplo n.º 37
0
    def testGetNamespaceWithoutData(self):
        """
        L{Facade.getNamespace} raises a L{TNonexistentNamespace} exception if
        the requested L{Namespace.path} doesn't exist.
        """
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.getNamespace(session, u'username/unknown',
                                                False, False, False)
            yield self.assertFailure(deferred, TNonexistentNamespace)
Exemplo n.º 38
0
    def testCreateNamespaceWithInvalidPath(self):
        """
        L{Facade.createNamespace} raises a L{TInvalidPath} exception
        if the path of the L{Namespace} is not well formed.
        """
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.createNamespace(session, u'username',
                                                   u'bad name', u'description')
            yield self.assertFailure(deferred, TInvalidPath)
Exemplo n.º 39
0
    def testUpdateNamespaceWithUnknownPath(self):
        """
        L{Facade.updateNamespace} raises a L{TNonexistentNamespace} exception
        if the requested L{Namespace.path} doesn't exist.
        """
        self.store.commit()

        with login(u'username', self.user.objectID, self.transact) as session:
            deferred = self.facade.updateNamespace(
                session, u'username/unknown', u'A new description.')
            yield self.assertFailure(deferred, TNonexistentNamespace)
Exemplo n.º 40
0
 def testGetNamespaceWithUnknownPath(self):
     """
     L{Facade.getNamespace} raises a L{TNonexistentNamespace} exception
     if the specified L{Namespace} doesn't exist.
     """
     with login(u'username', self.user.objectID, self.transact) as session:
         deferred = self.facade.getNamespace(session, u'unknown',
                                             returnDescription=False,
                                             returnNamespaces=False,
                                             returnTags=False)
         yield self.assertFailure(deferred, TNonexistentNamespace)
Exemplo n.º 41
0
 def testSetWithInvalidPolicy(self):
     """
     L{FacadePermissionMixin.updatePermission} raises a L{TInvalidPolicy}
     error if the given C{policy} is invalid.
     """
     policyAndExceptions = TPolicyAndExceptions(u'invalid', [])
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.updatePermission(session, u'namespaces',
                                                 u'create', u'username',
                                                 policyAndExceptions)
         yield self.assertFailure(deferred, TInvalidPolicy)
Exemplo n.º 42
0
 def testSetWithUnknownTag(self):
     """
     L{FacadePermissionMixin.updatePermission} raises a L{TNonexistentTag}
     error if the given L{Tag} path does not exist.
     """
     policyAndExceptions = TPolicyAndExceptions(u'closed', [])
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.updatePermission(
             session, u'tags', u'update', u'username/unknown',
             policyAndExceptions)
         yield self.assertFailure(deferred, TNonexistentTag)
Exemplo n.º 43
0
 def testSetWithSuperuser(self):
     """
     L{FacadePermissionMixin.updatePermission} raises a L{TInvalidUsername}
     error if a superuser is specified in the exceptions list.
     """
     policyAndExceptions = TPolicyAndExceptions(u'closed', [u'fluiddb'])
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.updatePermission(
             session, u'tags', u'update', u'username/tag',
             policyAndExceptions)
         yield self.assertFailure(deferred, TInvalidUsername)
Exemplo n.º 44
0
 def testCreateTagWithExistingPath(self):
     """
     L{FacadeTagMixin.createTag} raises a L{TTagAlreadyExists} exception if
     the new L{Tag} already exists.
     """
     TagAPI(self.user).create([(u'username/name', u'A tag.')])
     self.store.commit()
     with login(u'username', uuid4(), self.transact) as session:
         deferred = self.facade.createTag(
             session, u'username', u'name', u'A tag.', 'ignored', 'ignored')
         yield self.assertFailure(deferred, TTagAlreadyExists)