-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-By: Markus Gärtner <[email protected]>
- Loading branch information
Showing
4 changed files
with
214 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: Test | ||
|
||
on: | ||
push: | ||
branches: [ master ] | ||
pull_request: | ||
branches: [ master ] | ||
|
||
jobs: | ||
build: | ||
|
||
strategy: | ||
matrix: | ||
redis-version: ["2.*", "3.*", "4.*", "5.*"] | ||
os: ["ubuntu-24.04", "ubuntu-22.04", "ubuntu-20.04"] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Install redis package | ||
run: sudo python3 -m pip install redis==${{ matrix.redis-version }} | ||
- name: Run test | ||
run: python3 -m unittest discover python/tests/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../minqlx/database.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
from unittest import TestCase | ||
import database | ||
import random | ||
import string | ||
from time import sleep | ||
|
||
|
||
def random_string(): | ||
return "".join([random.choice(string.ascii_letters) for x in range(10)]) | ||
|
||
|
||
class RedisRegressionTestCase(TestCase): | ||
def setUp(self): | ||
self.c = database.Redis(None) | ||
self.c.connect("127.0.0.1:6379") | ||
|
||
def test_zadd_01(self): | ||
c = self.c | ||
key = "zadd_01_key_" + random_string() | ||
|
||
c.zadd(key, 5, "player1", 6, "player2") | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertEqual(res["player1"], 5) | ||
self.assertEqual(res["player2"], 6) | ||
|
||
c.zadd(key, 2, "player1") | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertEqual(res["player1"], 2) | ||
self.assertEqual(res["player2"], 6) | ||
|
||
c.zadd(key, 3, "player1", xx=True) | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertEqual(res["player1"], 3) | ||
|
||
c.zadd(key, 3, "player_does_not_exist", xx=True) | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertNotIn("player_does_not_exist", res) | ||
|
||
def test_zincrby_01(self): | ||
key = "zincrby_01_key_" + random_string() | ||
c = self.c | ||
|
||
c.zincrby(key, "FIELD1") | ||
c.zincrby(key, "FIELD2", 2) | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertEqual(res["FIELD1"], 1) | ||
self.assertEqual(res["FIELD2"], 2) | ||
|
||
c.zincrby(key, "FIELD1") | ||
c.zincrby(key, "FIELD2", 3) | ||
res = dict(c.zrange(key, 0, -1, withscores=True)) | ||
self.assertEqual(res["FIELD1"], 2) | ||
self.assertEqual(res["FIELD2"], 5) | ||
|
||
def test_lrem_01(self): | ||
key = "lrem_01_key_" + random_string() | ||
c = self.c | ||
|
||
c.rpush( | ||
key, | ||
"Cat", | ||
"Dog", | ||
"Horse", | ||
"Cat", | ||
"Dog", | ||
"Cat", | ||
"Monkey", | ||
"Dog", | ||
"Cat", | ||
"Dog", | ||
"Buffalo", | ||
) | ||
c.lrem(key, "Cat", 2) | ||
result = c.lrange(key, 0, -1) | ||
self.assertEqual( | ||
result, | ||
["Dog", "Horse", "Dog", "Cat", "Monkey", "Dog", "Cat", "Dog", "Buffalo"], | ||
) | ||
|
||
def test_setex_01(self): | ||
key = "setex_01_key_" + random_string() | ||
c = self.c | ||
test_value = "test value" | ||
timeout = 1 | ||
|
||
c.setex(key, test_value, timeout) | ||
self.assertEqual(c.get(key), test_value, "Too small timeout value?") | ||
sleep(timeout + 0.5) | ||
self.assertEqual(c.get(key), None) | ||
|
||
def test_mset_01(self): | ||
c = self.c | ||
c.mset(field1="example1", field2="example2") | ||
self.assertEqual(["example1", "example2"], c.mget("field1", "field2")) | ||
|
||
def test_mset_02(self): | ||
c = self.c | ||
c.mset({"field3": "example1", "field4": "example2"}) | ||
self.assertEqual(["example1", "example2"], c.mget("field3", "field4")) | ||
|
||
def test_msetnx_01_kwargs(self): | ||
c = self.c | ||
prefix = "msetnx_01_key_" + random_string() | ||
key1 = prefix + "_field1" | ||
key2 = prefix + "_field2" | ||
d = { | ||
key1: "example1", | ||
key2: "example2", | ||
} | ||
c.msetnx(**d) | ||
self.assertEqual(["example1", "example2"], c.mget(key1, key2)) | ||
|
||
d = { | ||
key1: "value should not be used", | ||
key2: "same here", | ||
} | ||
c.msetnx(**d) | ||
self.assertEqual(["example1", "example2"], c.mget(key1, key2)) | ||
|
||
def test_msetnx_02_dict(self): | ||
c = self.c | ||
prefix = "msetnx_02_key_" + random_string() | ||
key1 = prefix + "_field1" | ||
key2 = prefix + "_field2" | ||
d = { | ||
key1: "example1", | ||
key2: "example2", | ||
} | ||
c.msetnx(d) | ||
self.assertEqual(["example1", "example2"], c.mget(key1, key2)) | ||
|
||
d = { | ||
key1: "value should not be used", | ||
key2: "same here", | ||
} | ||
c.msetnx(d) | ||
self.assertEqual(["example1", "example2"], c.mget(key1, key2)) |