コード例 #1
0
    def test_should_add_customer(self):
        customer = Customer(customer_name="Test Customer",
                            address="Test dirección",
                            rfc="Opcional RFC")
        customer.add()

        self.assertIn(customer, self.db.session)
コード例 #2
0
class CustomerTest(Test):
    def setUp(self):
        Test.setUp(self)
        self.customer = Customer(customer_name="Test Name",
                                 address="Test Address",
                                 rfc="Test RFC")
        self.customer.add()
コード例 #3
0
ファイル: customer.py プロジェクト: ChrisPoul/Industrias-EnGo
def customers():
    customers = Customer.get_all()
    if request.method == "POST":
        customers = Customer.search_all(request.form["search_term"])

    return render_template('customer/customers.html',
                           customer_heads=customer_heads,
                           customers=customers)
コード例 #4
0
 def setUp(self):
     CustomerTest.setUp(self)
     self.customer2 = Customer(
         customer_name="Name Two",
         address="Address Two",
         rfc="RFC Two"
     )
     self.customer2.add()
コード例 #5
0
 def setUp(self):
     ReceiptTest.setUp(self)
     customer2 = Customer(
         customer_name="Name Two",
         address="Address Two",
         rfc=""
     )
     customer2.add()
     self.create_test_users()
コード例 #6
0
 def setUp(self):
     Test.setUp(self)
     self.customer = Customer(customer_name="Test Name",
                              address="Test Address",
                              rfc="Test RFC")
     self.customer.add()
     self.product_1 = Product(warehouse_id=1, code="Code 1", price=10)
     self.product_1.add()
     self.product_2 = Product(warehouse_id=1, code="Code 2", price=10)
     self.product_2.add()
     self.receipt = Receipt(customer_id=self.customer.id)
     self.receipt.add()
コード例 #7
0
    def test_should_not_return_error_given_valid_phone(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            phone="+442 303 2121")
        error = customer.validation.validate_phone()

        self.assertEqual(error, None)
コード例 #8
0
    def test_should_not_return_error_given_unique_name(self):
        customer = Customer(customer_name="Unique Name",
                            address="Test Address",
                            rfc="TESTRFC 123")
        error = customer.validation.validate_unique_value("customer_name")

        self.assertEqual(error, None)
コード例 #9
0
    def test_should_return_error_given_empty_name(self):
        customer = Customer(customer_name="",
                            address="Test Address",
                            rfc="TESTRFC 123")
        error = customer.validation.validate_empty_values()

        self.assertNotEqual(error, None)
コード例 #10
0
    def test_should_not_return_error_given_empty_rfc(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="")
        error = customer.validation.validate_empty_values()

        self.assertEqual(error, None)
コード例 #11
0
    def test_should_return_error_given_repeated_rfc(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="Test RFC")
        error = customer.validation.validate_unique_values()

        self.assertNotEqual(error, None)
コード例 #12
0
    def test_should_return_error_given_invalid_phone(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            phone="invalid phone")
        error = customer.validation.validate_phone()

        self.assertNotEqual(error, None)
コード例 #13
0
    def test_should_not_return_error_given_valid_customer(self):
        customer = Customer(customer_name="Test Name",
                            address="Test Address",
                            rfc="Unique RFC")
        error = customer.validation.validate()

        self.assertEqual(error, None)
コード例 #14
0
    def test_should_add_customer_given_valid_customer(self):
        customer = Customer(
            customer_name="Valid Name",
            address="Valid Address",
            rfc="Valid RFC"
        )
        customer.request.add()

        self.assertIn(customer, self.db.session)
コード例 #15
0
    def test_should_not_return_error_given_two_customers_with_empty_rfc(self):
        self.customer.rfc = ""
        self.customer.update()
        customer = Customer(customer_name="Valid Name",
                            address="Valid Address",
                            rfc="")
        error = customer.validation.validate_unique_values()

        self.assertEqual(error, None)
コード例 #16
0
    def test_should_add_customer_given_valid_customer_data_and_LUHP(self):
        self.login_user(self.admin_user)
        customer_data = dict(customer_name="Valid Name",
                             address="Valid Address",
                             phone="+123 456 7890",
                             rfc="")
        with self.client as client:
            client.post(url_for('customer.add'), data=customer_data)

        self.assertEqual(len(Customer.get_all()), 2)
コード例 #17
0
    def test_should_not_return_error_given_two_customers_with_empty_name(self):
        self.customer.customer_name = ""
        self.customer.update()
        customer = Customer(customer_name="",
                            address="Valid Address",
                            rfc="Test RFC")
        error = customer.validation.validate_optional_unique_value(
            'customer_name')

        self.assertEqual(error, None)
