Exemplo n.º 1
0
 def test_validate_asset_hierarchy__more_than_limit_only_resolved_assets(
         self):
     with set_request_limit(ASSETS_API, 1):
         _AssetPoster([
             Asset(external_id="a1", parent_id=1),
             Asset(external_id="a2", parent_id=2)
         ], ASSETS_API)
Exemplo n.º 2
0
 def test_validate_asset_hierarchy_duplicate_ref_ids(self):
     assets = [
         Asset(external_id="1"),
         Asset(parent_external_id="1", external_id="1")
     ]
     with pytest.raises(AssertionError, match="Duplicate"):
         _AssetPoster(assets, ASSETS_API)
Exemplo n.º 3
0
 def test_post_assets_over_limit_only_resolved(self,
                                               mock_post_asset_hierarchy):
     with set_request_limit(ASSETS_API, 1):
         _AssetPoster([
             Asset(external_id="a1", parent_id=1),
             Asset(external_id="a2", parent_id=2)
         ], ASSETS_API).post()
     assert 2 == len(mock_post_asset_hierarchy.calls)
Exemplo n.º 4
0
 def test_validate_asset_hierarchy_self_dependency(self):
     assets = [
         Asset(external_id="1"),
         Asset(external_id="2", parent_external_id="2")
     ]
     with set_request_limit(ASSETS_API, 1):
         with pytest.raises(AssertionError, match="circular dependencies"):
             _AssetPoster(assets, ASSETS_API)
Exemplo n.º 5
0
 def test_validate_asset_hierarchy_asset_has_parent_id_and_parent_ref_id(
         self):
     assets = [
         Asset(external_id="1"),
         Asset(parent_external_id="1", parent_id=1, external_id="2")
     ]
     with pytest.raises(AssertionError, match="has both"):
         _AssetPoster(assets, ASSETS_API)
Exemplo n.º 6
0
    def test_initialize(self):
        assets = [
            Asset(external_id="1"),
            Asset(external_id="3", parent_external_id="1"),
            Asset(external_id="2", parent_external_id="1"),
            Asset(external_id="4", parent_external_id="2"),
        ]

        ap = _AssetPoster(assets, ASSETS_API)
        assert OrderedDict({str(i): None
                            for i in range(1, 5)}) == ap.remaining_external_ids
        assert {
            "1": {
                Asset(external_id="2", parent_external_id="1"),
                Asset(external_id="3", parent_external_id="1")
            },
            "2": {Asset(external_id="4", parent_external_id="2")},
            "3": set(),
            "4": set(),
        } == ap.external_id_to_children
        assert {
            "1": 3,
            "2": 1,
            "3": 0,
            "4": 0
        } == ap.external_id_to_descendent_count
        assert ap.assets_remaining() is True
        assert 0 == len(ap.posted_assets)
        assert ap.request_queue.empty()
        assert ap.response_queue.empty()
        assert {"1", "2", "3", "4"} == ap.remaining_external_ids_set
Exemplo n.º 7
0
 def test_get_unblocked_assets__assets_unblocked_by_default_less_than_limit(
         self):
     assets = generate_asset_tree(root_external_id="0",
                                  depth=4,
                                  children_per_node=10)
     ap = _AssetPoster(assets=assets, client=ASSETS_API)
     unblocked_assets_lists = ap._get_unblocked_assets()
     assert 1 == len(unblocked_assets_lists)
     assert 1000 == len(unblocked_assets_lists[0])
Exemplo n.º 8
0
 def test_get_unblocked_assets__assets_unblocked_by_default_more_than_limit(self):
     assets = []
     for i in range(4):
         assets.extend(generate_asset_tree(root_external_id=str(i), depth=2, children_per_node=2))
     with set_request_limit(ASSETS_API, 3):
         ap = _AssetPoster(assets=assets, client=ASSETS_API)
         unblocked_assets_lists = ap._get_unblocked_assets()
     assert 4 == len(unblocked_assets_lists)
     for li in unblocked_assets_lists:
         assert 3 == len(li)
Exemplo n.º 9
0
 def test_get_unblocked_assets_parent_ref_null_pointer(self):
     assets = [Asset(parent_external_id="1", external_id="2")]
     ap = _AssetPoster(assets, ASSETS_API)
     asset_list = ap._get_unblocked_assets()
     assert len(asset_list) == 1