How to use the followthemoney.proxy.EntityProxy.from_dict function in followthemoney

To help you get started, we’ve selected a few followthemoney examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_clone(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        other = proxy.clone()
        assert other == proxy
        other.id = "banana"
        assert proxy.id == "test"
        assert other != proxy
github alephdata / followthemoney / tests / test_proxy.py View on Github external
proxy.add("directorshipDirector", mem)

        with assert_raises(InvalidData):
            proxy.add("sameAs", proxy)

        with assert_raises(InvalidData):
            proxy.get("banana")
        assert [] == proxy.get("banana", quiet=True)

        with assert_raises(InvalidData):
            proxy.first("banana")
        assert proxy.first("banana", quiet=True) is None

        assert len(proxy.get("nationality")) == 0

        double = EntityProxy.from_dict(model, proxy)
        assert double == proxy

        proxy.add("banana", name, quiet=True)
        with assert_raises(InvalidData):
            proxy.add("banana", name)

        with assert_raises(InvalidData):
            EntityProxy.from_dict(model, {})
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_len(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        proxy_len = len(proxy)
        assert proxy_len > 0, proxy_len
        proxy.add("name", "Some text")
        assert len(proxy) > proxy_len, (len(proxy), proxy_len)
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_pop(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        get_ids = proxy.get("idNumber")
        assert get_ids, get_ids
        ids = proxy.pop("idNumber")
        assert get_ids == ids, ids
        assert not proxy.get("idNumber")
        assert not proxy.pop("idNumber")

        # new in 1.6.1: pop is quiet by default
        assert not proxy.pop("banana")
        with assert_raises(InvalidData):
            proxy.pop("banana", quiet=False)
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_merge(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        proxy.merge(proxy)
        other = {"schema": "LegalEntity", "properties": {"country": "gb"}}
        other = EntityProxy.from_dict(model, other)
        proxy.merge(other)
        assert "Ralph Tester" in proxy.names, proxy.names
        assert "gb" in proxy.countries, proxy.countries
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_max_size(self):
        t = registry.name
        proxy = EntityProxy.from_dict(model, ENTITY)
        prev_size = t.max_size
        t.max_size = len(proxy) + 10
        assert len(proxy.get("name")) == 1
        proxy.add("name", "Louis George Maurice Adolphe Roche Albert Abel")
        assert len(proxy.get("name")) == 1

        proxy.set("name", "Louis")
        assert len(proxy.get("name")) == 1, proxy.get("name")
        proxy.add("name", "A")
        assert len(proxy.get("name")) == 2, proxy.get("name")
        proxy.add("name", "George")
        assert len(proxy.get("name")) == 2, proxy.get("name")
        t.max_size = prev_size
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_inverted_props(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        data = proxy.get_type_inverted()
        assert "names" in data
        assert "1972-05-01" in data["dates"]
        assert "countries" not in data
        proxy.add("nationality", ["vg"])
        assert "vg" in proxy.countries
        data = proxy.get_type_inverted()
        assert "countries" in data
        assert "vg" in proxy.country_hints, proxy.country_hints
        assert "us" in proxy.country_hints, proxy.country_hints
github alephdata / followthemoney / tests / test_proxy.py View on Github external
with assert_raises(InvalidData):
            proxy.first("banana")
        assert proxy.first("banana", quiet=True) is None

        assert len(proxy.get("nationality")) == 0

        double = EntityProxy.from_dict(model, proxy)
        assert double == proxy

        proxy.add("banana", name, quiet=True)
        with assert_raises(InvalidData):
            proxy.add("banana", name)

        with assert_raises(InvalidData):
            EntityProxy.from_dict(model, {})
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_rdf(self):
        proxy = EntityProxy.from_dict(model, ENTITY)
        triples = list(proxy.triples())
        assert 10 == len(triples), len(triples)

        proxy = model.make_entity("Person")
        assert 0 == len(list(proxy.triples()))
github alephdata / followthemoney / followthemoney / model.py View on Github external
def get_proxy(self, data, cleaned=True):
        return EntityProxy.from_dict(self, data, cleaned=cleaned)