Example #1
0
    def test_good_request(self):
        user = CustomUser(email="*****@*****.**")
        user.save()

        # check that we can get the page
        client = Client()
        response = client.get("/security/send_login_token/")
        assert response.content.find("form") > -1

        # check that we can get the token
        response = client.post("/security/send_login_token/",
                               {"email": "*****@*****.**"},
                               follow=True)
        assert response.content.find("sent to your email") > 1

        c2 = CustomUser.objects.get(email="*****@*****.**")
        assert c2.login_token is not None
        assert timezone.now() + timedelta(hours=24) > c2.login_token_expires

        # check that we can login using that token and then it is destroyed
        response = client.get("/security/login_with_token/{}/".format(
            c2.login_token),
                              follow=True)
        assert response.content.find("Hello World!") > -1
        assert response.content.find("very wrong") == -1
        c3 = CustomUser.objects.get(email="*****@*****.**")
        assert c3.login_token is None
Example #2
0
    def test_expired_token(TestCase):
        user = CustomUser(email="*****@*****.**")
        user.save()

        # check that we can get the page
        client = Client()
        response = client.get("/security/send_login_token/")
        assert response.content.find("form") > -1

        # set the token back
        c2 = CustomUser.objects.get(email="*****@*****.**")
        c2.login_token_expires = timezone.now() + timedelta(hours=24)
        c2.save()

        response = client.get("/security/login_with_token/{}/".format(c2.login_token), follow=True)
        assert response.content.find("Invalid or expired") > -1
Example #3
0
    def test_expired_token(TestCase):
        user = CustomUser(email="*****@*****.**")
        user.save()

        # check that we can get the page
        client = Client()
        response = client.get("/security/send_login_token/")
        assert response.content.find("form") > -1

        # set the token back
        c2 = CustomUser.objects.get(email="*****@*****.**")
        c2.login_token_expires = timezone.now() + timedelta(hours=24)
        c2.save()

        response = client.get("/security/login_with_token/{}/".format(
            c2.login_token),
                              follow=True)
        assert response.content.find("Invalid or expired") > -1
Example #4
0
    def test_good_request(self):
        user = CustomUser(email="*****@*****.**")
        user.save()

        # check that we can get the page
        client = Client()
        response = client.get("/security/send_login_token/")
        assert response.content.find("form") > -1

        # check that we can get the token
        response = client.post("/security/send_login_token/", {"email": "*****@*****.**"}, follow=True)
        assert response.content.find("sent to your email") > 1

        c2 = CustomUser.objects.get(email="*****@*****.**")
        assert c2.login_token is not None
        assert timezone.now() + timedelta(hours=24) > c2.login_token_expires

        # check that we can login using that token and then it is destroyed
        response = client.get("/security/login_with_token/{}/".format(c2.login_token), follow=True)
        assert response.content.find("Hello World!") > -1
        assert response.content.find("very wrong") == -1
        c3 = CustomUser.objects.get(email="*****@*****.**")
        assert c3.login_token is None