def publish_results(username, password, journalId): # Initialize Ledger API ledgerApi = LedgerApi(baseUrl) # Authenticate user in ledger session = ledgerApi.authenticateUser(username, password) # Retrieve voting journal data journalString = ledgerApi.getJournal(session, journalId) export_raw(journalString) # Calculate voting results votingResults = VotesCounter().count(journalString) # Export result to html presentation html = generate_html(votingResults) export_html(html)
def test_all(self): logger = logging.getLogger(__name__) # Load ledger base url from configuration parser = SafeConfigParser() parser.read('load.ini') baseUrl = parser.get('general', 'host') username = parser.get('general', 'username') password = parser.get('general', 'password') # Initialize ledger api client ledgerApi = LedgerApi(baseUrl) with open('tests/resources/fingerprint_template.json', 'r') as fingerprint_template_file: fingerprint_template = fingerprint_template_file.read() with open('tests/resources/vote_template.json', 'r') as vote_template_file: vote_template = vote_template_file.read() vote = vote_template voteBase64 = b64encode(vote) fingerprint = fingerprint_template % voteBase64 session = ledgerApi.authenticateUser(username, password) journalId = ledgerApi.createJournal(session, faker.name()) recordId = ledgerApi.createRecord(session) ledgerApi.saveRecordFingerprint(session, recordId, fingerprint) ledgerApi.commitRecord(session, journalId, recordId) # Uncomment next line if need to timestamp (create a transaction in blockchain) ledgerApi.timestampJournal(session, journalId) print journalId self.assertTrue(True)
class TestResultPublisher(unittest.TestCase): def setUp(self): self.logger = logging.getLogger(__name__) # Load ledger base url from configuration parser = SafeConfigParser() parser.read('load.ini') baseUrl = parser.get('general', 'host') # Initialize ledger api client self.ledgerApi = LedgerApi(baseUrl) with open('tests/resources/fingerprint_template.json','r') as fingerprint_template_file: fingerprint_template = fingerprint_template_file.read() with open('tests/resources/vote_template.json','r') as vote_template_file: vote_template = vote_template_file.read() voteBase64 = b64encode(vote_template) self.testFingerprint = fingerprint_template % voteBase64 self.username = faker.email() self.password = "******" self.journalId = self.setupJournal(self.username, self.password) def setupJournal(self, username, password): session = self.ledgerApi.createUser(username, password) journalId = self.ledgerApi.createJournal(session, faker.name()) recordId = self.ledgerApi.createRecord(session) self.ledgerApi.saveRecordFingerprint(session, recordId, self.testFingerprint) self.ledgerApi.commitRecord(session, journalId, recordId) # Uncomment next line if need to timestamp (create a transaction in blockchain) self.ledgerApi.timestampJournal(session, journalId) return journalId def test_publish_results(self): publish_results(self.username, self.password, self.journalId) self.assertTrue(True)
def setUp(self): self.logger = logging.getLogger(__name__) # Load ledger base url from configuration parser = SafeConfigParser() parser.read('load.ini') baseUrl = parser.get('general', 'host') # Initialize ledger api client self.ledgerApi = LedgerApi(baseUrl) with open('tests/resources/fingerprint_template.json','r') as fingerprint_template_file: fingerprint_template = fingerprint_template_file.read() with open('tests/resources/vote_template.json','r') as vote_template_file: vote_template = vote_template_file.read() voteBase64 = b64encode(vote_template) self.testFingerprint = fingerprint_template % voteBase64 self.username = faker.email() self.password = "******" self.journalId = self.setupJournal(self.username, self.password)
from base64 import b64encode from utils.ledger_api import LedgerApi # setup loggging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) faker = Factory.create() parser = SafeConfigParser() parser.read('load.ini') baseUrl = parser.get('general', 'host') ledgerApi = LedgerApi(baseUrl) """ Create user """ # TODO implement click # import click # @click.command() # @click.option('--timestamp-weight', default=1, help='Weight of a timestamp operation') logger.debug('Starting creating an user') username = faker.email()
#!/usr/bin/env python import logging from ConfigParser import SafeConfigParser from utils.ledger_api import LedgerApi # setup loggging logging.basicConfig(level=logging.DEBUG) logger = logging.getLogger(__name__) parser = SafeConfigParser() parser.read('load.ini') baseUrl = parser.get('general', 'host') journal = parser.get('general', 'journal') username = parser.get('general', 'username') password = parser.get('general', 'password') ledgerApi = LedgerApi(baseUrl) session = ledgerApi.authenticateUser(username, password) ledgerApi.timestampJournal(session, journal)