wire up andy's new 'full' field to the form (bug 834291)

This commit is contained in:
Matt Basta 2013-02-01 18:18:31 -08:00
Родитель 15e7e2a7e3
Коммит dcaf5a13f3
4 изменённых файлов: 31 добавлений и 19 удалений

Просмотреть файл

@ -269,7 +269,10 @@ exports.payment_setup = function() {
$('#id_' + field).val(data[field]);
}
}
);
).fail(function() {
$waiting_overlay.find('h2').text(gettext('Error'));
$waiting_overlay.find('p').text(gettext('There was a problem contacting the payment server.'));
});
};
};

Просмотреть файл

@ -15,6 +15,16 @@ from users.models import UserForeignKey
log = commonware.log.getLogger('z.devhub')
class CurlingHelper(object):
@staticmethod
def uri_to_pk(uri):
"""
Convert a resource URI to the primary key of the resource.
"""
return uri.rstrip('/').split('/')[-1]
class SolitudeSeller(amo.models.ModelBase):
# TODO: When Solitude allows for it, this should be updated to be 1:1 with
# users.
@ -38,7 +48,7 @@ class SolitudeSeller(amo.models.ModelBase):
return obj
class PaymentAccount(amo.models.ModelBase):
class PaymentAccount(CurlingHelper, amo.models.ModelBase):
user = UserForeignKey()
name = models.CharField(max_length=64)
solitude_seller = models.ForeignKey(SolitudeSeller)
@ -120,8 +130,7 @@ class PaymentAccount(amo.models.ModelBase):
acc_ref.addon.update(status=amo.STATUS_NULL)
acc_ref.delete()
# TODO(solitude): Once solitude supports CancelPackage, that goes here.
# ...also, make it a (celery) task.
# TODO(solitude): Make this a celery task.
# We would otherwise have delete(), but we don't want to do that
# without CancelPackage-ing. Once that support is added, we can write a
@ -136,8 +145,12 @@ class PaymentAccount(amo.models.ModelBase):
def get_details(self):
data = {'account_name': self.name}
package_data = client.call_uri(self.uri)
data.update((k, v) for k, v in package_data.items() if
package_data = (client.api
.bango
.package(self.uri_to_pk(self.uri))
.get(data={'full': True}))
data.update((k, v) for k, v in package_data.get('full').items() if
k in self.BANGO_PACKAGE_VALUES)
# TODO(solitude): Someday, we'll want to show existing bank details.
@ -148,7 +161,7 @@ class PaymentAccount(amo.models.ModelBase):
return u'%s - %s' % (self.created.strftime('%m/%y'), self.name)
class AddonPaymentAccount(amo.models.ModelBase):
class AddonPaymentAccount(CurlingHelper, amo.models.ModelBase):
addon = models.OneToOneField(
'addons.Addon', related_name='app_payment_account')
payment_account = models.ForeignKey(PaymentAccount)
@ -165,13 +178,6 @@ class AddonPaymentAccount(amo.models.ModelBase):
class Meta:
db_table = 'addon_payment_account'
@staticmethod
def uri_to_pk(uri):
"""
Convert a resource URI to the primary key of the resource.
"""
return uri.rstrip('/').split('/')[-1]
@classmethod
def create(cls, provider, addon, payment_account):
"""Parameters:

Просмотреть файл

@ -8,11 +8,11 @@
{{ csrf() }}
<div id="bango-account-errors"></div>
<div>
{#
<div class="field">
{{ bango_account_form.bankAccountPayeeName.label_tag() }}
{{ bango_account_form.bankAccountPayeeName }}
</div>
{#
<div class="field no-border">
{{ bango_account_form.bankAccountNumber.label_tag() }}
{{ bango_account_form.bankAccountNumber }}

Просмотреть файл

@ -136,11 +136,13 @@ class TestPaymentAccount(amo.tests.TestCase):
assert not AddonPaymentAccount.objects.exists()
def test_get_details(self):
self.client.call_uri.return_value = {
'vendorName': 'a', 'some_other_value': 'b'}
package = Mock()
package.get.return_value = {'full': {'vendorName': 'a',
'some_other_value': 'b'}}
self.client.api.bango.package.return_value = package
res = PaymentAccount.objects.create(
name='asdf', user=self.user, uri='foo',
name='asdf', user=self.user, uri='/foo/bar/123',
solitude_seller=self.seller)
deets = res.get_details()
@ -148,7 +150,8 @@ class TestPaymentAccount(amo.tests.TestCase):
eq_(deets['vendorName'], 'a')
assert 'some_other_value' not in deets
self.client.call_uri.assert_called_with(res.uri)
self.client.api.bango.package.assert_called_with('123')
package.get.assert_called_with(data={'full': True})
def test_update_account_details(self):
res = PaymentAccount.objects.create(