def finalize_response(self, request, response, *args, **kwargs): """Alter response to conform to IARC spec (which is not REST).""" if is_success(response.status_code): # Override data, because IARC wants a specific response and does # not care about our serialized data. response.data = _iarc_app_data(self.object) response.data["StatusCode"] = "Success" else: response.data["StatusCode"] = "InvalidRequest" return super(ContentRatingsPingbackV2, self).finalize_response(request, response, *args, **kwargs)
def finalize_response(self, request, response, *args, **kwargs): """Alter response to conform to IARC spec (which is not REST).""" if is_success(response.status_code): # Override data, because IARC wants a specific response and does # not care about our serialized data. response.data = _iarc_app_data(self.object) response.data['StatusCode'] = 'Success' else: response.data['StatusCode'] = 'InvalidRequest' return super(ContentRatingsPingbackV2, self).finalize_response(request, response, *args, **kwargs)
def test_iarc_app_data(self): self.app = app_factory() self.profile = user_factory() self.app.addonuser_set.create(user=self.profile) eq_(_iarc_app_data(self.app), {'StoreProductID': self.app.guid, 'StoreProductURL': absolutify(self.app.get_url_path()), 'EmailAddress': self.profile.email, 'CompanyName': u'', 'StoreDeveloperID': self.app.pk, 'DeveloperEmail': self.profile.email, 'Publish': True, 'ProductName': unicode(self.app.name)})
def test_attach_to_cert_uuid_hex_string(self): setup_mock_response('AttachToCert') fake_app = app_factory() fake_cert = uuid4() data = _attach_to_cert(fake_app, fake_cert.get_hex()) eq_(data, {'ResultCode': 'Success', 'ErrorMessage': None, 'ErrorID': None}) expected_json = _iarc_app_data(fake_app) expected_json['CertID'] = unicode(fake_cert) eq_(len(responses.calls), 1) eq_(responses.calls[0].request.headers.get('StorePassword'), settings.IARC_V2_STORE_PASSWORD) eq_(responses.calls[0].request.headers.get('StoreID'), settings.IARC_V2_STORE_ID) eq_(json.loads(responses.calls[0].request.body), expected_json)
def test_iarc_app_data_not_public(self): self.app = app_factory() self.profile = user_factory() self.app.addonuser_set.create(user=self.profile) with mock.patch.object(self.app, 'is_public') as is_public_mock: is_public_mock.return_value = False eq_(_iarc_app_data(self.app), {'StoreProductID': self.app.guid, 'StoreProductURL': absolutify(self.app.get_url_path()), 'EmailAddress': self.profile.email, 'CompanyName': u'', 'StoreDeveloperID': self.app.pk, 'DeveloperEmail': self.profile.email, 'Publish': False, 'ProductName': unicode(self.app.name)})
def finalize_response(self, request, response, *args, **kwargs): """Alter response to conform to IARC spec (which is not REST).""" if is_success(response.status_code): # Override data, because IARC wants a specific response and does # not care about our serialized data. response.data = _iarc_app_data(self.object) response.data['StatusCode'] = 'Success' # Delete IARCRequest object now that we've been successful. try: self.object.iarc_request.delete() except IARCRequest.DoesNotExist: pass else: response.data['StatusCode'] = 'InvalidRequest' return super(ContentRatingsPingbackV2, self).finalize_response( request, response, *args, **kwargs)