コード例 #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")
コード例 #7
0
 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)