예제 #1
0
 def setUp(self):
     CustomerRequestTest.setUp(self)
     self.customer2 = Customer(name="Test two",
                               email="*****@*****.**",
                               phone="222 456 7890",
                               address="Test address 2")
     self.customer2.add()
예제 #2
0
 def setUp(self):
     MyTest.setUp(self)
     self.customer = Customer(name="Test",
                              email="*****@*****.**",
                              phone="123 456 7890",
                              address="Test address")
     self.customer.add()
예제 #3
0
 def setUp(self):
     CustomerValidationTest.setUp(self)
     self.customer2 = Customer(
         name="Test two",
         email="*****@*****.**",
         phone="321 654 0987",
         address="Test address two"
     )
     self.customer2.add()
예제 #4
0
def search_for_customer(form):
    for key in customer_heads:
        customer = Customer.search(form[key])
        if customer:
            return customer

    return None
예제 #5
0
def customers():
    customers = Customer.get_all()
    autocomplete_data = [customer.name for customer in customers]
    placeholder = "Escribe el nombre o el email del cliente que buscas..."
    if request.method == "POST":
        search_term = request.form["search_term"]
        customer = Customer.search(search_term)
        if customer:
            return redirect(url_for('customer.profile', id=customer.id))
        else:
            flash("No se encontró ningún cliente")

    return render_template('customer/customers.html',
                           customers=customers,
                           heads=customer_heads,
                           autocomplete_data=autocomplete_data,
                           placeholder=placeholder)
예제 #6
0
class TestUpdateAttributes(CustomerRequestTest):
    def setUp(self):
        CustomerRequestTest.setUp(self)
        self.customer2 = Customer(name="Test two",
                                  email="*****@*****.**",
                                  phone="222 456 7890",
                                  address="Test address 2")
        self.customer2.add()

    def test_should_update_attributes_given_valid_data(self):
        customer_request = CustomerRequest(self.customer2)
        url = url_for('customer.update', id=self.customer2.id)
        customer_data = dict(name="New Name",
                             email="*****@*****.**",
                             phone="222 456 7890",
                             address="Test address 2")
        with self.request_context(url, customer_data):
            customer_request.update_attributes()

        self.assertEqual(self.customer2.name, "New Name")

    def test_should_update_attributes_given_invalid_data(self):
        customer_request = CustomerRequest(self.customer2)
        url = url_for('customer.update', id=self.customer2.id)
        customer_data = dict(name="Test",
                             email="test.email.com",
                             phone="invalid phone",
                             address="")
        with self.request_context(url, customer_data):
            customer_request.update_attributes()

        self.assertEqual(self.customer.name, "Test")
        self.assertEqual(self.customer2.email, "test.email.com")
        self.assertEqual(self.customer2.phone, "invalid phone")
        self.assertEqual(self.customer2.address, "")

    def test_should_not_save_changes_given_any_data(self):
        customer_request = CustomerRequest(self.customer2)
        url = url_for('customer.update', id=self.customer2.id)
        customer_data = dict(name="New Name")
        with self.request_context(url, customer_data):
            customer_request.update_attributes()
        self.db.session.rollback()

        self.assertEqual(self.customer2.name, "Test two")
 def setUp(self):
     MyTest.setUp(self)
     self.quote = Quote.new(1)
     self.customer = Customer(
         name="Test",
         email="*****@*****.**",
         phone="123 456 7890",
         address="Test address"
     )
     self.customer.add()
     self.product = Product(
         quote_id=1,
         name="Test",
         material="Material",
         acabado="Acabado",
         cristal="Cristal"
     )
     self.product.add()
예제 #8
0
 def __init__(self):
     self.customers = Customer.get_all()
     self.heads = customer_heads
     self.data = self.get_empty_data()
     self.add_data()
     self.names = self.data["name"]
     self.emails = self.data["email"]
     self.phones = self.data["phone"]
     self.addresses = self.data["address"]
예제 #9
0
    def test_should_not_add_customer_given_invalid_customer(self):
        customer = Customer(name="",
                            email="*****@*****.**",
                            phone="123 456 7890",
                            address="Test address")
        customer_request = CustomerRequest(customer)
        customer_request.add()
        self.db.session.rollback()

        self.assertNotIn(customer, self.db.session)
예제 #10
0
    def test_should_return_error_given_repeated_values(self):
        customer = Customer(
            name="Test",
            email="*****@*****.**",
            phone="123 456 7891",
            address="Test address"
        )
        customer_validation = CustomerValidation(customer)
        error = customer_validation.check_for_repeated_values()

        self.assertNotEqual(error, None)
예제 #11
0
def sidebar():
    search_term = request.args["sidebar-search-term"]
    customer = Customer.search(search_term)
    if customer:
        return redirect(
            url_for('customer.profile', id=customer.id)
        )

    return redirect(
        session['prev_uri']
    )
예제 #12
0
    def test_should_not_return_error_given_new_values(self):
        customer = Customer(
            name="Test two",
            email="*****@*****.**",
            phone="222 4444 7777",
            address="Test address two"
        )
        customer_validation = CustomerValidation(customer)
        error = customer_validation.check_for_repeated_values()

        self.assertEqual(error, None)
예제 #13
0
def update(id):
    customer = Customer.get(id)

    if request.method == "POST":
        error = customer.request.update()

        if not error:
            return redirect(url_for('customer.customers'))

        flash(error)

    return render_template('customer/update.html',
                           heads=customer_heads,
                           customer=customer)
예제 #14
0
class TestCheckForRepeatedValue(CustomerValidationTest):

    def setUp(self):
        CustomerValidationTest.setUp(self)
        self.customer2 = Customer(
            name="Test two",
            email="*****@*****.**",
            phone="321 654 0987",
            address="Test address two"
        )
        self.customer2.add()

    def test_should_not_return_error_given_not_repeated_value(self):
        customer_validation = CustomerValidation(self.customer2)
        error = customer_validation.check_for_repeated_value("Test two")

        self.assertEqual(error, None)

    def test_should_return_error_given_repeated_value(self):
        customer_validation = CustomerValidation(self.customer2)
        error = customer_validation.check_for_repeated_value("Test")

        self.assertNotEqual(error, None)
예제 #15
0
def add():
    form = get_form(customer_heads)

    if request.method == 'POST':
        form = get_form(customer_heads)
        customer = Customer(name=form['name'],
                            email=form['email'],
                            phone=form['phone'],
                            address=form['address'])
        error = customer.request.add()

        if not error:
            return redirect(url_for('customer.customers'))

        flash(error)

    return render_template('customer/add.html',
                           heads=customer_heads,
                           form=form)
예제 #16
0
def add():
    form = get_form(customer_heads)
    if request.method == "POST":
        error = None
        customer = search_for_customer(form)
        if not customer:
            customer = Customer(name=form['name'],
                                email=form['email'],
                                phone=form['phone'],
                                address=form['address'])
            error = customer.request.add()
        if not error:
            quote = Quote.new(customer.id)
            return redirect(url_for('quote.edit', id=quote.id))
        flash(error)

    return render_template(
        'quote/add.html',
        form=form,
        customer_heads=customer_heads,
        customer_placeholders=customer_placeholders,
    )
예제 #17
0
def delete(id):
    customer = Customer.get(id)
    customer.delete()

    return redirect(url_for('customer.customers'))
예제 #18
0
def profile(id):
    customer = Customer.get(id)

    return render_template('customer/profile.html', customer=customer)