Exemplo n.º 1
0
def test_fail_to_deserialize_event_data_with_event_set_to_null():
    data = build_payload_data(event=None)

    with pytest.raises(SchemaError) as e:
        deserialize_payload(data)

    assert str(
        e.value
    ) == "Invalid MEGA payload: {'event': ['Field may not be null.']}"
Exemplo n.º 2
0
def test_fail_to_deserialize_payload_data_without_event_attribute():
    data = build_payload_data()
    del data['event']

    with pytest.raises(SchemaError) as e:
        deserialize_payload(data)

    assert str(
        e.value
    ) == "Invalid MEGA payload: {'event': ['Missing data for required field.']}"
Exemplo n.º 3
0
def test_fail_to_deserialize_payload_data_with_invalid_object_section():
    bogus_object_data = build_object_data()
    bogus_object_data['current'] = None

    data = build_payload_data(object=bogus_object_data)

    with pytest.raises(SchemaError) as e:
        deserialize_payload(data)

    assert str(e.value) == "Invalid MEGA payload. There is an error in the 'object' section: " \
                           "{'current': ['Field may not be null.']}"
Exemplo n.º 4
0
def test_fail_to_deserialize_payload_data_with_invalid_event_section():
    bogus_event_data = build_event_data()
    del bogus_event_data['name']

    data = build_payload_data(event=bogus_event_data)

    with pytest.raises(SchemaError) as e:
        deserialize_payload(data)

    assert str(e.value) == "Invalid MEGA payload. There is an error in the 'event' section: " \
                           "{'name': ['Missing data for required field.']}"
Exemplo n.º 5
0
def test_deserialize_full_payload_data():
    data = build_payload_data()

    payload = deserialize_payload(data)

    event_data = data['event']
    assert payload.event is not None
    assert isinstance(payload.event, Event)
    assert payload.event.name == event_data['name']
    assert payload.event.version == event_data['version']
    assert payload.event.domain == event_data['domain']
    assert payload.event.subject == event_data['subject']
    assert payload.event.publisher == event_data['publisher']
    assert payload.event.attributes == event_data['attributes']
    assert payload.event.timestamp == dateutil.parser.parse(
        event_data['timestamp'])

    object_data = data['object']
    assert payload.object is not None
    assert isinstance(payload.object, ObjectData)
    assert payload.object.type == object_data['type']
    assert payload.object.id == object_data['id']
    assert payload.object.version == object_data['version']
    assert payload.object.current == object_data['current']
    assert payload.object.previous == object_data['previous']

    assert payload.extra is not None
    assert payload.extra == data['extra']
Exemplo n.º 6
0
def test_deserialize_payload_ignoring_unknown_attributes():
    data = build_payload_data()
    data['foo'] = 'bar'
    data['one'] = 1

    payload = deserialize_payload(data)

    assert payload is not None
    assert isinstance(payload, Payload)
Exemplo n.º 7
0
def test_deserialize_payload_data_with_optional_attribute_set_to_null(
        attribute_key, expected_value):
    data = build_payload_data()
    data[attribute_key] = None
    payload = deserialize_payload(data)
    assert getattr(payload, attribute_key) == expected_value
Exemplo n.º 8
0
def test_deserialize_payload_data_without_optional_attribute(
        attribute_key, expected_value):
    data = build_payload_data()
    del data[attribute_key]
    payload = deserialize_payload(data)
    assert getattr(payload, attribute_key) == expected_value