def test_search_and_attach_cert_invalid(self): setup_mock_response('SearchCerts', '{}') # Invalid data. setup_mock_response('AttachToCert') app = app_factory() cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80' with self.assertRaises(IARCException): search_and_attach_cert(app, cert_id) # Just to make sure we didn't do anything. There should have been only # one call to SearchCerts, none to AttachToCert. eq_(len(responses.calls), 1) eq_(RatingDescriptors.objects.filter(addon=app).exists(), False) eq_(RatingInteractives.objects.filter(addon=app).exists(), False) eq_(IARCCert.objects.filter(app=app).exists(), False) eq_(app.content_ratings.count(), 0)
def test_search_and_attach_cert(self): setup_mock_response('AttachToCert') setup_mock_response('SearchCerts') app = app_factory() cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80' data = search_and_attach_cert(app, cert_id) eq_(data, { 'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None }) eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id)) self.assertSetEqual(app.rating_descriptors.to_keys(), [ 'has_classind_lang', 'has_generic_parental_guidance_recommended', 'has_pegi_parental_guidance_recommended' ]) self.assertSetEqual(app.rating_interactives.to_keys(), [ 'has_shares_location', 'has_digital_purchases', 'has_users_interact' ]) eq_( app.get_content_ratings_by_body(), { 'generic': '12', 'esrb': '13', 'classind': '12', 'usk': '12', 'pegi': 'parental-guidance' })
def save(self, *args, **kwargs): if not self.is_valid(): # Safeguard. raise forms.ValidationError('Invalid Form') if self.cleaned_data['cert_id'] is None: # Dummy rating for local developement without IARC. self.app.set_descriptors([]) self.app.set_interactives([]) self.app.set_content_ratings({ ratingsbodies.ESRB: ratingsbodies.ESRB_E}) return try: search_and_attach_cert(self.app, self.cleaned_data['cert_id']) except IARCException: msg = _('This Certificate ID is not recognized by IARC, or is ' 'already attached to an app in the Firefox Marketplace.') self._errors['cert_id'] = self.error_class([msg]) raise forms.ValidationError(msg)
def save(self, *args, **kwargs): if not self.is_valid(): # Safeguard. raise forms.ValidationError('Invalid Form') if self.cleaned_data['cert_id'] is None: # Dummy rating for local developement without IARC. Existing # IARCCert is no longer relevant and has to be deleted. Since there # is a unique constraint we can't hardcode something like # 00000000-0000-0000-0000-000000000000 and we can't generate a fake # one either, we might call IARC with it later on. IARCCert.objects.filter(app=self.app).delete() self.app.set_descriptors([]) self.app.set_interactives([]) self.app.set_content_ratings({ ratingsbodies.ESRB: ratingsbodies.ESRB_E}) return try: search_and_attach_cert(self.app, self.cleaned_data['cert_id']) except IARCException: self._raise_cert_id_validation_error()
def save(self, *args, **kwargs): if not self.is_valid(): # Safeguard. raise forms.ValidationError('Invalid Form') if self.cleaned_data['cert_id'] is None: # Dummy rating for local developement without IARC. Existing # IARCCert is no longer relevant and has to be deleted. Since there # is a unique constraint we can't hardcode something like # 00000000-0000-0000-0000-000000000000 and we can't generate a fake # one either, we might call IARC with it later on. IARCCert.objects.filter(app=self.app).delete() self.app.set_descriptors([]) self.app.set_interactives([]) self.app.set_content_ratings( {ratingsbodies.ESRB: ratingsbodies.ESRB_E}) return try: search_and_attach_cert(self.app, self.cleaned_data['cert_id']) except IARCException: self._raise_cert_id_validation_error()
def test_search_and_attach_cert_error(self): setup_mock_response('SearchCerts') setup_mock_response('AttachToCert', '{}') # Invalid data. app = app_factory() cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80' with self.assertRaises(IARCException): search_and_attach_cert(app, cert_id) # Both requests were made. eq_(len(responses.calls), 2) eq_(responses.calls[0].request.url, urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'SearchCerts')) eq_(responses.calls[1].request.url, urljoin(settings.IARC_V2_SERVICE_ENDPOINT, 'AttachToCert')) # Just to make sure we didn't save anything. eq_(RatingDescriptors.objects.filter(addon=app).exists(), False) eq_(RatingInteractives.objects.filter(addon=app).exists(), False) eq_(IARCCert.objects.filter(app=app).exists(), False) eq_(app.content_ratings.count(), 0)
def test_search_and_attach_cert(self): setup_mock_response('AttachToCert') setup_mock_response('SearchCerts') app = app_factory() cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80' data = search_and_attach_cert(app, cert_id) eq_(data, {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None}) eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id)) # Note: the mock also contains PEGI_ParentalGuidanceRecommended but we # don't currently map it to a descriptor, because it didn't exist in # v1. eq_(app.rating_descriptors.to_keys(), ['has_classind_lang']) eq_(app.rating_interactives.to_keys(), ['has_shares_location', 'has_digital_purchases', 'has_users_interact']) eq_(app.content_ratings.count(), 5)
def test_search_and_attach_cert(self): setup_mock_response('AttachToCert') setup_mock_response('SearchCerts') app = app_factory() cert_id = 'adb3261b-c657-4fd2-a057-bc9f85310b80' data = search_and_attach_cert(app, cert_id) eq_(data, {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None}) eq_(UUID(app.iarc_cert.cert_id), UUID(cert_id)) self.assertSetEqual( app.rating_descriptors.to_keys(), ['has_classind_lang', 'has_generic_parental_guidance_recommended', 'has_pegi_parental_guidance_recommended']) self.assertSetEqual( app.rating_interactives.to_keys(), ['has_shares_location', 'has_digital_purchases', 'has_users_interact']) eq_(app.get_content_ratings_by_body(), {'generic': '12', 'esrb': '13', 'classind': '12', 'usk': '12', 'pegi': 'parental-guidance'})