Beispiel #1
0
def test_getattr_nbm(cbcsdk_mock):
    """Test __getattr__ method of NewBaseModel"""
    api = cbcsdk_mock.api
    cbcsdk_mock.mock_request("GET", "/integrationServices/v3/device/12345", ENDPOINT_STANDARD_DEVICE_GET_SPECIFIC_RESP)
    containsIdMutableBase = api.select(EndpointStandardDevice, 12345)
    assert containsIdMutableBase._model_unique_id == 12345
    assert containsIdMutableBase.__getattr__("avMaster") is False

    event = Event(api, 1234)
    assert 'eventTime' not in event._info
    cbcsdk_mock.mock_request("GET", "/integrationServices/v3/event/1234", {"eventInfo": {"eventTime": 1}})
    assert event.__getattr__("eventTime") == 1
    assert 'eventTime' in event._info

    with pytest.raises(AttributeError):
        assert event.__getattr__("missingInfoTag") is None
def test_getattr_nbm(cbcsdk_mock):
    """Test __getattr__ method of NewBaseModel"""
    api = cbcsdk_mock.api
    cbcsdk_mock.mock_request("GET", "/integrationServices/v3/policy/30241",
                             POLICY_GET_RESP)
    policy = Policy(api, 30241)
    assert policy._model_unique_id == 30241
    assert policy.__getattr__("name") == 'Lyon_test'

    event = Event(api, 1234)
    assert 'eventTime' not in event._info
    cbcsdk_mock.mock_request("GET", "/integrationServices/v3/event/1234",
                             {"eventInfo": {
                                 "eventTime": 1
                             }})
    assert event.__getattr__("eventTime") == 1
    assert 'eventTime' in event._info

    with pytest.raises(AttributeError):
        assert event.__getattr__("missingInfoTag") is None