|
11 | 11 | AddonUser, Category, Flag, Preview) |
12 | 12 | from amo.tests import AMOPaths, app_factory |
13 | 13 | from files.models import FileUpload |
| 14 | +from market.models import Price, AddonPremium |
14 | 15 | from users.models import UserProfile |
15 | 16 |
|
16 | | -from mkt.api.tests.test_oauth import BaseOAuth |
| 17 | +from mkt.api.tests.test_oauth import BaseOAuth, get_absolute_url |
17 | 18 | from mkt.api.base import get_url, list_url |
18 | 19 | from mkt.constants import APP_IMAGE_SIZES, carriers, regions |
| 20 | +from mkt.developers.models import (AddonPaymentAccount, PaymentAccount, |
| 21 | + SolitudeSeller) |
| 22 | +from mkt.developers.tests.test_api import payment_data |
19 | 23 | from mkt.site.fixtures import fixture |
20 | 24 | from mkt.webapps.models import ContentRating, ImageAsset, Webapp |
21 | 25 | from reviews.models import Review |
@@ -533,6 +537,130 @@ def test_put_desktop_error_nice(self): |
533 | 537 | assert '12345' in self.get_error(res)['device_types'][0], ( |
534 | 538 | self.get_error(res)) |
535 | 539 |
|
| 540 | + def test_put_price(self): |
| 541 | + app = self.create_app() |
| 542 | + data = self.base_data() |
| 543 | + Price.objects.create(price='1.07') |
| 544 | + data['premium_type'] = 'premium' |
| 545 | + data['price'] = "1.07" |
| 546 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 547 | + eq_(res.status_code, 202) |
| 548 | + eq_(str(app.addonpremium.price.get_price()), "1.07") |
| 549 | + |
| 550 | + def test_put_premium_inapp(self): |
| 551 | + app = self.create_app() |
| 552 | + data = self.base_data() |
| 553 | + Price.objects.create(price='1.07') |
| 554 | + data['premium_type'] = 'premium-inapp' |
| 555 | + data['price'] = "1.07" |
| 556 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 557 | + eq_(res.status_code, 202) |
| 558 | + eq_(str(app.addonpremium.price.get_price()), "1.07") |
| 559 | + eq_(Webapp.objects.get(pk=app.pk).premium_type, |
| 560 | + amo.ADDON_PREMIUM_INAPP) |
| 561 | + |
| 562 | + def test_put_bad_price(self): |
| 563 | + self.create_app() |
| 564 | + data = self.base_data() |
| 565 | + Price.objects.create(price='1.07') |
| 566 | + Price.objects.create(price='3.14') |
| 567 | + data['premium_type'] = 'premium' |
| 568 | + data['price'] = "2.03" |
| 569 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 570 | + eq_(res.status_code, 400) |
| 571 | + eq_(res.content, |
| 572 | + 'Premium app specified without a valid price. price can be one of ' |
| 573 | + '"1.07", "3.14".') |
| 574 | + |
| 575 | + def test_put_no_price(self): |
| 576 | + self.create_app() |
| 577 | + data = self.base_data() |
| 578 | + Price.objects.create(price='1.07') |
| 579 | + Price.objects.create(price='3.14') |
| 580 | + data['premium_type'] = 'premium' |
| 581 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 582 | + eq_(res.status_code, 400) |
| 583 | + eq_(res.content, |
| 584 | + 'Premium app specified without a valid price. price can be one of ' |
| 585 | + '"1.07", "3.14".') |
| 586 | + |
| 587 | + def test_put_free_inapp(self): |
| 588 | + app = self.create_app() |
| 589 | + data = self.base_data() |
| 590 | + Price.objects.create(price='0.00') |
| 591 | + Price.objects.create(price='3.14') |
| 592 | + data['premium_type'] = 'free-inapp' |
| 593 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 594 | + eq_(res.status_code, 202) |
| 595 | + eq_(str(app.addonpremium.get_price()), "0.00") |
| 596 | + |
| 597 | + @patch('mkt.developers.models.client') |
| 598 | + def test_get_payment_account(self, client): |
| 599 | + client.api.bango.package().get.return_value = {"full": payment_data} |
| 600 | + app = self.create_app() |
| 601 | + app.premium_type = amo.ADDON_PREMIUM |
| 602 | + app.save() |
| 603 | + seller = SolitudeSeller.objects.create(user=self.profile, uuid='uid') |
| 604 | + acct = PaymentAccount.objects.create( |
| 605 | + user=self.profile, solitude_seller=seller, agreed_tos=True, |
| 606 | + seller_uri='uri', uri='uri', bango_package_id=123) |
| 607 | + AddonPaymentAccount.objects.create( |
| 608 | + addon=app, payment_account=acct, set_price=1, |
| 609 | + product_uri="/path/to/app/") |
| 610 | + p = Price.objects.create(price='1.07') |
| 611 | + AddonPremium.objects.create(addon=app, price=p) |
| 612 | + acct_url = get_absolute_url(get_url('account', acct.pk), |
| 613 | + 'payments', False) |
| 614 | + res = self.client.get(self.get_url) |
| 615 | + eq_(res.status_code, 200) |
| 616 | + data = json.loads(res.content) |
| 617 | + eq_(data['payment_account'], acct_url) |
| 618 | + eq_(data['price'], '1.07') |
| 619 | + |
| 620 | + @patch('mkt.developers.models.client') |
| 621 | + def test_put_payment_account(self, client): |
| 622 | + client.api.bango.package().get.return_value = {"full": payment_data} |
| 623 | + app = self.create_app() |
| 624 | + data = self.base_data() |
| 625 | + seller = SolitudeSeller.objects.create(user=self.profile, uuid='uid') |
| 626 | + acct = PaymentAccount.objects.create( |
| 627 | + user=self.profile, solitude_seller=seller, agreed_tos=True, |
| 628 | + seller_uri='uri', uri='uri', bango_package_id=123) |
| 629 | + Price.objects.create(price='1.07') |
| 630 | + data['price'] = "1.07" |
| 631 | + data['premium_type'] = 'premium' |
| 632 | + data['payment_account'] = get_absolute_url(get_url('account', acct.pk), |
| 633 | + 'payments', False) |
| 634 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 635 | + eq_(res.status_code, 202) |
| 636 | + eq_(app.app_payment_account.payment_account.pk, acct.pk) |
| 637 | + |
| 638 | + @patch('mkt.developers.models.client') |
| 639 | + def test_put_payment_account_on_free(self, client): |
| 640 | + client.api.bango.package().get.return_value = {"full": payment_data} |
| 641 | + self.create_app() |
| 642 | + data = self.base_data() |
| 643 | + seller = SolitudeSeller.objects.create(user=self.profile, uuid='uid') |
| 644 | + acct = PaymentAccount.objects.create( |
| 645 | + user=self.profile, solitude_seller=seller, agreed_tos=True, |
| 646 | + seller_uri='uri', uri='uri', bango_package_id=123) |
| 647 | + data['payment_account'] = get_absolute_url(get_url('account', acct.pk), |
| 648 | + 'payments', False) |
| 649 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 650 | + eq_(res.status_code, 400) |
| 651 | + |
| 652 | + def test_put_bogus_payment_account(self): |
| 653 | + app = self.create_app() |
| 654 | + data = self.base_data() |
| 655 | + Price.objects.create(price='1.07') |
| 656 | + data['price'] = "1.07" |
| 657 | + data['premium_type'] = 'premium' |
| 658 | + data['payment_account'] = get_absolute_url(get_url('account', 999), |
| 659 | + 'payments', False) |
| 660 | + res = self.client.put(self.get_url, data=json.dumps(data)) |
| 661 | + eq_(res.status_code, 400) |
| 662 | + assert not hasattr(app, 'app_payment_account') |
| 663 | + |
536 | 664 | def test_put_not_mine(self): |
537 | 665 | obj = self.create_app() |
538 | 666 | obj.authors.clear() |
|
0 commit comments