fix: reconcile source currencies and retail token pricing
This commit is contained in:
1 parent
ea9069e332
commit
512ca52262
12 files changed
+458
-12
No files matched your search
@@ -0,0 +1,31 @@
|
||||
import unittest
|
||||
from importlib.util import spec_from_file_location, module_from_spec
|
||||
from pathlib import Path
|
||||
|
||||
spec=spec_from_file_location('pricing',Path(__file__).with_name('reconcile-pricing.py'))
|
||||
p=module_from_spec(spec)
|
||||
spec.loader.exec_module(p)
|
||||
|
||||
class PricingTests(unittest.TestCase):
|
||||
def test_cny_no_fx_and_plus_one(self):
|
||||
r=p.retail_price({'input':'.8','output':'2.8','cachedInput':'.23'},'CNY','2')
|
||||
self.assertEqual((r['input'],r['output'],r['cachedInput'],r['discount'],r['exchangeRate']),(.24,.84,.069,3,1))
|
||||
self.assertNotIn('listPriceUsd',r)
|
||||
def test_usd_and_zero(self):
|
||||
r=p.retail_price({'input':'1.25','output':'10','cachedInput':'0'},'USD','2.5')
|
||||
self.assertEqual((r['input'],r['output'],r['cachedInput']),(3.15,25.2,0))
|
||||
self.assertEqual(p.retail_price({'input':1,'output':2},'USD',9)['discount'],10)
|
||||
def test_half_up(self):
|
||||
self.assertEqual(p.retail_price({'input':'.00000001','output':0},'CNY',4)['input'],.00000001)
|
||||
def test_reject_ambiguous(self):
|
||||
for currency,discount in [('RMB',2),('USD',55)]:
|
||||
with self.assertRaises(ValueError):p.retail_price({'input':1,'output':1},currency,discount)
|
||||
def test_dynamic_not_evaluated(self):
|
||||
self.assertIsNone(p.source_rate({'billing_mode':'tiered_expr','billing_expr':'len < 10 ? tier("x",p*1+c*2) : tier("y",p*2+c*4)'}))
|
||||
self.assertEqual(p.source_rate({'billing_mode':'tiered_expr','billing_expr':'tier("standard", p * 10 + c * 50 + cr * 1 + cc * 12.5)'}),{'input':'10','output':'50','cachedInput':'1'})
|
||||
def test_migration_guard(self):
|
||||
sql=p.migration([{'state':'修正','provider':'x','model':'a','oldPricing':{'input':1},'newPricing':{'input':2}}])
|
||||
self.assertIn('m.pricing=c.old_pricing',sql)
|
||||
self.assertNotIn('status=',sql)
|
||||
|
||||
if __name__=='__main__':unittest.main()
|
||||
Reference in new issue
Block a user