コード例 #1
0
    def test_get_official_copy_data_throws_exception_when_api_returns_500_response(
            self, mock_get):

        with raises(Exception) as e:
            api_client.get_official_copy_data('title123')

        assert 'API returned an unexpected response (500)' in str(e)
コード例 #2
0
    def test_get_official_copy_data_throws_exception_when_200_response_body_is_not_json(
            self, mock_get):

        with raises(Exception) as e:
            api_client.get_official_copy_data('title123')

        assert 'API response body is not JSON' in str(e)
コード例 #3
0
    def test_get_official_copy_data_calls_the_right_api_endpoint(
            self, mock_get):
        title_number = 'title123'

        api_client.get_official_copy_data(title_number)
        mock_get.assert_called_once_with(
            '{}/titles/title123/official-copy'.format(
                self.register_title_api_url))
コード例 #4
0
def display_title_pdf(title_number):
    title = _get_register_title(title_number)
    if title:
        full_title_data = api_client.get_official_copy_data(title_number)
        if full_title_data:
            sub_registers = full_title_data.get('official_copy_data', {}).get('sub_registers')
            if sub_registers:
                html = _create_pdf_template(sub_registers, title, title_number)
                return render_pdf(HTML(string=html))
    abort(404)
def _get_title_data(trans_id, username, title_number):
    LOGGER.debug(
        "STARTED: _get_title_data title_number: {}".format(title_number))

    title = _get_register_title(title_number)

    if title:
        if _user_can_view(username, title_number):

            is_caution_title = title_utils.is_caution_title(title)

            if app.config['SHOW_FULL_TITLE_DATA']:
                full_title_data = _strip_delimiters(
                    api_client.get_official_copy_data(title_number))
            else:
                full_title_data = None

            if is_caution_title:
                title['summary_heading'] = gettext("Summary of caution title")
            else:
                title['summary_heading'] = gettext("Summary of title")

            if is_caution_title:
                title['proprietor_type_heading'] = gettext("Cautioner")
            elif title['tenure'].upper() == "LEASEHOLD":
                title['proprietor_type_heading'] = gettext("Leaseholder")
            else:
                title['proprietor_type_heading'] = gettext("Owner")

            if len(title['proprietors']) > 1:
                title['proprietor_type_heading'] += "s"

            title[
                'last_changed_readable'] = "This title was last changed on {} at {}".format(
                    template_filters.format_date(title['last_changed']),
                    template_filters.format_time(title['last_changed']))

            receipt = _create_receipt(trans_id, title_number)

            LOGGER.debug("ENDED: _get_title_data")

            return {
                'title': title,
                'is_caution_title': is_caution_title,
                'receipt': receipt,
                'full_title_data': full_title_data
            }

        else:
            raise TitleSummaryViewExpired

    else:
        LOGGER.debug("ENDED: _get_title_data")
        abort(404)
コード例 #6
0
def display_title_pdf(title_number):
    title = _get_register_title(title_number)
    if title:
        full_title_data = api_client.get_official_copy_data(title_number)
        if full_title_data:
            sub_registers = full_title_data.get('official_copy_data',
                                                {}).get('sub_registers')
            if sub_registers:
                html = _create_pdf_template(sub_registers, title, title_number)
                return render_pdf(HTML(string=html))
    abort(404)
コード例 #7
0
def display_title_pdf(title_number):
    LOGGER.debug("STARTED: display_title_pdf title_number: {}".format(title_number))
    if not _should_show_full_title_pdf():
        abort(404)

    title = _get_register_title(title_number)
    if title:
        full_title_data = api_client.get_official_copy_data(title_number)
        full_title_data = _strip_delimiters(full_title_data)
        if full_title_data:
            sub_registers = full_title_data.get('official_copy_data', {}).get('sub_registers')
            if sub_registers:
                html = _create_pdf_template(sub_registers, title, title_number)
                LOGGER.debug("ENDED: display_title_pdf")
                return render_pdf(HTML(string=html))
    LOGGER.debug("ENDED: display_title_pdf")
    abort(404)
コード例 #8
0
def get_title(title_number):
    """
    Show title (result) if user is logged in, has paid and hasn't viewed before.
    """
    LOGGER.debug("STARTED: get_title title_number: {0}".format(title_number))
    title = _get_register_title(title_number)
    username = _username_from_header(request)

    if title and _user_can_view(username, title_number):
        display_page_number = int(request.args.get('page') or 1)
        search_term = request.args.get('search_term', title_number)
        show_pdf = _should_show_full_title_pdf()
        full_title_data = (
            api_client.get_official_copy_data(title_number) if _should_show_full_title_data() else None
        )

        full_title_data = _strip_delimiters(full_title_data)

        LOGGER.debug("Title number{0}".format(title_number))
        auditing.audit("VIEW REGISTER: Title number {0} was viewed by {1}".format(
            title_number,
            username)
        )
        vat_json = {"date": 'N/A',
                    "address1": 'N/A',
                    "address2": 'N/A',
                    "address3": 'N/A',
                    "address4": 'N/A',
                    "postcode": 'N/A',
                    "title_number": 'N/A',
                    "net_amt": 0,
                    "vat_amt": 0,
                    "fee_amt": 0,
                    "vat_num": 'N/A'}

        transId = request.args.get('transid')
        if transId:
            receiptData = api_client.get_invoice_data(transId)
            receiptText = demjson.decode(receiptData.text)
            vat_json = demjson.decode(receiptText['vat_json'])

        receipt = {
            "trans_id": transId,
            "date": vat_json['date'],
            "address1": vat_json['address1'],
            "address2": vat_json['address2'],
            "address3": vat_json['address3'],
            "address4": vat_json['address4'],
            "postcode": vat_json['postcode'],
            "title_number": title_number,
            "net": "{0:.2f}".format(vat_json['net_amt']),
            "vat": "{0:.2f}".format(vat_json['vat_amt']),
            "total": "{0:.2f}".format(vat_json['fee_amt']),
            "reg_number": vat_json['vat_num']
        }

        LOGGER.debug("ENDED: get_title")

        return _title_details_page(title, search_term, show_pdf, full_title_data, request, receipt)

    else:
        LOGGER.debug("ENDED: get_title")
        abort(404)
コード例 #9
0
 def test_get_official_copy_data_returns_none_when_api_returns_404_response(
         self, mock_get):
     result = api_client.get_official_copy_data('title123')
     assert result is None
コード例 #10
0
 def test_get_official_copy_data_returns_json_from_api_when_response_is_200(
         self, mock_get):
     result = api_client.get_official_copy_data('title123')
     assert result == {'some': 'json'}