def test_publish_to_broker(pact):
    """
    This test does not clean-up previously generated pact.
    Sample execution where 2 is an arbitrary version:

    `pytest tests/consumer/test_message_consumer.py::test_publish_pact_to_broker`

    `pytest tests/consumer/test_message_consumer.py::test_publish_pact_to_broker --publish-pact 2`
    """
    expected_event = {
        "event": "ObjectCreated:Delete",
        "documentName": "document.doc",
        "creator": "TP",
        "documentType": "microsoft-word"
    }

    (pact.given("A document deleted successfully").expects_to_receive(
        "Description with broker").with_content(expected_event).with_metadata(
            {"Content-Type": "application/json"}))

    with pact:
        MessageHandler(expected_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 1
示例#2
0
def test_publish_to_broker(pact):
    """
    This test does not clean-up previously generated pact.
    Sample execution where 2 is an arbitrary version:

    `pytest tests/consumer/test_message_consumer.py::test_publish_pact_to_broker`

    `pytest tests/consumer/test_message_consumer.py::test_publish_pact_to_broker --publish-pact 2`
    """
    expected_event = {
        'documentName': 'document.doc',
        'creator': 'TP',
        'documentType': 'microsoft-word'
    }

    (pact
     .given('A document create in Document Service with broker')
     .expects_to_receive('Description with broker')
     .with_content(expected_event)
     .with_metadata({
         'Content-Type': 'application/json'
     }))

    with pact:
        MessageHandler(expected_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 1
def test_put_file(pact):
    cleanup_json(PACT_FILE)

    expected_event = {
        "event": "ObjectCreated:Put",
        "documentName": "document.doc",
        "creator": "TP",
        "documentType": "microsoft-word"
    }

    (pact.given("A document created successfully").expects_to_receive(
        "Description").with_content(expected_event).with_metadata(
            {"Content-Type": "application/json"}))

    with pact:
        MessageHandler(expected_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 1
示例#4
0
def test_generate_new_pact_file(pact):
    cleanup_json(PACT_FILE)

    expected_event = {
        'documentName': 'document.doc',
        'creator': 'TP',
        'documentType': 'microsoft-word'
    }

    (pact.given('A document create in Document Service').expects_to_receive(
        'Description').with_content(expected_event).with_metadata(
            {'Content-Type': 'application/json'}))

    with pact:
        # handler needs 'documentType' == 'microsoft-word'
        MessageHandler(expected_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 1
示例#5
0
def test_throw_exception_handler(pact):
    cleanup_json(PACT_FILE)
    wrong_event = {
        'documentName': 'spreadsheet.xls',
        'creator': 'WI',
        'documentType': 'microsoft-excel'
    }

    (pact.given('Another document in Document Service').expects_to_receive(
        'Description').with_content(wrong_event).with_metadata(
            {'Content-Type': 'application/json'}))

    with pytest.raises(CustomError):
        with pact:
            # handler needs 'documentType' == 'microsoft-word'
            MessageHandler(wrong_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 0
def test_throw_exception_handler(pact):
    cleanup_json(PACT_FILE)

    wrong_event = {
        "event": "ObjectCreated:Put",
        "documentName": "spreadsheet.xls",
        "creator": "WI",
        "documentType": "microsoft-excel"
    }

    (pact.given("Document unsupported type").expects_to_receive(
        "Description").with_content(wrong_event).with_metadata(
            {"Content-Type": "application/json"}))

    with pytest.raises(CustomError):
        with pact:
            # handler needs "documentType" == "microsoft-word"
            MessageHandler(wrong_event)

    progressive_delay(f"{PACT_FILE}")
    assert isfile(f"{PACT_FILE}") == 0
#!/usr/bin/env python3


from src.light_controller import LightController
from src.message_handler import MessageHandler
from src.config import loadConfig
from src.subscriber import start_mqtt, set_on_message_callback


if __name__ == "__main__":
    loadConfig("config.json")
    
    # Create a light controller and initialize a bulb
    lightController = LightController()
    lightController.initializeBulb()

    # Create a message handler and pass the light controller
    messageHandler = MessageHandler(lightController)

    # Start the mqtt service and set the 
    start_mqtt()
    set_on_message_callback(messageHandler.receiveData)