Example #1
0
 def test_alphanumeric_case(self):
     alphanumeric_1 = format_price("123.550FAFFA")
     alphanumeric_2 = format_price("asdaKJHJKHFkafsdf")
     alphanumeric_3 = format_price("*(&*(^&*(^@#$&*%^&*$")
     self.assertIsNone(alphanumeric_1)
     self.assertIsNone(alphanumeric_2)
     self.assertIsNone(alphanumeric_3)
Example #2
0
 def test_built_in_datatype_case(self):
     list_type = format_price([1234])
     dict_type = format_price({'price': 1235.895})
     tuple_type = format_price((123.553,))
     self.assertIsNone(list_type)
     self.assertIsNone(dict_type)
     self.assertIsNone(tuple_type)
Example #3
0
 def test_price_format_for_rounded_values(self):
     self.assertEqual('1 234.57', format_price(price=1234.567))
     self.assertEqual(
         '1 234.567',
         format_price(price='1234.567', count_digits_after_point=3),
     )
     self.assertEqual(
         '1 234.568',
         format_price(price=1234.5678, count_digits_after_point=3),
     )
Example #4
0
 def test_price_format_for_small_values(self):
     self.assertEqual('0', format_price(price=0.0049))
     self.assertEqual(
         '0.005',
         format_price(price=0.0049, count_digits_after_point=3),
     )
     self.assertEqual(
         '0.0049',
         format_price(price=0.0049, count_digits_after_point=4),
     )
Example #5
0
 def test_format_price_float(self):
     self.assertEqual(format_price(3245.000001), '3 245')
     self.assertEqual(format_price(3245.678901), '3 245.68')
     self.assertEqual(format_price(3245.670001), '3 245.67')
     self.assertEqual(format_price(1111.978901), '1 111.98')
     self.assertEqual(format_price(0.0049), '0')
     self.assertEqual(format_price(1234.9), '1 234.90')
     self.assertEqual(format_price(3000.00), '3 000')
     self.assertEqual(format_price(10564.113), '10 564.11')
     self.assertEqual(format_price(623401.7867), '623 401.79')
Example #6
0
 def test_incorrect_price_type(self):
     self.assertIsNone(format_price(None))
     self.assertIsNone(format_price(object()))
     self.assertIsNone(format_price(list()))
     self.assertIsNone(format_price(dict()))
     self.assertIsNone(format_price(tuple()))
     self.assertIsNone(format_price(set()))
     self.assertIsNone(format_price(lambda a: a))
     self.assertIsNone(format_price(True))
     self.assertIsNone(format_price(False))
Example #7
0
    def select_product_variants(self, variants_response, product_info):
        descriptions = []
        if product_info:
            descriptions.append("\nDescription: " + product_info)
        product_ids = []
        if (len(variants_response["variant_options"]) > 1):
            for i in xrange(len(variants_response["variant_options"])):
                current_descriptions_list = []
                current_option = variants_response["variant_options"][i]
                for dimension in current_option["dimensions"]:
                    current_descriptions_list.append(dimension["name"] + ": " + dimension["value"])
                if "unit_price" in current_option:
                    current_descriptions_list.append("Price: " + format_price(current_option["unit_price"]))
                product_ids.append(current_option["product_id"])
                descriptions.append(str(i) + ") " + ", ".join(current_descriptions_list))

            prompt = self.build_prompt(self.PROMPTS["select_product_variants"], descriptions)

            description_number = self.prompt(prompt, 
                    ValidationHelpers.validate_number(len(descriptions)-1))
            chosen_product_id = product_ids[int(description_number)]
        else:
            chosen_product_id = variants_response["variant_options"][0]["product_id"]

        quantity = self.get_quantity()
        return [{
                "product_id": chosen_product_id,
                "quantity": quantity
                }]
Example #8
0
    def testAnyData(self):
        def test_func():
            pass

        self.assertEqual(format_price(self.test_list), TypeError)
        self.assertEqual(format_price(self.num_complex), TypeError)
        self.assertEqual(format_price(self.test_dict), TypeError)
        self.assertEqual(format_price(self.test_tuple), TypeError)
        self.assertEqual(format_price(test_func()), TypeError)
        self.assertEqual(format_price(self.test_set), TypeError)
        self.assertEqual(format_price(self.num_negative), ValueError)
        self.assertEqual(format_price(self.fractional_more_three), ValueError)
        self.assertEqual(format_price(self.n), TypeError)
Example #9
0
 def test_positive_integer_price(self):
     self.assertEqual(format_price(1), "1")
     self.assertEqual(format_price(123), "123")
     self.assertEqual(format_price(2018), "2 018")
     self.assertEqual(format_price(30000), "30 000")
     self.assertEqual(format_price(1000000), "1 000 000")
     self.assertEqual(format_price("100"), "100")
     self.assertEqual(format_price("1000"), "1 000")
Example #10
0
 def test_positive_float_price(self):
     self.assertEqual(format_price(1000.0000), "1 000")
     self.assertEqual(format_price(100000.325235), "100 000.33")
     self.assertEqual(format_price(5.1700000), "5.17")
     self.assertEqual(format_price("1000.124500"), "1 000.12")
     self.assertEqual(format_price(pi), "3.14")
     self.assertEqual(format_price(.1), "0.1")
Example #11
0
    def get_place_order(self, response_data):
        self.write_to_zincrc()
        self.print_price_components(response_data)
        if self.prompt_boolean(self.PROMPTS["place_order"]):
            print "\nProcessing request...\n"
            place_order_response = ZincRequestProcessor.process("place_order", {
                        "client_token": self.client_token,
                        "place_order_key": response_data["review_order_response"]["place_order_key"]
                    })

            response_data["place_order_response"] = place_order_response
            print "HOORAY! You've successfully placed an order. Here are the details:\n"
            print "Amazon Order Id: %s" % place_order_response["merchant_order"]["merchant_order_id"]
            print "Total Price: %s" % format_price(place_order_response["price_components"]["total"])
            print place_order_response["shipping_method"]["name"] + ": " + place_order_response["shipping_method"]["description"]
