示例#1
0
    def confirm_completion(deed_id):
        def update_case_status():
            response = case_api.update_status(deed.id, "Completion confirmed")
            if response.status_code != status.HTTP_200_OK:
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        def update_deed():
            try:
                deed_json = deed.get_json_doc()
                operative_deed = deed_json['operative-deed']
                operative_deed['registrars-signature'] = registrars_signature
                operative_deed['date-effective'] = str(datetime.now())
                deed.json_doc = deed_json
                deed.save()
            except Exception as exc:
                print(str(type(exc)) + ":" + str(exc))
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

        deed = Deed.get(deed_id)
        if deed is None:
            abort(status.HTTP_404_NOT_FOUND)
        if not Deed.registrars_signature_exists(deed.id):
            registrars_signature = request.data['registrars-signature']

            update_deed()
            update_case_status()

            return {'status_code': status.HTTP_200_OK}
        else:
            abort(status.HTTP_403_FORBIDDEN)
示例#2
0
def get_deed_by_token(token_):
    conn = db.session.connection()

    sql = text("SELECT * "
               "FROM deed AS the_deed "
               "WHERE :token in "
               "(SELECT jsonb_array_elements("
               "json_doc -> 'deed' -> 'operative-deed' -> "
               "'borrowers') ->> 'token' "
               "FROM deed WHERE id = the_deed.id)")

    result = conn.execute(sql, token=token_) \
        .fetchall()

    if len(result) > 1:
        raise ValueError(
            'Tokens should be unique however several deeds were found')

    if len(result) == 0:
        return None

    deed = Deed()
    deed.id = result[0]['id']
    deed.json_doc = result[0]['json_doc']

    return deed
示例#3
0
    def _create_deed():
        DeedHelper._id = randint(1, 999999)

        deed = Deed()
        deed.id = DeedHelper._id
        deed.json_doc = DeedHelper._json_doc

        return deed
    def _create_deed():
        DeedHelper._id = randint(1, 999999)

        deed = Deed()
        deed.id = DeedHelper._id
        deed.json_doc = DeedHelper._json_doc

        return deed
示例#5
0
    def get__signed_status(id_):
        all_signed = Deed.get(id_).all_borrowers_signed()
        deed_names = Deed.names_of_all_borrowers_not_signed(id_)

        return {
            'all_signed': all_signed,
            'names': deed_names
        }, status.HTTP_200_OK
    def test_delete(self):
        base_deed = DeedHelper._create_deed_db()
        deed = Deed.get(base_deed.id)

        self.assertEqual(deed.id, DeedHelper._id)

        Deed.delete(deed.id)
        deed = Deed.get(deed.id)

        self.assertIs(deed, None)
    def test_delete_route(self, client):
        deed = DeedHelper._create_deed_db()

        response = client.get('/deed/{}'.format(deed.id))

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        Deed.delete(deed.id)

        response = client.get('/deed/{}'.format(deed.id))

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
    def test_borrower_has_signed(self):
        base_deed = DeedHelper._create_deed_db()
        johns_id = 1

        has_john_signed = Deed.borrower_has_signed(base_deed.id, johns_id)
        self.assertFalse(has_john_signed)

        base_deed.sign_deed(johns_id, 'I am John!')
        base_deed.save()

        has_john_signed = Deed.borrower_has_signed(base_deed.id, johns_id)
        self.assertTrue(has_john_signed)
示例#9
0
    def get(id_):
        deed = Deed.get(id_)

        if deed is None:
            abort(status.HTTP_404_NOT_FOUND)
        else:
            return {'id': deed.id, 'deed': deed.json_doc}, status.HTTP_200_OK
示例#10
0
    def get_with_token(token_):
        deed = Deed.get_deed_by_token(token_)

        if deed is None:
            abort(status.HTTP_404_NOT_FOUND)
        else:
            return {'id': deed.id, 'deed': deed.json_doc}, status.HTTP_200_OK
    def test_get(self):
        base_deed = DeedHelper._create_deed_db()
        deed = Deed.get(base_deed.id)

        self.assertEqual(deed.id, base_deed.id)

        DeedHelper._delete_deed(base_deed.id)
示例#12
0
    def delete(id_):
        try:
            deed = Deed.delete(id_)
        except Exception as inst:
            print(str(type(inst)) + ":" + str(inst))

        if deed is None:
            abort(status.HTTP_404_NOT_FOUND)
        else:
            return {'id': id_}, status.HTTP_200_OK
