Exemplo n.º 1
0
    def test_bill_repo(self):
        invoice_repo = BillRepo(Invoice)

        invoice = Invoice()
        address = Address()
        address.set_address("Strada Academiei nr. 7")
        address.set_county("Bucuresti")
        address.set_country("Romania")
        address.set_postal_code("010011")
        customer = Customer("Ion", "Radu", "*****@*****.**",
                            "0758245170", address)
        company = Company()
        company.set_address(address)
        company.set_first_name("Plesoiu")
        company.set_last_name("Alexandru")
        company.set_fiscal_no("RO0123")
        company.set_registration_number("123456")
        company.set_company_name("Pleso Academy")
        company.set_fiscal_no("RO2345")
        company.set_registration_number("0000123456789")
        item = BillItem()
        currency = Currency("LEU", "Leu", "RON")
        item.set_name("Water")
        item.set_currency(currency)
        item.set_price(2)
        item.set_discount(0)
        item.set_description("Drinkabale liquid")
        item.set_id(1)
        customer.set_id(1)
        invoice.set_currency(currency)
        invoice.set_items([item])
        invoice.set_total(2)
        invoice.set_issuer(company)
        invoice.set_id(1)
        invoice.set_issue_date("12.12.2020")
        invoice.set_due_date("16.12.2020")
        invoice.set_customer(customer)
        invoice_repo.store(invoice)
        self.assertEqual(invoice_repo.get(1), invoice)
        item.set_quantity(2)
        invoice.set_items([item])
        invoice.set_total(4)
        invoice_repo.update(1, invoice)
        self.assertEqual(invoice_repo.get(1), invoice)
        invoice_repo.delete(1)
        self.assertEqual(invoice_repo.get_all(), [])
        self.assertEqual(invoice_repo.get(69), None)
        try:
            repo = BillRepo("asdas")
            self.assertFalse(True)
        except Exception as exp:
            self.assertFalse(False)

        with self.assertRaises(TypeError):
            invoice_repo.update(1, 1)

        with self.assertRaises(TypeError):
            invoice_repo.store(1)
def get_customerdomain_by_attributes(name, address, xcoord, ycoord):
    customer = BuildingCustomer()
    c = Customer()
    c.name = name
    customer.customer = [c]
    customer.address = address
    customer.xcoord = xcoord
    customer.ycoord = ycoord
    return customer
Exemplo n.º 3
0
def update_customer_by_car_id(customer: Customer):
    sql_text = '''UPDATE user
                     set carModel = '{}',
                         carPhone = '{',
                         userName = '******'
                    WHERE carId = '{}\'''' \
        .format(customer.car_model(), customer.phone(), customer.username(), customer.car_id())

    execute(sql_text)
    def test_output_html_statement(self):
        output = "<h1><em>山田様</em>のレンタル明細</h1><p>\n" + "\t新作\t900円<br>\n" + "\t子供\t150円<br>\n" + "\t一般\t200円<br>\n" + "<p>合計金額 <em>1250円</em><p>\n" + "獲得ポイント <em>4ポイント</em><p>"
        customer = Customer("山田")
        customer.add_rental(self.new_release)
        customer.add_rental(self.children)
        customer.add_rental(self.regular)

        self.assertEqual(output, customer.html_statement())
    def test_output_text_statement(self):
        output = "山田様のレンタル明細\n" + "\t新作\t900円\n" + "\t子供\t150円\n" + "\t一般\t200円\n" + "合計金額 1250円\n" + "獲得ポイント 4ポイント"
        customer = Customer("山田")
        customer.add_rental(self.new_release)
        customer.add_rental(self.children)
        customer.add_rental(self.regular)

        self.assertEqual(output, customer.statement())
Exemplo n.º 6
0
def enter_username_to_block(message):
    username = message.text
    try:
        customer = Customer.construct(username)
        user.person.block_fan_id_card(customer)
        send(
            message, "The Fan ID Card {} was successfully blocked".format(
                customer.fan_id_card.id))
    except CustomerDoesNotExistError:
        send(
            message,
            "Customer with username \"{}\" does not exist. Please enter the username again"
            .format(username), enter_username_to_block)
