add tests, rearrange to address review comments (bug 869553)

This commit is contained in:
Allen Short 2013-05-10 19:22:59 -07:00
Родитель 49437a2328
Коммит 022f8f7846
5 изменённых файлов: 61 добавлений и 38 удалений

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

@ -7,7 +7,6 @@ from mkt.api.base import handle_500
from mkt.api.resources import (AppResource, CarrierResource, CategoryResource,
ConfigResource, PreviewResource, RegionResource,
StatusResource, ValidationResource)
from mkt.developers.api import AccountResource
from mkt.ratings.resources import RatingResource
from mkt.search.api import SearchResource, WithFeaturedResource
from mkt.stats.api import GlobalStatsResource
@ -23,8 +22,6 @@ api.register(SearchResource())
api.register(StatusResource())
api.register(RatingResource())
payments = Api(api_name='payments')
payments.register(AccountResource())
stats_api = Api(api_name='stats')
stats_api.register(GlobalStatsResource())
@ -41,7 +38,6 @@ if settings.ALLOW_TASTYPIE_SERVICES:
urlpatterns = patterns('',
url(r'^', include(api.urls)),
url(r'^', include(payments.urls)),
url(r'^', include(stats_api.urls)),
url(r'^', include(services.urls))
)

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

@ -1,10 +1,8 @@
import json
from django import http
import commonware
from curling.lib import HttpClientError, HttpServerError
from tastypie import validation
from tastypie import validation, http
from tastypie.authorization import Authorization
from tastypie.exceptions import ImmediateHttpResponse
from tower import ugettext as _
@ -23,7 +21,7 @@ class AccountResource(MarketplaceModelResource):
form_class=BangoPaymentAccountForm)
queryset = PaymentAccount.objects.all()
list_allowed_methods = ['get', 'post']
detail_allowed_methods = ['get', 'post', 'put', 'delete']
detail_allowed_methods = ['get', 'post', 'put']
authentication = OAuthAuthentication()
authorization = Authorization()
resource_name = 'account'
@ -38,11 +36,10 @@ class AccountResource(MarketplaceModelResource):
request.amo_user, bundle.data)
except HttpClientError as e:
log.error('Client error create Bango account; %s' % e)
raise ImmediateHttpResponse(http.HttpResponse(
json.dumps(e.content), status=400))
raise ImmediateHttpResponse(
http.HttpApplicationError(json.dumps(e.content)))
except HttpServerError as e:
log.error('Error creating Bango payment account; %s' % e)
raise ImmediateHttpResponse(http.HttpResponse(
_(u'Could not connect to payment server.'), status=400))
raise ImmediateHttpResponse(http.HttpApplicationError(
_(u'Could not connect to payment server.')))
return self.full_hydrate(bundle)

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

@ -1,12 +1,36 @@
import json
from curling.lib import HttpClientError, HttpServerError
import mock
from nose.tools import eq_
from mkt.api.tests.test_oauth import BaseOAuth, get_absolute_url
from mkt.api.base import list_url
from mkt.api.tests.test_oauth import BaseOAuth
from mkt.developers.models import PaymentAccount
payment_data = {
'bankAccountPayeeName': 'name',
'companyName': 'company',
'vendorName': 'vendor',
'financeEmailAddress': 'a@a.com',
'adminEmailAddress': 'a@a.com',
'supportEmailAddress': 'a@a.com',
'address1': 'address 1',
'addressCity': 'city',
'addressState': 'state',
'addressZipCode': 'zip',
'addressPhone': '123',
'countryIso': 'BRA',
'currencyIso': 'EUR',
'bankAccountNumber': '123',
'bankAccountCode': '123',
'bankName': 'asd',
'bankAddress1': 'address 2',
'bankAddressZipCode': '123',
'bankAddressIso': 'BRA',
'account_name': 'account'
}
class AccountTests(BaseOAuth):
@ -15,34 +39,29 @@ class AccountTests(BaseOAuth):
@mock.patch('mkt.developers.models.client')
def test_add(self, client):
data = {
'bankAccountPayeeName': 'name',
'companyName': 'company',
'vendorName': 'vendor',
'financeEmailAddress': 'a@a.com',
'adminEmailAddress': 'a@a.com',
'supportEmailAddress': 'a@a.com',
'address1': 'address 1',
'addressCity': 'city',
'addressState': 'state',
'addressZipCode': 'zip',
'addressPhone': '123',
'countryIso': 'BRA',
'currencyIso': 'EUR',
'bankAccountNumber': '123',
'bankAccountCode': '123',
'bankName': 'asd',
'bankAddress1': 'address 2',
'bankAddressZipCode': '123',
'bankAddressIso': 'BRA',
'account_name': 'account'
}
r = self.client.post(list_url('account'),
data=json.dumps(data))
data=json.dumps(payment_data))
eq_(r.status_code, 201)
pa = PaymentAccount.objects.get(name='account')
eq_(pa.user.pk, self.user.pk)
d = client.api.bango.package.post.call_args[1]['data']
for k, v in d.iteritems():
if k not in ['paypalEmailAddress', 'seller']:
eq_(data[k], v)
eq_(payment_data[k], v)
@mock.patch('mkt.developers.models.client')
def test_add_fail(self, client):
err = {'broken': True}
client.api.bango.package.post.side_effect = HttpClientError(
content=err)
r = self.client.post(list_url('account'),
data=json.dumps(payment_data))
eq_(r.status_code, 500)
eq_(json.loads(r.content), err)
@mock.patch('mkt.developers.models.client')
def test_add_fail2(self, client):
client.api.bango.package.post.side_effect = HttpServerError()
r = self.client.post(list_url('account'),
data=json.dumps(payment_data))
eq_(r.status_code, 500)

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

@ -1,10 +1,13 @@
from django import http
from django.conf.urls import include, patterns, url
from tastypie.api import Api
from lib.misc.urlconf_decorator import decorate
import amo
from amo.decorators import write
from mkt.developers.api import AccountResource
from mkt.developers.decorators import use_apps
from mkt.receipts.urls import test_patterns
from mkt.stats.urls import all_apps_stats_patterns
@ -153,3 +156,9 @@ urlpatterns = decorate(write, patterns('',
url('^test/receipts/', include(test_patterns)),
))
payments = Api(api_name='payments')
payments.register(AccountResource())
api_patterns = patterns('',
url(r'^', include(payments.urls)))

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

@ -15,6 +15,7 @@ from mkt.account.urls import (api_patterns as account_api_patterns,
users_patterns as mkt_users_patterns)
from mkt.detail.views import manifest as mini_manifest
from mkt.developers.views import login
from mkt.developers.urls import api_patterns as payments_api_patterns
from mkt.api import oauth
from mkt.home.urls import home_api_patterns
from mkt.purchase.urls import webpay_services_patterns
@ -37,6 +38,7 @@ api_patterns = patterns('',
url('', include(account_api_patterns)),
url('', include(reviewer_api_patterns)),
url('', include('mkt.webpay.urls')),
url('', include(payments_api_patterns)),
url('', include(receipt_api_patterns)),
url('', include('mkt.monolith.urls')),
)