From d68f3024f1e70d997d3d7c37ec2a3390f5a8e0c0 Mon Sep 17 00:00:00 2001 From: Kevin Ngo Date: Mon, 18 Nov 2013 20:21:02 -0800 Subject: [PATCH] expect one-to-one region-ratingbody to fix tests --- mkt/api/resources.py | 10 ++++------ mkt/api/tests/test_handlers.py | 12 +++++------- mkt/developers/api.py | 4 ++-- mkt/developers/tests/test_api.py | 2 +- mkt/developers/tests/test_forms.py | 12 ++++++------ mkt/developers/tests/test_views_payments.py | 2 +- 6 files changed, 19 insertions(+), 23 deletions(-) diff --git a/mkt/api/resources.py b/mkt/api/resources.py index 73b0a7ad36..bdb4c16e01 100644 --- a/mkt/api/resources.py +++ b/mkt/api/resources.py @@ -378,7 +378,7 @@ class RegionResource(CORSResource, MarketplaceResource): id = fields.IntegerField('id') default_currency = fields.CharField('default_currency') default_language = fields.CharField('default_language') - ratingsbodies = fields.ListField('ratingsbodies') + ratingsbody = fields.CharField('ratingsbody', null=True) class Meta(MarketplaceResource.Meta): detail_allowed_methods = ['get'] @@ -386,8 +386,9 @@ class RegionResource(CORSResource, MarketplaceResource): resource_name = 'region' slug_lookup = 'slug' - def dehydrate_ratingsbodies(self, bundle): - return [rb.name for rb in bundle.obj.ratingsbodies] + def dehydrate_ratingsbody(self, bundle): + if bundle.obj.ratingsbody: + return bundle.obj.ratingsbody.name def obj_get_list(self, request=None, **kwargs): return REGIONS_DICT.values() @@ -407,9 +408,6 @@ class CarrierResource(CORSResource, MarketplaceResource): resource_name = 'carrier' slug_lookup = 'slug' - def dehydrate_ratingsbodies(self, bundle): - return [rb.name for rb in bundle.obj.ratingsbodies] - def obj_get_list(self, request=None, **kwargs): return CARRIERS diff --git a/mkt/api/tests/test_handlers.py b/mkt/api/tests/test_handlers.py index 81f8bee062..012b9cfebc 100644 --- a/mkt/api/tests/test_handlers.py +++ b/mkt/api/tests/test_handlers.py @@ -270,20 +270,18 @@ class TestAppCreateHandler(CreateHandler, AMOPaths): rating = ratingsbodies.CLASSIND_12 app = self.create_app() app.content_ratings.create( - ratings_body=ratingsbodies.CLASSIND.id, - rating=rating.id) + ratings_body=ratingsbodies.CLASSIND.id, rating=rating.id) app.save() res = self.client.get(self.get_url) eq_(res.status_code, 200) data = json.loads(res.content) - cr = data.get('content_ratings') + cr = data.get('content_ratings')['ratings'] self.assertIn('br', cr.keys()) - eq_(len(cr['br']), 1) - eq_(cr['br'][0]['body'], 'CLASSIND') - eq_(cr['br'][0]['name'], rating.name) - eq_(cr['br'][0]['description'], unicode(rating.description)) + eq_(cr['br']['body'], 'CLASSIND') + eq_(cr['br']['rating'], rating.name) + eq_(cr['br']['description'], unicode(rating.description)) def test_dehydrate(self): app = self.create_app() diff --git a/mkt/developers/api.py b/mkt/developers/api.py index ffce6606cf..b235523e95 100644 --- a/mkt/developers/api.py +++ b/mkt/developers/api.py @@ -105,13 +105,13 @@ class ContentRatingSerializer(ModelSerializer): return obj.get_body().name def get_body_slug(self, obj): - return obj.get_body().slug + return obj.get_body().label def get_rating_name(self, obj): return obj.get_rating().name def get_rating_slug(self, obj): - return obj.get_rating().slug + return obj.get_rating().label def get_rating_description(self, obj): return obj.get_rating().description diff --git a/mkt/developers/tests/test_api.py b/mkt/developers/tests/test_api.py index 944301abb0..11b9e0e6d3 100644 --- a/mkt/developers/tests/test_api.py +++ b/mkt/developers/tests/test_api.py @@ -191,7 +191,7 @@ class TestContentRating(amo.tests.TestCase): rating = res['objects'][0] eq_(rating['body_slug'], 'classind') eq_(rating['body_name'], 'CLASSIND') - eq_(rating['name'], '0+') + assert rating['name'] eq_(rating['slug'], '0') assert 'description' in rating diff --git a/mkt/developers/tests/test_forms.py b/mkt/developers/tests/test_forms.py index f27141fb09..e6c5ea4773 100644 --- a/mkt/developers/tests/test_forms.py +++ b/mkt/developers/tests/test_forms.py @@ -239,7 +239,7 @@ class TestRegionForm(amo.tests.WebappTestCase): def test_rated_games_with_content_rating(self): # This game has a government content rating! for region in mkt.regions.ALL_REGIONS_WITH_CONTENT_RATINGS: - rb = region.ratingsbodies[0] + rb = region.ratingsbody ContentRating.objects.create( addon=self.app, ratings_body=rb.id, rating=rb.ratings[0].id) @@ -633,7 +633,7 @@ class TestAdminSettingsForm(TestAdmin): excluded_regions) # Add Brazil content rating. - rb_br = mkt.regions.BR.ratingsbodies[0] + rb_br = mkt.regions.BR.ratingsbody br_0_idx = mkt.ratingsbodies.ALL_RATINGS().index(rb_br.ratings[0]) self.data['app_ratings'] = [br_0_idx] @@ -657,11 +657,11 @@ class TestAdminSettingsForm(TestAdmin): game in Brazil only. """ self.log_in_with('Apps:Configure') - rb_br = mkt.regions.BR.ratingsbodies[0] + rb_br = mkt.regions.BR.ratingsbody ContentRating.objects.create(addon=self.webapp, ratings_body=rb_br.id, rating=rb_br.ratings[0].id) - rb_de = mkt.regions.DE.ratingsbodies[0] + rb_de = mkt.regions.DE.ratingsbody ContentRating.objects.create(addon=self.webapp, ratings_body=rb_de.id, rating=rb_de.ratings[0].id) @@ -693,11 +693,11 @@ class TestAdminSettingsForm(TestAdmin): self.create_switch('iarc') self.log_in_with('Apps:Configure') - rb_br = mkt.regions.BR.ratingsbodies[0] + rb_br = mkt.regions.BR.ratingsbody ContentRating.objects.create(addon=self.webapp, ratings_body=rb_br.id, rating=rb_br.ratings[0].id) - rb_de = mkt.regions.DE.ratingsbodies[0] + rb_de = mkt.regions.DE.ratingsbody ContentRating.objects.create(addon=self.webapp, ratings_body=rb_de.id, rating=rb_de.ratings[0].id) diff --git a/mkt/developers/tests/test_views_payments.py b/mkt/developers/tests/test_views_payments.py index f70e27a5c0..e8baeebdc1 100644 --- a/mkt/developers/tests/test_views_payments.py +++ b/mkt/developers/tests/test_views_payments.py @@ -824,7 +824,7 @@ class TestRegions(amo.tests.TestCase): def test_games_form_enabled_with_content_rating(self): for region in (mkt.regions.BR, mkt.regions.DE): - rb = region.ratingsbodies[0] + rb = region.ratingsbody ContentRating.objects.create( addon=self.webapp, ratings_body=rb.id, rating=rb.ratings[0].id)