Esempio n. 1
0
 def testGetChildEmptyStringReturnsSelf(self):
     """
     If the next component in the URI is empty, the resource should
     consume it (i.e., return itself).
     """
     resource = AboutObjectResource(None, None, None)
     child = resource.getChild('', None)
     self.assertTrue(resource is child)
Esempio n. 2
0
 def testGetChildEmptyStringReturnsSelf(self):
     """
     If the next component in the URI is empty, the resource should
     consume it (i.e., return itself).
     """
     resource = AboutObjectResource(None, None, None)
     child = resource.getChild('', None)
     self.assertTrue(resource is child)
Esempio n. 3
0
 def testGetAboutTagInstanceResource(self):
     """
     Check that when getChild is passed a name (ntoll) and the request
     has additional components (a tag path) that we receive a child
     object that has the right about value and path.
     """
     about = 'barcelona'
     resource = AboutObjectResource(None, None, about)
     request = FakeRequest('GET')
     request.postpath = ['books', 'rating']
     child = resource.getChild('ntoll', request)
     self.assertEqual(child.about, about)
     self.assertEqual(child.path, 'ntoll/books/rating')
Esempio n. 4
0
 def testGetAboutTagInstanceResource(self):
     """
     Check that when getChild is passed a name (ntoll) and the request
     has additional components (a tag path) that we receive a child
     object that has the right about value and path.
     """
     about = 'barcelona'
     resource = AboutObjectResource(None, None, about)
     request = FakeRequest('GET')
     request.postpath = ['books', 'rating']
     child = resource.getChild('ntoll', request)
     self.assertEqual(child.about, about)
     self.assertEqual(child.path, 'ntoll/books/rating')
Esempio n. 5
0
 def testGETNonExistentObjectAboutParis(self):
     """
     Set up a fake query resolver that will give no results for
     fluiddb/about = \"paris\" and then make sure that doing a GET on
     /about/paris results in a NOT_FOUND status.
     """
     about = 'paris'
     fakeQueryResolver = FakeQueryResolver(about, [], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     yield d
     self.assertEqual(request.status, http.NOT_FOUND)
Esempio n. 6
0
 def testGETNonExistentObjectAboutParis(self):
     """
     Set up a fake query resolver that will give no results for
     fluiddb/about = \"paris\" and then make sure that doing a GET on
     /about/paris results in a NOT_FOUND status.
     """
     about = 'paris'
     fakeQueryResolver = FakeQueryResolver(about, [], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     yield d
     self.assertEqual(request.status, http.NOT_FOUND)
Esempio n. 7
0
 def testGETAboutWithDoubleQuotes(self):
     '''
     Test that a GET to /about/chicken%20"soup"%20taste results in an OK
     status and that we get back the id of the object that already
     existed (as will be supplied by the fake query resolver).
     '''
     about = 'chicken "soup" taste'
     aboutQuoted = r'chicken \"soup\" taste'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(aboutQuoted, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     yield d
     self.assertEqual(request.status, http.OK)
Esempio n. 8
0
 def testPOSTObjectAboutChickenSoup(self):
     """
     Test that a POST to /about/chicken%20soup results in a CREATED
     status and that we get back the id of the object that already
     existed (as will be supplied by the fake query resolver).
     """
     about = 'chicken soup'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(about, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('POST', d)
     request.content = StringIO.StringIO()
     resource.render(request)
     body = yield d
     self.assertEqual(request.status, http.CREATED)
     responseDict = json.loads(body)
     self.assertEqual(responseDict['id'], objectId)
Esempio n. 9
0
 def testGETAboutWithDoubleQuotes(self):
     '''
     Test that a GET to /about/chicken%20"soup"%20taste results in an OK
     status and that we get back the id of the object that already
     existed (as will be supplied by the fake query resolver).
     '''
     about = 'chicken "soup" taste'
     aboutQuoted = r'chicken \"soup\" taste'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(aboutQuoted, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     yield d
     self.assertEqual(request.status, http.OK)
Esempio n. 10
0
 def testPOSTObjectAboutChickenSoup(self):
     """
     Test that a POST to /about/chicken%20soup results in a CREATED
     status and that we get back the id of the object that already
     existed (as will be supplied by the fake query resolver).
     """
     about = 'chicken soup'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(about, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('POST', d)
     request.content = StringIO.StringIO()
     resource.render(request)
     body = yield d
     self.assertEqual(request.status, http.CREATED)
     responseDict = json.loads(body)
     self.assertEqual(responseDict['id'], objectId)
Esempio n. 11
0
 def testGETObjectAboutBarcelona(self):
     """
     Test that a GET of /about/barcelona results in an OK status and
     that we get back the id of the object that already existed (as will
     be supplied by the fake query resolver), and that it has no tags on
     it.
     """
     about = 'barcelona'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(about, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     body = yield d
     self.assertEqual(request.status, http.OK)
     responseDict = json.loads(body)
     self.assertEqual(responseDict[objects.tagPathsArg], [])
     self.assertEqual(responseDict['id'], objectId)
Esempio n. 12
0
 def testGETObjectAboutBarcelona(self):
     """
     Test that a GET of /about/barcelona results in an OK status and
     that we get back the id of the object that already existed (as will
     be supplied by the fake query resolver), and that it has no tags on
     it.
     """
     about = 'barcelona'
     objectId = util.generateObjectId()
     fakeQueryResolver = FakeQueryResolver(about, [objectId], self)
     facadeClient = FakeFacadeClient(fakeQueryResolver=fakeQueryResolver)
     session = FakeSession()
     resource = AboutObjectResource(facadeClient, session, about)
     d = defer.Deferred()
     request = FakeRequest('GET', d)
     request.args = {objects.showAboutArg: ['False']}
     request.content = StringIO.StringIO()
     resource.render(request)
     body = yield d
     self.assertEqual(request.status, http.OK)
     responseDict = json.loads(body)
     self.assertEqual(responseDict[objects.tagPathsArg], [])
     self.assertEqual(responseDict['id'], objectId)
Esempio n. 13
0
 def testAboutObjectResource(self):
     resource = AboutObjectResource(FakeFacadeClient(),
                                    FakeSession(),
                                    about='foo')
     self._checkCORSPreFlightRequest(resource)
Esempio n. 14
0
 def testAllowedMethods(self):
     """L{AboutObjectResource} allows the correct methods"""
     resource = AboutObjectResource(None, None, None)
     self.assertEqual(('GET', 'OPTIONS', 'POST'), resource.allowedMethods)