'Tests the _safe_postlogin_redirect function with different values of next'

def test__safe_postlogin_redirect(self):

    HOST = 'testserver'
    ONSITE1 = '/dashboard'
    ONSITE2 = '/courses/org/num/name/courseware'
    ONSITE3 = 'http://{}/my/custom/url'.format(HOST)
    OFFSITE1 = 'http://www.attacker.com'
    for redirect_to in [ONSITE1, ONSITE2, ONSITE3]:
        redir = _safe_postlogin_redirect(redirect_to, HOST)
        self.assertEqual(redir.status_code, 302)
        self.assertEqual(redir['location'], redirect_to)
    redir2 = _safe_postlogin_redirect(OFFSITE1, HOST)
    self.assertEqual(redir2.status_code, 302)
    self.assertEqual('/', redir2['location'])
