How to use followthemoney - 10 common examples

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_graph.py View on Github external
def test_basic_graph(self):
        proxy = model.get_proxy(ENTITY, cleaned=False)
        graph = Graph(edge_types=registry.pivots)
        graph.add(proxy)
        assert len(graph.iternodes()) > 1, graph.to_dict()
        assert len(graph.proxies) == 1, graph.proxies
        assert len(graph.queued) == 0, graph.proxies
        graph.add(None)
        assert len(graph.proxies) == 1, graph.proxies
        assert len(graph.queued) == 0, graph.proxies
github alephdata / followthemoney / tests / export / test_graph.py View on Github external
def test_nxgraph_full(self):
        sio = io.StringIO()
        edge_types = (
            registry.entity.name,
            registry.email.name,
            registry.phone.name,
        )
        exporter = NXGraphExporter(sio, edge_types=edge_types)
        for entity in ENTITIES:
            proxy = model.get_proxy(entity)
            exporter.write(proxy)

        self.assertEqual(len(exporter.graph.nodes), 5)
        self.assertEqual(len(exporter.graph.edges), 4)
github alephdata / followthemoney / tests / export / test_neo4j.py View on Github external
def test_csv_export(self):
        exporter = Neo4JCSVExporter(
            self.outdir, extra=["source"], edge_types=edge_types()
        )
        for entity in ENTITIES:
            entity = model.get_proxy(entity)
            exporter.write(entity, extra=["test"])
            fh, writer = exporter.handles[entity.schema]
            outfile = fh.name
        exporter.finalize()
        fh = open(outfile, "r")
        csv_reader = csv.reader(fh)
        rows = list(csv_reader)
        headers = rows[0]
        assert ":TYPE" in headers, headers
        assert ":START_ID" in headers, headers
        assert ":END_ID" in headers, headers
        assert "id" in headers, headers
        assert "date" in headers, headers
        data = rows[1]
        assert "OWNERSHIP" in data, data
        assert "2003-04-01" in data, data
github alephdata / followthemoney / tests / dedupe / test_match.py View on Github external
assert match.id == match.canonical.id, match
        assert match.entity_id == "ent", match
        assert match.entity_id == match.entity.id, match

        assert match._score is None, match
        assert match.score is not None, match

        sample2 = deepcopy(SAMPLE)
        canon = sample2.pop("canonical")
        sample2["profile_id"] = canon.get("id")
        match = Match(model, sample2)
        assert match.id == "can", match
        assert match.canonical is None, match
        assert match.entity is not None, match
        canon["id"] = "banana"
        match.canonical = model.get_proxy(canon)
        assert match.id == "banana", match
        match.entity = model.get_proxy(canon)
        assert match.entity_id == "banana", match
        assert "banana" in repr(match), repr(match)
github alephdata / followthemoney / tests / export / test_rdf.py View on Github external
def test_rdf_export(self):
        fh = open(self.temp, "w+")
        entity = model.get_proxy(ENTITY)
        exporter = RDFExporter(fh)
        exporter.write(entity)
        exporter.finalize()
        fh.seek(0)
        data = fh.readlines()
        assert len(data) == 8, len(data)
github alephdata / followthemoney / tests / graph / test_statement.py View on Github external
def test_graph(self):
        g = DiGraph()
        proxy = model.get_proxy(ENTITY)
        node = proxy.node
        self.assertEqual(str(node), node.id)
        for stmt in proxy.statements:
            stmt.to_digraph(g)
        self.assertEqual(g.number_of_edges(), 8)
        self.assertEqual(g.number_of_nodes(), 9)
        self.assertIn(node.id, g.nodes)

        prop = model.get_qname('Thing:name')
        stmt = Statement(Node(registry.name, 'Bob'), prop, proxy.id,
                         inverted=True)
        stmt.to_digraph(g)
        self.assertEqual(g.number_of_edges(), 9)

        stmt = Statement(node, prop, 'Blub', weight=0)
        stmt.to_digraph(g)
github alephdata / followthemoney / tests / export / test_excel.py View on Github external
def test_excel_bytesio(self):
        entity = model.get_proxy(ENTITY)
        exporter = ExcelExporter(self.temp, extra=["source"])
        exporter.write(entity, extra=["test"])
        buffer = exporter.get_bytesio()
        assert len(buffer.getvalue()) > 100
github alephdata / followthemoney / tests / test_helpers.py View on Github external
def test_entity_filename(self):
        proxy = model.get_proxy({"id": "banana", "schema": "Document",})
        file_name = entity_filename(proxy)
        assert "banana" == file_name, file_name

        proxy = model.get_proxy(
            {
                "id": "banana",
                "schema": "Document",
                "properties": {"extension": [".doc"],},
            }
        )
        file_name = entity_filename(proxy)
        assert "banana.doc" == file_name, file_name

        proxy = model.get_proxy(
            {
                "id": "banana",
                "schema": "Document",
                "properties": {"mimeType": ["application/pdf"],},
            }
        )
github alephdata / followthemoney / tests / test_proxy.py View on Github external
def test_make_id(self):
        proxy = model.make_entity("Thing")
        assert not proxy.make_id(None)
        assert proxy.make_id("banana")
        assert proxy.make_id("banana") == proxy.make_id("banana")
        ff = proxy.make_id(44)
        assert ff is not None
        proxy = model.make_entity("Thing", key_prefix="foo")
        assert proxy.make_id(44)
        assert proxy.make_id(44) != ff, proxy.make_id(44)
github alephdata / followthemoney / tests / test_proxy.py View on Github external
proxy.add("name", None)
        assert len(proxy.get("name")) == 2
        proxy.add("name", "")
        assert len(proxy.get("name")) == 2
        proxy.add("name", [""])
        assert len(proxy.get("name")) == 2
        proxy.add("name", {"name": "banana"})
        assert len(proxy.get("name")) == 3, proxy.get("name")
        assert name in proxy.get("name")
        assert name in proxy.names, proxy.names

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

        mem = model.make_entity("Membership")
        mem.id = "foo"
        with assert_raises(InvalidData):
            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