예제 #1
0
def test_request_push(send_ack, send_request, terminate_transfers,
                      ongoing_transfers, add_to_ongoing):
    """Test trollmoves.client.request_push()."""
    from trollmoves.client import request_push, file_cache
    from tempfile import gettempdir

    # Clear file cache, the other tests have added stuff in it
    file_cache.clear()

    ongoing_transfers[UID_FILE2].pop.return_value = MSG_FILE2
    send_request.return_value = [MSG_FILE2, 'localhost']
    publisher = MagicMock()
    kwargs = {'transfer_req_timeout': 1.0, 'req_timeout': 1.0}

    request_push(MSG_FILE2, gettempdir(), 'login', publisher=publisher,
                 **kwargs)

    send_request.assert_called_once()
    send_ack.assert_not_called()
    # The file should be added to ongoing transfers
    add_to_ongoing.assert_called_once()
    # And removed
    ongoing_transfers[UID_FILE2].pop.assert_called_once()
    # The transferred file should be in the cache
    assert MSG_FILE2.data['uid'] in file_cache
    assert len(file_cache) == 1

    # Request the same file again. Now the transfer should not be
    # started again, and `send_ack()` should be called.
    request_push(MSG_FILE2, gettempdir(), 'login', publisher=publisher,
                 **kwargs)

    send_ack.assert_called_once()
    send_request.assert_called_once()
예제 #2
0
 def push(self, message):
     new_uri = None
     for source_message in file_registry.get(message.data['uid'], []):
         request_push(source_message, publisher=None, **self._attrs)
         destination = urlparse(self._attrs['destination']).path
         new_uri = os.path.join(destination, message.data['uid'])
         if os.path.exists(new_uri):
             break
     if new_uri is None:
         raise KeyError('No source message found for %s',
                        str(message.data['uid']))
     message.data['uri'] = new_uri
     return RequestManager.push(self, message)