def test_url(settings): settings.REDIRECT_HOST = 'www.foo.com' settings.REDIRECT_SECURE = True redirect = Redirect(path='/test', location='https://www.example.com') assert redirect.url == 'https://www.foo.com/test' settings.REDIRECT_HOST = 'www.foo.com' settings.REDIRECT_SECURE = False redirect = Redirect(path='/test', location='https://www.example.com') assert redirect.url == 'http://www.foo.com/test'
def make_redirect(job, business_unit): """Given a job dictionary, make a redirect record Input: :job: A dictionary describing a job. :return: a redirect""" location = "%s-%s" % (job['state_short'], job['city_slab_exact']) # Get or create doesn't support not saving, and Redirects are not valid to # save until new_date is set. guid = '{%s}' % str(uuid.UUID(job['guid'])).upper() try: redirect = Redirect.objects.get(guid=guid) redirect.url = job['link'] redirect.save() return redirect except Redirect.DoesNotExist: logger.debug("Creating new redirect for guid %s", guid) redirect = Redirect(guid=guid, buid=business_unit.id, uid=None, url=job['link'], new_date=job['date_new'], expired_date=None, job_location=location, job_title=job['title_exact'], company_name=job['company']) redirect.save() return redirect
def test_path(): redirect = Redirect.objects.create(path='test', location='https://www.example.com') assert redirect.path == '/test' redirect = Redirect.objects.create(path='/test2', location='https://www.example.com') assert redirect.path == '/test2' with pytest.raises(ValidationError): redirect = Redirect(path='test3?foo=bar', location='https://www.example.com') redirect.full_clean()