示例#1
0
    def test_get_all_peers_returns_peer_in_list(self):

        transfer = server.Transfer('1', '.', '1.1.1.1')
        rootUrl = b'piazza.org'
        mockOb = MagicMock(server.OutboundRequests)
        mockOb.all.return_value = iter([transfer])

        app = server.OutboundRequestEndpoint(outboundRequests=mockOb,
                                             getFileNames=None,
                                             submitFileRequest=None,
                                             rootUrl=rootUrl).app
        kr = KleinResource(app)

        request = requestMock('/', 'GET')
        d = _render(kr, request)

        self.assertFired(d)
        self.assertTrue(mockOb.all.called)

        expected = utils.sortedDump({
            "files": [{
                "url": "piazza.org/1/",
                "transferId": "1",
                "userIp": "1.1.1.1",
                "filepath": "."
            }]
        })
        self.assertEqual(expected, request.getWrittenData())
示例#2
0
    def test_requestTransfer_returns_transfer(self):
        """
        This function finishes up the new request. Test that it returns
        the transfer object it will send to the target user to the sending
        user as well.

        As of right now, this contains the file names and the root url.
        """
        fakeResults = utils.Paths(directories=[b'plop'],
                                  filenames=[b'/plop', b'/plop/foo'])

        def fakeSubmitter(*args):
            return

        app = server.OutboundRequestEndpoint(outboundRequests=None,
                                             getFileNames=None,
                                             submitFileRequest=fakeSubmitter,
                                             rootUrl='')

        transfer = server.Transfer('1', '.', '1.1.1.1')
        response = app.requestTransfer((
            fakeResults,
            transfer,
        ))
        expected = '{"directories": ["plop"], "filenames": ' \
                   '["/plop", "/plop/foo"], "transfer": "/1/"}'

        self.assertEqual(expected, response)
示例#3
0
 def test_add_outbound_adds_new_transfer(self):
     mockOb = MagicMock(server.OutboundRequests)
     app = server.OutboundRequestEndpoint(outboundRequests=mockOb,
                                          getFileNames=None,
                                          submitFileRequest=None,
                                          rootUrl=None)
     app.addOutbound(server.Transfer('1', '.', '1.1.1.1'))
     self.assertTrue(mockOb.add.called)
示例#4
0
 def test_parse_incoming_post_request_without_filepath(self):
     app = server.OutboundRequestEndpoint(outboundRequests=None,
                                          getFileNames=None,
                                          submitFileRequest=None,
                                          rootUrl=None)
     request = utils.sortedDump({"user": "******"})
     body = StringIO(request)
     self.assertRaises(server.MissingFormDataError, app.parse, body)
示例#5
0
 def test_add_outbound_returns_transfer(self):
     mockOb = MagicMock(server.OutboundRequests)
     app = server.OutboundRequestEndpoint(outboundRequests=mockOb,
                                          getFileNames=None,
                                          submitFileRequest=None,
                                          rootUrl=None)
     transfer = server.Transfer('1', '.', '1.1.1.1')
     result = app.addOutbound(transfer)
     self.assertEqual(result, transfer)
示例#6
0
 def test_parse_incoming_post_request_returns_new_transfer(self):
     app = server.OutboundRequestEndpoint(outboundRequests=None,
                                          getFileNames=None,
                                          submitFileRequest=None,
                                          rootUrl=None)
     request = utils.sortedDump({
         "filepath": "/Users/chris/Documents",
         "user": "******"
     })
     body = StringIO(request)
     result = app.parse(body)
     self.assertTrue(result.transferId is not None)
示例#7
0
    def test_get_filenames(self):
        """
        This only tests that given a transfer, getFilenames returns that
        transfer and a set of filenames.
        """
        fakeResults = [b'/plop', b'/plop/foo']

        def fake(*args):
            return fakeResults

        app = server.OutboundRequestEndpoint(outboundRequests=None,
                                             getFileNames=fake,
                                             submitFileRequest=None,
                                             rootUrl=None)
        transfer = server.Transfer('1', '.', '1.1.1.1')
        deferred = app.getFilenames(transfer)

        def check(result):
            self.assertTrue(result[0], fakeResults)
            self.assertTrue(result[1], transfer)

        return deferred
示例#8
0
    def setUp(self):
        self.transfer = server.Transfer('1', '.', '1.1.1.1')
        self.paths = utils.Paths(directories=[], filenames=[b'plop.txt'])
        self.patcher = patch(
            'teiler.server.OutboundRequestEndpoint.getFilenames',
            return_value=(
                self.paths,
                self.transfer,
            ))
        self.patcher.start()

        def fakeSubmitter(*args):
            return

        self.outbound = server.OutboundRequests()
        self.endpoint = server.OutboundRequestEndpoint(
            outboundRequests=self.outbound,
            # getFilenames uses getFileNames. This will be patched; so the
            # method passed in will not be used.
            getFileNames=None,
            submitFileRequest=fakeSubmitter,
            rootUrl='')

        self.kr = KleinResource(self.endpoint.app)