def test_add_update_certification(meta_repo):
    certifications_repo = CertificationsRepo(meta_repo.conn)
    certification = Certification(
        "testcurrency", "7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
        "FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn", 20, 1473108382,
        "H41/8OGV2W4CLKbE35kk5t1HJQsb3jEM0/QGLUf80CwJvGZf3HvVCcNtHPUFoUBKEDQO9mPK3KJkqOoxHpqHCw==",
        0)

    certifications_repo.insert(certification)
    certification.written_on = 22
    certifications_repo.update(certification)
    cert2 = certifications_repo.get_one(
        currency="testcurrency",
        certifier="7Aqw6Efa9EzE7gtsc8SveLLrM7gm6NEGoywSv4FJx6pZ",
        certified="FADxcH5LmXGmGFgdixSes6nWnC4Vb4pRUBYT81zQRhjn",
        block=20)
    assert cert2.written_on == 22
Ejemplo n.º 2
0
    async def load_certified_by(self, identity):
        """
        Request the identity data and save it to written certifications
        It does nothing if the identity is already written and updated with blockchain lookups
        :param sakia.data.entities.Identity identity: the identity
        """
        certifications = []
        try:
            data = await self._bma_connector.get(self.currency,
                                                 bma.wot.certified_by,
                                                 {'search': identity.pubkey})
            for certified_data in data['certifications']:
                cert = Certification(
                    currency=self.currency,
                    certifier=data["pubkey"],
                    certified=certified_data["pubkey"],
                    block=certified_data["cert_time"]["block"],
                    timestamp=certified_data["cert_time"]["medianTime"],
                    signature=certified_data['signature'])
                if certified_data['written']:
                    cert.written_on = certified_data['written']['number']
                certifications.append(cert)
                # We save connections pubkeys
                if identity.pubkey in self._connections_processor.pubkeys():
                    self._certs_processor.insert_or_update_certification(cert)

            identity.written = True
            if identity.pubkey in self._connections_processor.pubkeys():
                self._identities_processor.insert_or_update_identity(identity)
        except errors.DuniterError as e:
            if e.ucode in (errors.NO_MATCHING_IDENTITY,
                           errors.NO_MEMBER_MATCHING_PUB_OR_UID):
                logging.debug("Certified by error : {0}".format(str(e)))
                identity.written = False
                if identity.pubkey in self._connections_processor.pubkeys():
                    self._identities_processor.insert_or_update_identity(
                        identity)
        except NoPeerAvailable as e:
            logging.debug(str(e))
        return certifications