Example #12
0
 def print_price_components(self, response_data):
     components = response_data["review_order_response"]["price_components"]
     self.print_indent("Product Subtotal: %s" % format_price(components["subtotal"]))
     self.print_indent("Shipping Cost:    %s" % format_price(components["shipping"]))
     self.print_indent("Tax:              %s" % format_price(components["tax"]))
     if "gift_certificate" in components:
         self.print_indent("Gift Certificate: %s" % format_price(components["gift_certificate"]))
     if "promotion" in components:
         self.print_indent("Promotion:        %s" % format_price(components["promotion"]))
     self.print_indent("Total:            %s" % format_price(components["total"]))
Example #13
0
    def select_product_name(self, response):
        descriptions = []
        collector = []
        for i in xrange(len(response["results"])):
            current = response["results"][i]
            new_description = str(i) + ") " + current["title"].encode("ascii", "replace")
            if "price" in current:
                new_description += ", " + format_price(current["price"])
            descriptions.append(new_description)
            asin = self.get_asin(current["product_url"])
            collector.append(current["product_url"])

        prompt = self.build_prompt(self.PROMPTS["select_product_name"], descriptions)
        collected_number = self.prompt(prompt,
                ValidationHelpers.validate_number(len(descriptions)-1))
        return collector[int(collected_number)]
Example #14
0
 def test_price_empty(self):
     self.assertIsNone(format_price(''))
Example #15
0
 def test_only_number(self):
     test_value = str('111')
     expected = str(111)
     number = format_price(test_value)
     self.assertEqual(expected, number)
Example #16
0
 def test_one_dot_one_number(self):
     test_value = str('111.2')
     expected = None
     number = format_price(test_value)
     self.assertEqual(expected, number)
Example #17
0
 def test_integer_values(self):
     price = format_price(4245)
     self.assertEqual(price, '4 245')
Example #18
0
 def test_integer_with_nulls(self):
     price = format_price('446,000000')
     self.assertEqual(price, '446')
Example #19
0
 def test_float_values(self):
     price = format_price(3245.42342)
     self.assertIsNotNone(price, '3 245.42')
Example #20
0
 def test_int_var_case(self):
     int_price = format_price(12312)
     self.assertEqual(int_price, "12 312")
Example #21
0
 def test_price_strings_formatting_digit_sparse(self):
     self.assertEqual(format_price('100 000'), '100 000')
Example #22
0
 def test_price_strings_formatting_digit_exp(self):
     self.assertEqual(format_price('25e-1'), '2.50')
Example #23
0
 def test_price_string_bool(self):
     self.assertIsNone(format_price('True'))
Example #24
0
 def test_price_none(self):
     self.assertIsNone(format_price(None))
Example #25
0
 def test_price_digits_float_formatting(self):
     self.assertEqual(format_price(100.), '100')
Example #26
0
 def test_price_strings_formatting_float(self):
     self.assertEqual(format_price('100.00'), '100')
Example #27
0
 def test_price_comma_in_string(self):
     self.assertIsNone(format_price('10.0,0'))
Example #28
0
 def test_one_symbol_one_letter(self):
     test_value = str('a$')
     expected = TypeError
     number = format_price(test_value)
     self.assertRaises(expected, number)
Example #29
0
 def test_float_var_case(self):
     float_price = format_price(234.0431231)
     long_float_price = format_price(546789.964305)
     self.assertEqual(float_price, "234")
     self.assertEqual(long_float_price, "546 790")
Example #30
0
 def test_price_chars_in_string(self):
     self.assertIsNone(format_price('90O'))
Example #31
0
 def test_negative_price(self):
     price = format_price(-56.01)
     self.assertEqual(price, None)
Example #32
0
 def test_price_digits_exp_formatting(self):
     self.assertEqual(format_price(1e2), '100')
Example #33
0
 def test_incorrect_type_values(self):
     price_one = format_price([587.6])
     price_two = format_price((123213, 3213))
     price_three = format_price({'abc'})
     self.assertEqual((price_one, price_two, price_three),
                      (None, None, None))
Example #34
0
    def test_million(self):
        price_origin = '3245245.00000'
        price_expected = '3 245 245'

        self.assertEqual(price_expected, format_price(price_origin))
Example #35
0
 def test_begin_one_dot(self):
     test_value = str('.111')
     expected = None
     number = format_price(test_value)
     self.assertEqual(expected, number)
Example #36
0
    def test_incorrect_value(self):
        incorrect_value = 'test'

        self.assertIsNone(format_price(incorrect_value))
Example #37
0
 def test_two_comma(self):
     test_value = str('111,2,3')
     expected = TypeError
     number = format_price(test_value)
     self.assertRaises(expected, number)
Example #38
0
    def test_simple_number(self):
        price_origin = '3245.000000'
        price_expected = '3 245'

        self.assertEqual(price_expected, format_price(price_origin))
Example #39
0
 def test_one_dot_two_symbols(self):
     test_value = str('11%.@11')
     expected = TypeError
     number = format_price(test_value)
     self.assertRaises(expected, number)
Example #40
0
 def test_price_bool(self):
     self.assertIsNone(format_price(True))
Example #41
0
 def test_one_comma_two_letters(self):
     test_value = str('O.O')
     expected = TypeError
     number = format_price(test_value)
     self.assertRaises(expected, number)
Example #42
0
 def test_price_space(self):
     self.assertIsNone(format_price(' '))