Exemplo n.º 1
0
import pytest
from pytest_localserver.http import WSGIServer

from simon_says.app import create_app
from simon_says.client import Client
from simon_says.helpers import redis_present

#
# To run a redis instance locally for testing:
#   docker run --name my-redis -p 6379:6379 --restart always --detach redis
#
pytestmark = pytest.mark.skipif(not redis_present(),
                                reason="redis not present")

CODE = "1234"


@pytest.fixture
def test_server(request, test_controller, test_config):
    server = WSGIServer(
        application=create_app(config=test_config, controller=test_controller))
    server.start()
    request.addfinalizer(server.stop)
    return server


@pytest.fixture
def test_client(test_server):
    return Client(test_server.url)

Exemplo n.º 2
0
    assert e2["code"] == 131
    assert e2["code_description"] == "Perimeter"
    assert e2["category"] == "Alarms"
    assert e2["sensor"] == 15
    assert e2["sensor_name"] == "front window left"


def test_event(test_parsed_events):
    for r in test_parsed_events:
        event = under_test.AlarmEvent(**r)
        assert isinstance(event, under_test.AlarmEvent)
        assert event.sensor in [0, 15]
        assert json.loads(event.to_json())


@pytest.mark.skipif(not redis_present(), reason="redis not present")
def test_event_store(test_parsed_events, test_db):

    # Create a new event store for testing
    event_store = under_test.EventStore(db=test_db)

    for r in test_parsed_events:
        # Delete it first if it exists from previous tests
        o = event_store.get(r["uid"])
        if o:
            event_store.delete(r["uid"])

        # Create the object
        event = under_test.AlarmEvent(**r)

        # Add it to store