def test_model_attributes_nbm(cbcsdk_mock):
    """Test _model_unique_id property/method of NewBaseModel"""
    initial_data = {'id': 123, 'test': 1, 'a list': [], 'a string': 'test'}
    api = cbcsdk_mock.api
    nbm_object = NewBaseModel(cb=api,
                              model_unique_id=None,
                              initial_data=initial_data)
    nbm_object._dirty_attributes = {'id': None, 'test': 2}
    assert nbm_object._model_unique_id == 123
    result_str = str(nbm_object)
    assert '{0:s} {1:>20s}:'.format('(+)', 'id') in result_str
    assert '{0:s} {1:>20s}:'.format('(*)', 'test') in result_str
def test_model_unique_id_nbm(cbcsdk_mock):
    """Test _model_unique_id property/method of NewBaseModel"""
    api = cbcsdk_mock.api
    nbm_object = NewBaseModel(cb=api, model_unique_id=123)
    assert nbm_object._model_unique_id == 123
    obj_repr = nbm_object.__repr__()
    assert 'cbc_sdk.base.NewBaseModel:' in obj_repr
    assert 'id 123' in obj_repr

    nbm_object._full_init = False
    result = str(nbm_object)
    assert 'Partially initialized. Use .refresh() to load all attributes' in result
def test_get_nbm(cbcsdk_mock):
    """Test get method of NewBaseModel"""
    api = cbcsdk_mock.api
    nbm = NewBaseModel(api)
    assert nbm.get("_mutable_attr", default_val="def") == "def"

    nbm.__setattr__("_mutable_attr", "new_value")
    assert nbm.get("_mutable_attr", default_val="def") == "new_value"
Ejemplo n.º 4
0
def test_refresh_nbm(cbcsdk_mock):
    """Test refresh and _refresh methods of NewBaseModel"""
    api = cbcsdk_mock.api
    # refresh() should return False if there is no _model_unique_id
    object_without_model_unique_id = NewBaseModel(api)
    assert object_without_model_unique_id.refresh() is False

    # refresh() should return False if cls.primary_key is in _dirty_attributes
    object_with_dirty_model_unique_id = NewBaseModel(api, 1)
    object_with_dirty_model_unique_id._dirty_attributes["id"] = 2
    assert object_with_dirty_model_unique_id.primary_key == "id"
    assert "id" in object_with_dirty_model_unique_id._dirty_attributes
    object_with_dirty_model_unique_id.refresh() is False

    # refresh() should return True if there's a _model_unique_id and primary_key hasn't been changed
    cbcsdk_mock.mock_request("GET", "/integrationServices/v3/event/a1e12604d67b11ea920d3d9192a785d1",
                             EVENT_GET_SPECIFIC_RESP)
    refreshable_object = Event(api, "a1e12604d67b11ea920d3d9192a785d1")
    assert refreshable_object._full_init is False
    assert refreshable_object.refresh() is True
    assert refreshable_object._full_init is True
def test_model_unique_id_nbm(cbcsdk_mock):
    """Test _model_unique_id property/method of NewBaseModel"""
    api = cbcsdk_mock.api
    nbm_object = NewBaseModel(cb=api, model_unique_id=123)
    assert nbm_object._model_unique_id == 123
def test_parse_nbm(cbcsdk_mock):
    """Test _parse method of NewBaseModel"""
    nbm = NewBaseModel(cbcsdk_mock.api)
    # _parse returns whatever is passed into it as a parameter
    assert nbm._parse(nbm._cb) == cbcsdk_mock.api
    assert nbm._parse(nbm._last_refresh_time) == 0