Exemple #1
0
def test_get_random_blocks_equal_to_zero(mock_get_dispatcher_instance):
    """
    Test if the function expectedly raises an error of the number of blocks is equal to 0
    """
    with pytest.raises(ValueError) as error:
        get_random_blocks(0)
    mock_get_dispatcher_instance.assert_not_called()
    assert "argument blocks cannot be lower or equal to 0" in error.value
Exemple #2
0
 def run(self):
     while True:
         try:
             self.queue.put(proxy_service.get_random_blocks(self.blocks),
                            block=True,
                            timeout=CacheFiller.DEFAULT_TIMEOUT)
         except Queue.Full:
             # Ignore the exception
             pass
Exemple #3
0
def test_get_random_blocks_returns_a_list_of_length_blocks(
        mock_get_dispatcher_instance):
    """
    Test if the function expectedly returns the appropriate number of blocks
    """
    mock_get_dispatcher_instance.return_value = MockDispatcher()
    result = get_random_blocks(1)
    mock_get_dispatcher_instance.assert_called_once()
    assert isinstance(result, list)
    assert len(result) == 1
Exemple #4
0
 def get_random_blocks(self, blocks):
     """
     Args:
         blocks(int): The number of blocks desired
     Returns:
         list(Strip): Returns a list of ```blocks``` strips from the data stores
     Raises:
         ValueError: if the blocks arguments has a value that is lower or equal to 0
     """
     if blocks <= 0:
         raise ValueError("argument blocks cannot be lower or equal to 0")
     return proxy_service.get_random_blocks(blocks)
Exemple #5
0
 def get_random_blocks(self, blocks):
     """
     Args:
         blocks(int): Number of blocks to fetch
     Returns:
         list(pyproxy.playcloud_pb2.Strip): A list of blocks
     """
     try:
         pointers = self.queue.get_nowait()
         self.logger.info("cache hit")
         return pointers
     except Queue.Empty:
         self.logger.info("cache miss")
         #TODO Should call parent method but keeps failing
         # return super(LocalProxyClient, self).get_random_blocks(blocks)
         return proxy_service.get_random_blocks(blocks)