Skip to content

Commit

Permalink
🧪 test
Browse files Browse the repository at this point in the history
  • Loading branch information
mic1on committed Aug 8, 2023
1 parent 06686cc commit fa75be0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
fail-fast: true
matrix:
os: [ "ubuntu-latest" ]
python-version: [ "3.8", "3.9", "3.10" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
runs-on: ${{ matrix.os }}
services:
redis:
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "usepy-plugin-redis"
version = "0.1.0"
version = "0.1.1"
description = ""
authors = ["miclon <jcnd@163.com>"]
readme = "README.md"
Expand Down
31 changes: 30 additions & 1 deletion tests/test_redis.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import threading

import pytest

from usepy_plugin_redis import useRedisStreamStore
Expand All @@ -8,8 +10,35 @@ def redis():
return useRedisStreamStore()


def test_connection(redis):
"""
Test that the connection is established
"""
assert redis.connection.ping()


def test_send(redis):
stream = 'test_stream'
message = {'foo': 'bar'}
redis.send(stream, message)
assert redis.connection.xlen(stream) == 1
assert redis.connection.xlen(stream) >= 1


def test_consumer(redis):
stream = 'test_consumer_stream'
send_message = {'foo': 'bar'}
redis.send(stream, send_message)

def callback(message):
assert isinstance(message, list)
assert len(message) == 1
first_message = message[0]
message_id, message = first_message
_message = {
k.decode() if isinstance(k, bytes) else k: v.decode() if isinstance(v, bytes) else v
for k, v in message.items()
}
assert _message == send_message
redis.shutdown()

threading.Thread(target=redis.start_consuming, args=(stream, 'test_group', 'test_consumer', callback)).start()

0 comments on commit fa75be0

Please sign in to comment.