| 1 |
import os |
| 2 |
|
| 3 |
import pytest |
| 4 |
|
| 5 |
from celery import states |
| 6 |
from celery.backends.azureblockblob import AzureBlockBlobBackend |
| 7 |
|
| 8 |
pytest.importorskip('azure') |
| 9 |
|
| 10 |
|
| 11 |
@pytest.mark.skipif( |
| 12 |
not os.environ.get('AZUREBLOCKBLOB_URL'), |
| 13 |
reason='Environment variable AZUREBLOCKBLOB_URL required' |
| 14 |
) |
| 15 |
class test_AzureBlockBlobBackend: |
| 16 |
def test_crud(self, manager): |
| 17 |
backend = AzureBlockBlobBackend( |
| 18 |
app=manager.app, |
| 19 |
url=os.environ["AZUREBLOCKBLOB_URL"]) |
| 20 |
|
| 21 |
key_values = {("akey%d" % i).encode(): "avalue%d" % i |
| 22 |
for i in range(5)} |
| 23 |
|
| 24 |
for key, value in key_values.items(): |
| 25 |
backend._set_with_state(key, value, states.SUCCESS) |
| 26 |
|
| 27 |
actual_values = backend.mget(key_values.keys()) |
| 28 |
expected_values = list(key_values.values()) |
| 29 |
|
| 30 |
assert expected_values == actual_values |
| 31 |
|
| 32 |
for key in key_values: |
| 33 |
backend.delete(key) |
| 34 |
|
| 35 |
def test_get_missing(self, manager): |
| 36 |
backend = AzureBlockBlobBackend( |
| 37 |
app=manager.app, |
| 38 |
url=os.environ["AZUREBLOCKBLOB_URL"]) |
| 39 |
|
| 40 |
assert backend.get(b"doesNotExist") is None |