def testGetValueUponStatus200(self): "Test result value upon status 200" source = DocumentSourceMock((200, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertEquals(document.get_value(parser_func=parser_stub_func), 3)
def testGetValueUponWrongStatus(self): "Test result value upon wrong status" source = DocumentSourceMock((405, CORRECT_CERTIFICATE_WITH_VALID_SIGNATURE)) document = Document(source) self.assertEquals(document.get_value(parser_func=parser_stub_func), None)
def index(): D = request.args.get('D', None) B = request.args.get('B', '') F = request.args.get('F', None) E = request.args.get('E', None) K = request.args.get('K', None) L = request.args.get('L', '') status_code = 200 payment_required = False if F is not None: try: F = int(F) except ValueError: F = 0 else: F = 0 page = [render_header()] if D is None: return _render_error_page(_('Missing parameter'), _('Parameter D is missing')) invoice = Invoice(D, B=B, F=F) document_source = DocumentSource(settings.ISSUER, docid=invoice.D) document = Document(document_source) value = None verified = document.verify() # document.verify() returns False if verification failed # and None upon another error if verified != False: value = document.get_value() if value is not None: invoice.value = value if value > 0: invoice.certificate_link = '<a href="%s/info?ID=%s">%s</a>' % (settings.ISSUER, invoice.D, _('GET CERTIFICATE')) if (value >= F) and (F is not None) and (F > 0): invoice.message = _('The corresponding invoice has been paid') page.append(render_invoce(invoice)) # Email address email = '' if E is not None: set_cookie_value('pfemail', E) email = E else: email = request.cookies.get('pfemail') # PGP encryption key ID pgpkey = '' if K is not None: set_cookie_value('pfpgpkey', K) pgpkey = K else: pgpkey = request_cookies_get('pfpgpkey') # If mailreceipt application is configured render the email form if settings.MAILRECEIPT_URL: page.append(render_email_form(email, pgpkey, document.get_sn(), settings.MAILRECEIPT_URL, L)) else: if F > 0: payment_required = True status_code = 402 invoice.G = '%s/?D=%s&F=%s' % (settings.REDIRECTION_TARGET, invoice.D, str(invoice.F)) page.append(render_invoce_form(invoice)) else: return self._render_error_page(_('Internal error'), _('Sorry for the inconvenience')) page.append(render_footer()) response = make_response(page, status_code) if payment_required: response.headers['Content-Price'] = "%s EPT" % str(F - value) return response