def _check(node_data, signal_d, hash_value, data):
            """Check the upload was ok."""
            mdid, node_id = node_data

            # download it
            buf = NoCloseStringIO()
            self.patch(self.main.fs, 'get_partial_for_writing',
                       lambda s, n: buf)
            yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
            yield self.wait_for_nirvana()
            self.assertEqual(buf.getvalue(), data)

            # it's ok, we're happy
            signal_d.callback(None)
        def _check(node_data, signal_d, hash_value, data):
            """Check the upload was ok."""
            mdid, node_id = node_data

            # download it
            buf = NoCloseStringIO()
            self.patch(self.main.fs, 'get_partial_for_writing',
                       lambda s, n: buf)
            yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
            yield self.wait_for_nirvana()
            self.assertEqual(buf.getvalue(), data)

            # it's ok, we're happy
            signal_d.callback(None)
    def test_upload(self):
        """Test we can upload stuff."""
        buf = NoCloseStringIO()
        self.patch(self.main.fs, 'get_partial_for_writing', lambda s, n: buf)

        hash_value, _, data, d = self._mk_file_w_content()
        mdid, node_id = yield d
        yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
        yield self.wait_for_nirvana()
        self.assertEqual(buf.getvalue(), data)

        self.assertEvent(('AQ_UPLOAD_FINISHED', {'share_id': request.ROOT,
                                                 'node_id': node_id,
                                                 'hash': hash_value,
                                                 'new_generation': 2L}))
    def test_upload(self):
        """Test we can upload stuff."""
        buf = NoCloseStringIO()
        self.patch(self.main.fs, 'get_partial_for_writing', lambda s, n: buf)

        hash_value, _, data, d = self._mk_file_w_content()
        mdid, node_id = yield d
        yield self.aq.download(request.ROOT, node_id, hash_value, mdid)
        yield self.wait_for_nirvana()
        self.assertEqual(buf.getvalue(), data)

        self.assertEvent(('AQ_UPLOAD_FINISHED', {
            'share_id': request.ROOT,
            'node_id': node_id,
            'hash': hash_value,
            'new_generation': 2L
        }))