Ejemplo n.º 1
0
    def test_extract_custom_currency_key(self):
        d = {'price': '7', 'currency': 'zzz'}
        with self.assertRaises(AttributeError):
            e = extract_monetary_amount(d)
            self.assertEqual(e.currency._label, 'Custom Currency')

        e = extract_monetary_amount(d, currency_mapping=CUSTOM_MAPPING)
        self.assertEqual(e.value, 7)
        self.assertEqual(e.currency._label, 'US Dollars')
Ejemplo n.º 2
0
 def test_extract_comma_separated(self):
     e = extract_monetary_amount({'price': '1,280.5', 'currency': 'pounds'})
     self.assertEqual(e.type, 'MonetaryAmount')
     self.assertEqual(e._label, '1,280.50 pounds')
     self.assertEqual(e.value, 1280.50)
     c = e.currency
     self.assertEqual(c.type, 'Currency')
     self.assertEqual(c._label, 'British Pounds')
Ejemplo n.º 3
0
 def test_extract_simple(self):
     e = extract_monetary_amount({'price': '10.0', 'currency': 'pounds'})
     self.assertEqual(e.type, 'MonetaryAmount')
     self.assertEqual(e._label, '10.00 pounds')
     self.assertEqual(e.value, 10)
     c = e.currency
     self.assertEqual(c.type, 'Currency')
     self.assertEqual(c._label, 'British Pounds')
Ejemplo n.º 4
0
	def test_extract_start(self):
		e = extract_monetary_amount({
			'start_price': '8.5',
			'currency': 'pounds'
		})
		self.assertEqual(e.value, 8.5)
		c = e.currency
		self.assertEqual(e.classified_as[0]._label, 'Starting Price')
		self.assertEqual(e.currency._label, 'British Pounds')
Ejemplo n.º 5
0
	def test_extract_est(self):
		e = extract_monetary_amount({
			'est_price': '12.0',
			'currency': 'pounds'
		})
		self.assertEqual(e.value, 12)
		c = e.currency
		self.assertEqual(e.classified_as[0]._label, 'Estimated Price')
		self.assertEqual(e.currency._label, 'British Pounds')
Ejemplo n.º 6
0
	def test_extract_price_with_citation(self):
		d = {
			'price': '7',
			'currency': 'pounds',
			'citation': 'crom test suite'
		}
		e = extract_monetary_amount(d, add_citations=True)
		self.assertEqual(e.value, 7)
		self.assertEqual(e.currency._label, 'British Pounds')
		self.assertEqual(e.referred_to_by[0].content, 'crom test suite')
Ejemplo n.º 7
0
 def test_extract_label_digits(self):
     e = extract_monetary_amount({
         'price': '1,280.5',
         'currency': 'pounds'
     },
                                 truncate_label_digits=4)
     self.assertEqual(e.type, 'MonetaryAmount')
     self.assertEqual(e._label, '1,280.5000 pounds')
     self.assertEqual(e.value, 1280.50)
     c = e.currency
     self.assertEqual(c.type, 'Currency')
     self.assertEqual(c._label, 'British Pounds')