Exemplo n.º 7
0
 def test_customer_getters(self):
     address = Address()
     address.set_address("Strada Academiei nr. 7")
     address.set_county("Bucuresti")
     address.set_country("Romania")
     address.set_postal_code("010011")
     customer = Customer("Ion", "Radu", "*****@*****.**",
                         "0758245170", address)
     self.assertEqual(customer.get_first_name(), "Ion")
     self.assertEqual(customer.get_last_name(), "Radu")
     self.assertEqual(customer.get_email_address(), "*****@*****.**")
     self.assertEqual(customer.get_phone_number(), "0758245170")
     self.assertEqual(customer.get_address(), address)
Exemplo n.º 8
0
def enter_last_name(message):
    new_customer.last_name = message.text
    customer = Customer(new_customer.username, new_customer.first_name,
                        new_customer.last_name, new_customer.age, None)
    try:
        user.person.register(customer)
        send(
            message, "The customer was successfully registered".format(
                customer.username))
        send(
            message,
            "Username: {}\nPassword: {}".format(customer.username,
                                                customer.password))
    except IncorrectInputFormat as error:
        send(message, error)
    except UserAlreadyExistsError as error:
        send(message, error)
Exemplo n.º 9
0
    def create_statement(self):
        new_release_movie = Movie("新作", NewReleasePrice())

        children_movie = Movie("子供", ChildrenPrice())

        regular_movie = Movie("一般", RegularPrice())

        new_release = Rental(new_release_movie, 3)

        children = Rental(children_movie, 2)

        regular = Rental(regular_movie, 1)

        customer = Customer("山田")

        customer.add_rental(new_release)

        customer.add_rental(children)

        customer.add_rental(regular)

        return customer
Exemplo n.º 10
0
def enter_password(message):
    password = message.text
    if PersonDAO.is_password_correct(user.username, password):
        user.password = password
        user.authenticated = True
        user.role = PersonDAO.get_role_by_username(user.username)
        if user.role == "customer":
            user.person = Customer.construct(user.username)
        elif user.role == "cashier":
            user.person = Cashier.construct(user.username)
        elif user.role == "organizer":
            user.person = Organizer.construct(user.username)
        send(
            message,
            "🟢 You have been successfully logged in as {} {} {} 🟢".
            format(user.role, user.person.first_name,
                   user.person.last_name), show)
    else:
        send(
            message,
            "The entered password is wrong. Enter correct username and password again",
            enter_username)
Exemplo n.º 11
0
 def test_equal(self):
     address = Address()
     address.set_address("Strada Academiei nr. 7")
     address.set_county("Bucuresti")
     address.set_country("Romania")
     address.set_postal_code("010011")
     customer = Customer("Ion", "Radu", "*****@*****.**",
                         "0758245170", address)
     customer2 = copy.deepcopy(customer)
     customer.set_id(1)
     customer2.set_id(2)
     self.assertNotEqual(customer, customer2)
     customer2.set_id(1)
     customer2.set_last_name("Dan")
     self.assertNotEqual(customer, customer2)
     customer2.set_last_name(customer.get_last_name())
     customer2.set_first_name("Pop")
     self.assertNotEqual(customer, customer2)
     customer2.set_first_name(customer.get_first_name())
     customer2.set_email_address("isk")
     self.assertNotEqual(customer, customer2)
     customer2.set_email_address(customer.get_email_address())
     customer2.set_phone_number("dokf")
     self.assertNotEqual(customer, customer2)
Exemplo n.º 12
0
 def read_customer(self, path: str, flag: str):
     header_list, attrs_list = FileReader.read_lines(path, flag, True)
     for attrs in attrs_list:
         customer = Customer(attrs[0], attrs[1])
         self.customers[customer.cust_id] = customer
     return header_list
Exemplo n.º 13
0
def add_customer(customer: Customer):
    sql_text = '''
                INSERT INTO User(userName, carId, carModel, carPhone, createdTime)
                VALUES ('{}', '{}', '{}', '{}', '{}')''' \
        .format(customer.username(), customer.car_id(), customer.car_model(), customer.phone(), customer.create_time())
    return execute(sql_text)
Exemplo n.º 14
0
import hashlib
import re

import psycopg2

from dao.fan_id_card_dao import FanIDCardDAO
from domain.cashier import Cashier
from domain.customer import Customer
from domain.fan_id_card import FanIDCard
from domain.match import Match
from domain.organizer import Organizer
from domain.ticket import SingleTicket

