1
2async def test_redis(service_client, redis_store):
3 response = await service_client.delete('/v1/key-value?key=hello')
4 assert response.status == 200
5
6
7 assert redis_store.get('hello') is None
8
9 response = await service_client.post('/v1/key-value?key=hello&value=world')
10 assert response.status == 201
11 assert 'text/plain' in response.headers['Content-Type']
12 assert response.text == 'world'
13
14
15 assert redis_store.get('hello') == b'world'
16
17 response = await service_client.request('GET', '/v1/key-value?key=hello')
18 assert response.status == 200
19 assert 'text/plain' in response.headers['Content-Type']
20 assert response.text == 'world'
21
22
23 response = await service_client.request(
24 'POST', '/v1/key-value?key=hello&value=there',
25 )
26 assert response.status == 409
27
28 response = await service_client.request('GET', '/v1/key-value?key=hello')
29 assert response.status == 200
30 assert 'text/plain' in response.headers['Content-Type']
31 assert response.text == 'world'
32
33 response = await service_client.request(
34 'DELETE', '/v1/key-value?key=hello',
35 )
36 assert response.status == 200
37 assert 'text/plain' in response.headers['Content-Type']
38 assert response.text == '1'
39
40 response = await service_client.request('GET', '/v1/key-value?key=hello')
41 assert response.status == 404
42
43
44async def test_evalsha(service_client):
45 script = 'return "42"'
46
47 hash_id = 'initialhash'
48 response = await service_client.post(
49 f'/v1/script?command=evalsha&key=hello&hash={hash_id}',
50 )
51 assert response.status == 200
52 assert 'text/plain' in response.headers['Content-Type']
53 assert response.text == 'NOSCRIPT'
54
55 response = await service_client.post(
56 f'/v1/script?command=scriptload&key=hello&script={script}',
57 )
58 assert response.status == 200
59 hash_id = response.content.decode()
60
61 response = await service_client.post(
62 f'/v1/script?command=evalsha&key=hello&hash={hash_id}',
63 )
64 assert response.status == 200
65 assert 'text/plain' in response.headers['Content-Type']
66 assert response.text == '42'