def test_invalid_no_type():
    data = {
        'id': 'Room:001',
        'temperature': {
            'type': 'Number',
            'value': 50,
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '2018-01-01T11:46:45.000Z'
                }
            }
        }
    }
    assert _validate_payload(data) is not None
def test_valid_no_attr_type():
    data = {
        'id': 'Room:001',
        'type': 'Room',
        'temperature': {
            'value': 50,
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '2018-01-01T11:46:45.000Z'
                }
            }
        }
    }
    assert _validate_payload(data) is None
    assert data['temperature']['value'] == 50
def test_valid_empty_textual_attr_value():
    data = {
        'id': 'Room:001',
        'type': 'Room',
        'temperature': {
            'type': 'Text',
            'value': '',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '2018-01-01T11:46:45.000Z'
                }
            }
        }
    }
    assert _validate_payload(data) is None
    assert 'value' in data['temperature']
    assert data['temperature']['value'] is ''
def test_valid_empty_numeric_attr_value():
    # See also GH Issue #145
    data = {
        'id': 'Room:001',
        'type': 'Room',
        'temperature': {
            'type': 'Number',
            'value': '',
            'metadata': {
                'dateModified': {
                    'type': 'DateTime',
                    'value': '2018-01-01T11:46:45.000Z'
                }
            }
        },
        'proximity': {
            'type': 'Number',
            'value': ' ',
            'metadata': {}
        },
        'TimeStep': {
            'type': 'DateTime',
            'value': '',
            'metadata': {}
        },
        'TimeInstant': {
            'type': 'DateTime',
            'value': ' ',
            'metadata': {}
        },
    }

    assert _validate_payload(data) is None
    assert data['temperature']['value'] is None
    assert data['proximity']['value'] is None
    assert data['TimeStep']['value'] is None
    assert data['TimeInstant']['value'] is None
def test_valid_no_attr():
    data = {
        'id': 'Room:001',
        'type': 'Room',
    }
    assert _validate_payload(data) is None