コード例 #18
0
ファイル: customer.py プロジェクト: ChrisPoul/Industrias-EnGo
def update(id):
    customer = Customer.get(id)
    if request.method == "POST":
        update_obj_attrs(customer, customer_heads)
        error = customer.request.update()
        if not error:
            return redirect(url_for('customer.customers'))
        flash(error)

    return render_template('customer/update.html',
                           customer_heads=customer_heads,
                           customer=customer)
コード例 #19
0
ファイル: customer.py プロジェクト: ChrisPoul/Industrias-EnGo
def receipts(id):
    selected_date_str = ""
    customer = Customer.get(id)
    receipts = customer.receipts
    if request.method == "POST":
        selected_date_str = request.form["selected_date"]
        selected_date = datetime.strptime(selected_date_str, "%Y-%m-%d")
        receipts = filter_receipts_by_date(receipts, selected_date)

    return render_template('customer/receipts.html',
                           receipt_heads=receipt_heads,
                           selected_date=selected_date_str,
                           customer=customer,
                           receipts=receipts)
コード例 #20
0
class TestUpdate(CustomerTest):

    def setUp(self):
        CustomerTest.setUp(self)
        self.customer2 = Customer(
            customer_name="Name Two",
            address="Address Two",
            rfc="RFC Two"
        )
        self.customer2.add()

    def test_should_update_customer_given_valid_change(self):
        self.customer.customer_name = "New Name"
        self.customer.request.update()
        self.db.session.rollback()

        self.assertEqual(self.customer.customer_name, "New Name")

    def test_should_not_update_customer_given_invalid_change(self):
        self.customer2.rfc = "Test RFC"
        self.customer2.request.update()
        self.db.session.rollback()

        self.assertNotEqual(self.customer2.rfc, "Test RFC")
コード例 #21
0
def get_autocomplete_data(group, attribute):
    groups = dict(
        users=User.get_all(),
        products=Product.get_all(),
        customers = Customer.get_all(),
        expenses=Expense.get_all(),
        warehouses=Warehouse.get_all()
    )
    data = []
    for obj in groups[group]:
        value = getattr(obj, attribute)
        if value not in set(data):
            data.append(value)
    
    return data
コード例 #22
0
ファイル: customer.py プロジェクト: ChrisPoul/Industrias-EnGo
def add():
    form = get_form(customer_heads)
    if request.method == 'POST':
        customer = Customer(customer_name=request.form['customer_name'],
                            address=request.form['address'],
                            phone=request.form['phone'],
                            rfc=request.form['rfc'])
        error = customer.request.add()
        if not error:
            return redirect(url_for('customer.customers'))
        flash(error)

    return render_template('customer/add.html',
                           customer_heads=customer_heads,
                           form=form)
コード例 #23
0
 def test_should_add_receipt_and_new_customer_given_valid_customer_data_and_LUHP(self):
     self.login_user(self.admin_user)
     customer_data = dict(
         customer_name="Valid New Name",
         address="Valid Address",
         phone="+123 456 7890"
     )
     prev_receipts = Receipt.get_all()
     with self.client as client:
         client.post(
             url_for('receipt.add'),
             data=customer_data
         )
     
     self.assertNotEqual(len(Receipt.get_all()), len(prev_receipts))
     self.assertEqual(len(Customer.search_all('Valid New Name')), 1)
コード例 #24
0
def search_bar():
    search_term = request.form['search_term']
    try:
        customer = Customer.search_all(search_term)[0]
    except IndexError:
        customer = None
    if customer:
        return redirect(
            url_for("customer.update", id=customer.id)
        )
    user = User.search(search_term)
    if user:
        return redirect(
            url_for("user.profile", id=user.id)
        )
    product = Product.search(search_term)
    if product:
        return redirect(
            url_for("product.update", id=product.id)
        )

    return redirect(
        request.referrer
    )
コード例 #25
0
ファイル: customer.py プロジェクト: ChrisPoul/Industrias-EnGo
def delete(id):
    customer = Customer.get(id)
    customer.delete()

    return redirect(url_for('customer.customers'))
コード例 #26
0
    def test_should_return_customer_given_valid_id(self):
        customer = Customer.get(self.customer.id)

        self.assertEqual(customer, self.customer)
コード例 #27
0
    def test_should_return_none_given_invalid_id(self):
        customer = Customer.get(2)

        self.assertEqual(customer, None)
コード例 #28
0
    def test_should_return_list_of_all_customers(self):
        customers = Customer.get_all()

        self.assertEqual(customers, [self.customer])
コード例 #29
0
    def test_should_return_list_of_customers_given_valid_rfc(self):
        customers = Customer.search_all(self.customer.rfc)

        self.assertEqual(customers, [self.customer])
コード例 #30
0
    def test_should_return_empty_list_given_invalid_search_term(self):
        customer = Customer.search_all("invalid search term")

        self.assertEqual(customer, [])