示例#13
0
    def sign(deed_id, borrower_id):

        deed = Deed.get(deed_id)
        if deed is None:
            abort(status.HTTP_404_NOT_FOUND)

        if Deed.borrower_on(deed_id, borrower_id) and \
                not Deed.borrower_has_signed(deed_id, borrower_id):

            signature = request.json['signature']
            deed.sign_deed(borrower_id, signature)
            try:
                deed.save()
            except Exception as inst:
                print(str(type(inst)) + ":" + str(inst))
                abort(status.HTTP_500_INTERNAL_SERVER_ERROR)

            if deed.all_borrowers_signed():
                case_api.update_status(deed_id, 'Deed signed')
        else:
            abort(status.HTTP_403_FORBIDDEN)

        return {'signature': signature}, status.HTTP_200_OK
    def test_get_deed_by_token(self):
        base_deed = DeedHelper._create_deed_db()

        base_deed_token = \
            base_deed.json_doc["operative-deed"]["borrowers"][0]["token"]

        retrieved_deed_from_token = Deed.get_deed_by_token(base_deed_token)

        self.assertEqual(base_deed.id,
                         retrieved_deed_from_token.id)
        self.assertEqual(base_deed.json_doc,
                         retrieved_deed_from_token.json_doc)

        DeedHelper._delete_deed(base_deed.id)
    def test_names_of_borrowers_signed_and_not(self):
        base_deed = DeedHelper._create_deed_db()
        johns_id = 1

        self.assertListEqual(
            ['John Smith'],
            Deed.names_of_all_borrowers_not_signed(base_deed.id)
        )
        self.assertListEqual(
            [],
            Deed.names_of_all_borrowers_signed(base_deed.id)
        )

        base_deed.sign_deed(johns_id, 'I am John!')
        base_deed.save()

        self.assertListEqual(
            [],
            Deed.names_of_all_borrowers_not_signed(base_deed.id)
        )
        self.assertListEqual(
            ['John Smith'],
            Deed.names_of_all_borrowers_signed(base_deed.id)
        )
示例#16
0
    def _create_deed_db():
        DeedHelper._id = randint(1, 999999)

        deed = Deed()
        deed.id = DeedHelper._id

        new_jdoc = DeedHelper._json_doc

        new_jdoc["borrowers"][0]["token"] = Deed.generate_token()

        new_jdoc = {"operative-deed": new_jdoc}

        deed.json_doc = new_jdoc

        deed.save()

        return deed
示例#17
0
    def create():
        deed = Deed()
        deed_json = request.get_json()

        for borrower in deed_json['borrowers']:
            borrower["token"] = Deed.generate_token()

        json_doc = {
            "operative-deed": {
                "mdref":
                deed_json['mdref'],
                "title":
                deed_json['title'],
                "lender":
                deed_json['lender'],
                "borrowers":
                deed_json['borrowers'],
                "charging-clause":
                "You, the borrower, with full title "
                "guarantee, charge property to the "
                "lender by way of legal mortgage with "
                "the payment of all money secured by this"
                " charge.",
                "effective-clause":
                "This charge takes effect when the "
                "registrar receives notification from "
                "Bailey & Co Solicitors, who prepared "
                "this charge. The effective date and time "
                "is applied by the registrar on "
                "completion.",
                "signatures": [],
                "restrictions":
                deed_json['restrictions'],
                "provisions":
                deed_json['provisions']
            }
        }
        deed.json_doc = json_doc
        try:
            deed.save()
            return {'id': deed.id}, status.HTTP_200_OK
        except Exception as inst:
            print(str(type(inst)) + ":" + str(inst))
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#18
0
    def _create_deed_db():
        DeedHelper._id = randint(1, 999999)

        deed = Deed()
        deed.id = DeedHelper._id

        new_jdoc = DeedHelper._json_doc

        new_jdoc["borrowers"][0]["token"] = Deed.generate_token()

        deed.json_doc = {
            'deed': {
                'operative-deed': new_jdoc,
                "signatures": []
            }
        }

        deed.save()

        return deed
示例#19
0
    def get_names_signed(id_):
        deed_names = Deed.names_of_all_borrowers_signed(id_)

        return {'names': deed_names}, status.HTTP_200_OK
示例#20
0
    def create():
        deed = Deed()
        deed_json = request.get_json()

        json_doc = {
            "deed": {
                "operative-deed": {
                    "mdref": deed_json['mdref'],
                    "lender": deed_json['lender'],
                    "borrowers": [],
                    "charging-clause": "You, the borrower, with full title "
                                       "guarantee, charge property to the "
                                       "lender by way of legal mortgage with "
                                       "the payment of all money secured by "
                                       "this charge.",
                    "effective-clause": "This charge takes effect when the "
                                        "registrar receives notification from "
                                        "Bailey & Co Solicitors, who prepared "
                                        "this charge. The effective date and "
                                        "time is applied by the registrar on "
                                        "completion.",
                    "restrictions": deed_json['restrictions'],
                    "provisions": deed_json['provisions']
                },
                "signatures": []
            }
        }

        borrowers = case_api.get_borrowers(deed_json['case_id']).json()

        for borrower in borrowers:
            def set_name(borrower):
                names = [borrower["first_name"], borrower["middle_names"],
                         borrower["last_name"]]

                # strings return false if they are empty or null,
                # this lambda strips out those
                names_list = list(filter(lambda name: bool(name), names))

                # whats left gets joined together
                full_borrower_name = ' '.join(names_list)
                borrower["name"] = full_borrower_name

            set_name(borrower)
            borrower["token"] = Deed.generate_token()
            json_doc["deed"]["operative-deed"]["borrowers"].append(borrower)

        def extract_title():
            property_ = case_api.get_property(deed_json['case_id']).json()
            return {
                "title-number": property_['title_number'],
                "address": {
                    "street-address": property_['street'],
                    "postal-code": property_['postcode'],
                    "locality": property_['locality'],
                    "extended-address": property_.get('extended')
                }
            }

        title_json = extract_title()

        json_doc["deed"]["operative-deed"]["title"] = title_json

        deed.json_doc = json_doc
        try:
            deed.save()
            return {'id': deed.id}, status.HTTP_200_OK
        except Exception as inst:
            print(str(type(inst)) + ":" + str(inst))
            abort(status.HTTP_500_INTERNAL_SERVER_ERROR)
示例#21
0
 def _delete_deed(_id):
     Deed.delete(_id)