Пример #1
0
    def create_commercial_customer(self, customer_zip: int, phone_number: str,
                                   email: str, ein: str,
                                   name: str) -> CommercialCustomer:
        """

        :param customer_zip: Customer's zip code of operation
        :param phone_number: Customer's main office or financial office number
        :param email: Customer's main office of financial office email
        :param ein: Customer's EIN
        :param name: Customer's operating name
        """
        customer = CommercialCustomer(create_id(), customer_zip, phone_number,
                                      email, ein, name)

        if self.customer_exists(customer):
            return self.get_customer_by_id(customer.customer_id)

        LOGGER.INFO("CustomerCreation(customer_id=%s)", customer.customer_id)
        self.conn.execute(f"""
            INSERT INTO customers
            VALUES ({customer.customer_id}, DATETIME('now'), '{customer.ein}',
            NULL, '{customer.first_name}', NULL, '{customer.zip}',
            '{customer.phone}', '{customer.email}')
            """)
        self.conn.commit()
        return customer
Пример #2
0
    def create_retail_customer(
        self,
        customer_zip: int,
        phone_number: str,
        email: str,
        ssn: str,
        first_name: str,
        last_name: str,
    ) -> RetailCustomer:
        """
        Creates a customer entry according to information passed in

        :param customer_zip: Zip code associated with customer
        :param phone_number: Phone number associated with customer
        :param email: Email associated with customer
        :param ssn: Social security number for customer
        :param first_name: Customer's first name
        :param last_name: Customer's last name
        """
        customer = RetailCustomer(create_id(), customer_zip, phone_number,
                                  email, ssn, first_name, last_name)

        if self.customer_exists(customer):
            return self.get_customer_by_id(customer.customer_id)

        LOGGER.INFO("CustomerCreation(customer_id=%s)", customer.customer_id)
        self.conn.execute(f"""
            INSERT INTO customers
            VALUES ({customer.customer_id}, DATETIME('now'), NULL, '{customer.ssn}',
            '{customer.first_name}', '{customer.last_name}', '{customer.zip}',
            '{customer.phone}', '{customer.email}')
            """)
        self.conn.commit()
        return customer
Пример #3
0
    def record_entry(self, account: BaseAccount, amount: float) -> None:
        """
        Record entry in ledger table

        :param account: Account associated with ledger entry
        :param amount: Amount to record in ledger
        """
        tx_id = create_id()
        LOGGER.INFO("LedgerEntry(%s, %s)", account.account_id, str(amount))
        self.conn.execute(f"""
            INSERT INTO ledger
            VALUES ({tx_id}, {account.account_id}, DATETIME('now'), {amount})
            """)
        self.conn.commit()
Пример #4
0
    def create_savings_account(self, customer: BaseCustomer,
                               rate: float) -> SavingsAccount:
        acct_id = create_id()
        acct = SavingsAccount(acct_id, customer.customer_id, rate)

        if self.account_exists(acct):
            return self.get_account_by_id(acct_id=acct_id)

        LOGGER.INFO("AccountCreation(account_id=%s)", acct.account_id)
        self.conn.execute(f"""
            INSERT INTO accounts
            VALUES(
                {acct.account_id}, {acct.customer_id}, DATETIME('NOW'), {acct.type}, {acct.rate}
            )
            """)
        self.conn.commit()
        return acct
Пример #5
0
    def create_checking_account(self,
                                customer: BaseCustomer) -> CheckingAccount:
        """
        Creates a record for a new checking account associated
        with the customer passed in

        :param customer: Customer associated with new account
        """

        acct_id = create_id()
        acct = CheckingAccount(acct_id, customer.customer_id)

        if self.account_exists(acct):
            return self.get_account_by_id(acct_id=acct_id)

        LOGGER.INFO("AccountCreation(account_id=%s)", acct.account_id)
        self.conn.execute(f"""
            INSERT INTO accounts
            VALUES(
                {acct.account_id}, {acct.customer_id}, DATETIME('NOW'), {acct.type}, {acct.rate}
            )
            """)
        self.conn.commit()
        return acct
Пример #6
0
def test_reserve_id():
    assert create_id(reserve=True) == "0000000001"
Пример #7
0
def test_non_reserve_id():
    assert create_id(random_seed=42) == "11043321816"
Пример #8
0
def test_random_id():
    rand_id = create_id()

    assert rand_id != "11043321816"
    assert rand_id != "0000000001"
Пример #9
0
 def __init__(self):
     super().__init__(account_id=create_id(reserve=True), customer_id=None)