Пример #1
0
def webpage():
    if request.method == 'GET':
        return render_template('index.html')
    elif request.method == 'POST':
        sku = request.form['sku']
        price = {"price": parse_price(sku)}
        return render_template('result.html', **price)
Пример #2
0
    def test_parse_price(self):
        """Should return the price as flaot for a good sku given"""
        sku = "del5397184246030"
        result = parse_price(sku)
        self.assertEqual(type(result), float)
        """Should return False for a bad sku given"""
        sku = "zdadzaa"
        result = parse_price(sku)
        self.assertFalse(result)
        """Should return False for a bad sku type given"""
        sku = False
        result = parse_price(sku)
        self.assertFalse(result)

        sku = True
        result = parse_price(sku)
        self.assertFalse(result)

        sku = [1, 2, 3]
        result = parse_price(sku)
        self.assertFalse(result)
    def test_parse_price(self):
        # Test when sku is a string, expect float
        self.assertEqual(type(parse_price("del5397184246030")), float)

        # Tests when sku is not a string, expect False
        self.assertFalse(parse_price(42), False)
        self.assertFalse(parse_price(3.14), False)
        self.assertFalse(parse_price([1, 2, 3, 4]), False)
        self.assertFalse(parse_price(True), False)
        self.assertFalse(parse_price(False), False)
Пример #4
0
def home(sku: str = ''):
    sku = request.args.get('sku')

    if (sku != '' and isinstance(sku, str)):
        product_price = parse_price(sku)

        if isinstance(product_price, float):
            html_price = '''<h1 class='success'>
                ''' + str(product_price) + ''' €</h1>'''
            return render_template('product.html', sku=html_price)
        else:
            error = '''Unable to find a price for the reference
                    "''' + sku + '''".</h2>'''
            return render_template('product.html', error=product_price)

    else:
        if (sku is None):
            return render_template('product.html')
        else:
            error = '''Warning: the passed sku "''' + sku + '''" insn't a
            valid reference'''
            return render_template('product.html', error=error)
Пример #5
0
 def test_result(self):
     """Test le fonctionnement de la fonction 'parse_price'."""
     sku = 'del5397184246030'
     self.assertIsInstance(parse_price(sku), float)
    def test_parse_price_sku_is_not_string(self):
        sku = 52545625
        price = parse_price(sku)

        self.assertEqual(price, "the argument of function isn't a string")
    def test_parse_price_return_float(self):
        sku = "del5397184246030"
        price = parse_price(sku)

        if self.assertIsInstance(sku, str):
            self.assertIsInstance(price, float)
    def test_parse_price_sku_is_not_product_id(self):
        sku = "000000"
        price = parse_price(sku)

        self.assertEqual(price,
                         "The sku you entered is not a product identifier")