customer = Customer.construct("mario")
organizer = Organizer.construct("cristiano")
cashier = Cashier.construct("slava")
# match = Match(None, "Dortmund", "Sevilla", "2021-03-10", organizer.username, "quarterfinal")
# organizer.add_match(match)
# new_customer = Customer("alexis", "alexis", "sanchez", 29, None)
# cashier.register(new_customer)


def encrypt_password(password):
    return hashlib.md5(password.encode()).hexdigest()


print(encrypt_password("james"))
Exemplo n.º 15
0
    def user(self, keyword, get_data):
        try:
            if self.request.method == 'POST':
                if keyword == "add":
                    try:
                        username = get_data.pop("username")
                        phone = get_data.pop("carPhone")
                        car_model = get_data.pop("carModel")
                        car_id = get_data.pop("carId")
                    except Exception as e:
                        print(e)
                        raise ApiException(ErrorCode.ParameterMiss)

                    customer = Customer()
                    customer.username(username)
                    customer.car_model(car_model)
                    customer.phone(phone)
                    customer.car_id(car_id)
                    customer.create_time(time_utils.get_now())

                    temp_user = customer_handler.get_customer_by_key(
                        "carId", car_id)
                    if temp_user:
                        try:
                            customer_handler.update_customer_by_car_id(
                                customer)
                        except Exception as update_exception:
                            print(update_exception)
                            raise ApiException(ErrorCode.ParameterError)
                        customer_id = temp_user[0][0]
                    else:
                        try:
                            customer_id = customer_handler.add_customer(
                                customer)
                        except Exception as insert_exception:
                            print(insert_exception)
                            raise ApiException(ErrorCode.UserMore)

                    return set_return_dicts({"userId": customer_id})

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

            elif self.request.method == "GET":

                if not self.storeId:
                    raise ApiException(ErrorCode.PCError)

                if keyword == "find":
                    key = get_data.get("key", "")
                    if key not in ["carPhone", "carId"]:
                        raise ApiException(ErrorCode.ParameterError)

                    value = get_data.get("value", "")

                    if self.connect:
                        temp = SocketServer("user {} {} {}".format(
                            self.storeId, key, value))
                        if not temp:
                            temp = self.find_customer(key, value)

                    else:
                        temp = self.find_customer(key, value)
                    result = []
                    key_temp = []
                    if temp == 'restart':
                        raise ApiException(ErrorCode.ReStartPC)
                    else:
                        for data in temp:
                            key = data.get("phone") + data.get(
                                "carId") + data.get("carModel") + data.get(
                                    "userName")
                            if key in key_temp:
                                pass
                            else:
                                result.append(data)
                                key_temp.append(key)

                    return set_return_dicts(result)

                elif keyword == 'order':
                    car_id = get_data.get("carId", "")
                    phone = get_data.get("carPhone", "")

                    if not car_id:
                        raise ApiException(ErrorCode.ParameterMiss)

                    if self.connect:
                        all_order_money = 0.0
                        result = SocketServer("userorder {} {} {}".format(
                            self.storeId, car_id, phone))
                        if result:
                            order_number = len(result)
                            for data in result:
                                all_order_money += data.get("totalPrice")
                        else:
                            result, order_number, all_order_money = self.get_order(
                                car_id)

                    else:
                        result, order_number, all_order_money = self.get_order(
                            car_id)
                    if result == 'restart':
                        raise ApiException(ErrorCode.ReStartPC)
                        # result = []
                    else:
                        print('sort')
                        try:
                            result.sort(key=lambda obj: obj.get('createdTime'),
                                        reverse=True)
                        except Exception as sortE:
                            print(sortE)
                    try:
                        for data in result:
                            print(data)
                            msg = data.get("msg")
                            for msg_data in msg:
                                temp = {}
                                attribute = msg_data.get("attribute")
                                for k, v in attribute.items():
                                    if v != "" and v != "-":
                                        temp[k] = v
                                msg_data['attribute'] = temp
                    except Exception as forException:
                        print(forException)

                    send_msg = {
                        'orderMsg': result,
                        'orderNumber': order_number,
                        'allOrderMoney': all_order_money
                    }
                    print(send_msg)
                    return set_return_dicts(send_msg)

                else:
                    raise ApiException(ErrorCode.ErrorRequest)

        except ApiException as e:
            return set_return_dicts(forWorker=e.error_result['forWorker'],
                                    code=e.error_result['errorCode'],
                                    forUser=e.error_result['forUser'])