From f545679842456a61b0ff448408da3f398dbcf460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Friedger=20M=C3=BCffke?= Date: Thu, 6 Jun 2019 11:00:36 +0200 Subject: [PATCH] add expire block --- blockstats/blockstats_dao.py | 5 +++++ blockstats/blockstats_importer.py | 4 ++++ tests/unit/dao_test.py | 11 ++++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/blockstats/blockstats_dao.py b/blockstats/blockstats_dao.py index aba3ed0..9bfc49e 100644 --- a/blockstats/blockstats_dao.py +++ b/blockstats/blockstats_dao.py @@ -31,6 +31,11 @@ def update_profile_url(self, snapshot_id, address, profile_url): {'snapshot_id': snapshot_id, 'address': address}, {"$set": {"profile_url": profile_url}}) + def update_expire_block(self, snapshot_id, address, expire_block): + self._db.identities.find_one_and_update( + {'snapshot_id': snapshot_id, 'address': address}, + {"$set": {"expire_block": expire_block}}) + def update_is_person(self, snapshot_id, address, is_person): self._db.identities.find_one_and_update( {'snapshot_id': snapshot_id, 'address': address}, {"$set": {"is_person": is_person}}) diff --git a/blockstats/blockstats_importer.py b/blockstats/blockstats_importer.py index 1b74de3..7318d87 100644 --- a/blockstats/blockstats_importer.py +++ b/blockstats/blockstats_importer.py @@ -73,12 +73,16 @@ def _import_profile_url(self, client, snapshot_id, address): details = client.download_name_details(address) zonefile = None profile_url = None + expire_block = None if details: zonefile = details.get('zonefile') + expire_block = details.get('expire_block') if zonefile: profile_url = parser.extract_profile_url(zonefile) if profile_url: self.dao.update_profile_url(snapshot_id, address, profile_url) + if expire_block: + self.dao.update_expire_block(snapshot_id, address, expire_block) def import_app_installs_multithreaded(self, snapshot_id, threads=1): identities = self.dao.get_identities(snapshot_id) diff --git a/tests/unit/dao_test.py b/tests/unit/dao_test.py index 61c7a7a..6fd72ec 100644 --- a/tests/unit/dao_test.py +++ b/tests/unit/dao_test.py @@ -55,6 +55,15 @@ def test_update_profile_url(dao): assert dao.read_all_identities()[0].get('profile_url') == 'https://testurl.com' +def test_update_expire_block(dao): + timestamp = datetime.datetime.utcnow() + identities = [{'address': '111.id', 'name': '111', 'namespace': 'id'}] + + dao.save_identities(snapshot_id='1234', timestamp=timestamp, identities=identities) + dao.update_expire_block(snapshot_id='1234', address='111.id', expire_block=100) + + assert dao.read_all_identities()[0].get('expire_block') == 100 + def test_update_is_person(dao): timestamp = datetime.datetime.utcnow() identities = [{'address': '111.id', 'name': '111', 'namespace': 'id'}] @@ -111,4 +120,4 @@ def test_force_remove_snapshot(dao): assert len(dao.get_identities(snapshot2_id)) == 1 assert len(dao.get_app_installations(snapshot1_id)) == 0 - assert len(dao.get_identities(snapshot2_id)) == 1 \ No newline at end of file + assert len(dao.get_identities(snapshot2_id)) == 1