Example #1
0
def test_get_attribute_behaviour_dynamically_loading_object_lists(
                                                            API_OBJECT_TYPES):
    """Test ``__get_attribute__`` loads object lists dynamically if required.

    Test that :py:class:`~pyrally.models.BaseRallyModel` classes dynamically
    load sub-content using Rally API calls when required.

    It does this when an attribute is given that is defined in
    ``sub_objects_dynamic_loader``. In such circumstances the mapped key
    should be used and all sub items in that key fetched from the server.
    """
    mock_baserally_obj = Mock()
    mock_create_from_ref = mock_baserally_obj.create_from_ref
    API_OBJECT_TYPES.get.return_value = mock_baserally_obj
    test_data = {'dynamic_sub_object': [{'_ref': 'some_reference_1',
                                         '_type': 'api_type'},
                                        {'_ref': 'some_reference_2',
                                         '_type': 'api_type'},
                                         ]}

    brm = BaseRallyModel(test_data)
    brm.sub_objects_dynamic_loader = {'test_property': 'dynamic_sub_object'}

    dynamic_content = brm.test_property

    # Check that this is now stored in the object for use later.
    assert_equal(dynamic_content, brm._full_sub_objects['test_property'])

    assert_equal(dynamic_content, [mock_create_from_ref.return_value,
                                   mock_create_from_ref.return_value])

    assert_equal(API_OBJECT_TYPES.get.call_count, 2)
    assert_equal(mock_create_from_ref.call_count, 2)
Example #2
0
def test_get_attribute_behaviour_dynamically_loading_object_lists(
        API_OBJECT_TYPES):
    """Test ``__get_attribute__`` loads object lists dynamically if required.

    Test that :py:class:`~pyrally.models.BaseRallyModel` classes dynamically
    load sub-content using Rally API calls when required.

    It does this when an attribute is given that is defined in
    ``sub_objects_dynamic_loader``. In such circumstances the mapped key
    should be used and all sub items in that key fetched from the server.
    """
    mock_baserally_obj = Mock()
    mock_create_from_ref = mock_baserally_obj.create_from_ref
    API_OBJECT_TYPES.get.return_value = mock_baserally_obj
    test_data = {
        'dynamic_sub_object': [
            {
                '_ref': 'some_reference_1',
                '_type': 'api_type'
            },
            {
                '_ref': 'some_reference_2',
                '_type': 'api_type'
            },
        ]
    }

    brm = BaseRallyModel(test_data)
    brm.sub_objects_dynamic_loader = {'test_property': 'dynamic_sub_object'}

    dynamic_content = brm.test_property

    # Check that this is now stored in the object for use later.
    assert_equal(dynamic_content, brm._full_sub_objects['test_property'])

    assert_equal(
        dynamic_content,
        [mock_create_from_ref.return_value, mock_create_from_ref.return_value])

    assert_equal(API_OBJECT_TYPES.get.call_count, 2)
    assert_equal(mock_create_from_ref.call_count, 2)