def test_cors_header(self): # Create App to login using token user, packs, sounds = create_user_and_sounds(num_sounds=5, num_packs=1) c = ApiV2Client(user=user, status='OK', redirect_uri="https://freesound.com", url="https://freesound.com", name="test") c.save() sound = sounds[0] sound.change_processing_state("OK") sound.change_moderation_state("OK") headers = { 'HTTP_AUTHORIZATION': 'Token %s' % c.key, 'HTTP_ORIGIN': 'https://www.google.com' } resp = self.client.options(reverse('apiv2-sound-instance', kwargs={'pk': sound.id}), secure=True, **headers) self.assertEqual(resp.status_code, 200) # Check if header is present self.assertEqual(resp['ACCESS-CONTROL-ALLOW-ORIGIN'], '*')
def test_encoding(self): # Create App to login using token user, packs, sounds = create_user_and_sounds(num_sounds=5, num_packs=1) c = ApiV2Client(user=user, status='OK', redirect_uri="https://freesound.com", url="https://freesound.com", name="test") c.save() sound = sounds[0] sound.change_processing_state("OK") sound.change_moderation_state("OK") headers = { 'HTTP_AUTHORIZATION': 'Token %s' % c.key, } # make query that can't be decoded resp = self.client.options( "/apiv2/search/text/?query=ambient&filter=tag:(rain%20OR%CAfe)", secure=True, **headers) self.assertEqual(resp.status_code, 200)