Esempio n. 1
0
    def test_add_new_user(self):

        # Set site into Site table
        site = Site.objects.get(id=1)
        site.domain = "localhost:8000"
        site.name = "localhost"
        site.save()

        # Set captcha
        captcha = CaptchaStore.objects.get(hashkey=CaptchaStore.generate_key())
        # Set parameters to similate POST
        context = {
            "email": "*****@*****.**",
            'captcha_0': captcha.hashkey,
            'captcha_1': captcha.response
        }
        request = RequestFactory().post(reverse("authentication:login"),
                                        context,
                                        follow=True)

        # Call .views.login()
        login_response = views.login(request)

        # Test good printing of the page
        self.assertInHTML(
            "Un mail est un route pour que vous puissiez confirmer la création de votre compte.",
            login_response.content.decode("utf-8"))

        # Get user and test creation in User table
        try:
            user = User.objects.get(email="*****@*****.**")
            existing_user = True
        except:
            existing_user = False
        self.assertIs(existing_user, True)
def test_login(sample_user, sample_chatter, mock_request_factory,
               fake_password):
    body = json.dumps({
        "username": sample_user.username,
        "password": fake_password
    })
    request = mock_request_factory(method="POST", body=body)
    response = login(request)
    chatter = json.loads(response.content)["chatter"]
    assert chatter == model_to_dict(sample_chatter)
    assert chatter["user"] == sample_user.id
Esempio n. 3
0
def dashboard(request):
    if request.user.is_authenticated():
        # Тут код личного профиля
        args = {}
        args['userprofile'] = request.user
        args['banks'] = Bank.objects.all()
        args.update(csrf(request))
        return render_to_response('dashboard.html', args)
    else:
        # отправляем на аутентификацию и проверяем пользователя
        return login(request)
Esempio n. 4
0
    def test_add_new_user_with_different_mail_with_different_passwords(self):

        # Set site into Site table
        site = Site.objects.get(id=1)
        site.domain = "localhost:8000"
        site.name = "localhost"
        site.save()

        # Add existing user in database
        User.objects.create_user(username="******",
                                 email="*****@*****.**")
        # Test addition of user
        try:
            test_user = User.objects.get(email="*****@*****.**")
            existing_test_user = True
        except:
            existing_test_user = False
        self.assertIs(existing_test_user, True)

        # Set captcha
        captcha = CaptchaStore.objects.get(hashkey=CaptchaStore.generate_key())
        # Set parameters to similate POST
        context = {
            "email": "*****@*****.**",
            'captcha_0': captcha.hashkey,
            'captcha_1': captcha.response,
            'password1': "secret_password",
            'password2': "password_secret",
        }
        request = RequestFactory().post(reverse("authentication:login"),
                                        context,
                                        follow=True)

        # Call .views.login()
        login_response = views.login(request)

        # Test good printing of the page
        self.assertInHTML("Les mots de passe ne sont pas identiques.",
                          login_response.content.decode("utf-8"))

        # Get user and test creation in User table
        try:
            user = User.objects.get(email="*****@*****.**")
            existing_user = True
        except:
            existing_user = False
        self.assertIs(existing_user, False)
Esempio n. 5
0
    def test_two_users_with_same_mail(self):

        # Set site into Site table
        site = Site.objects.get(id=1)
        site.domain = "localhost:8000"
        site.name = "localhost"
        site.save()

        # Add existing user in database
        User.objects.create_user(username="******", email="*****@*****.**")
        User.objects.create_user(username="******", email="*****@*****.**")
        # Test addition of user and that number of users superior to 1
        try:
            test_user_count = User.objects.count()
            test_user = User.objects.filter(email="*****@*****.**")
            existing_test_user = True
        except:
            existing_test_user = False
        self.assertGreaterEqual(test_user_count, 2)
        self.assertIs(existing_test_user, True)

        # Set captcha
        captcha = CaptchaStore.objects.get(hashkey=CaptchaStore.generate_key())
        # Set parameters to similate POST
        context = {
            "email": "*****@*****.**",
            'captcha_0': captcha.hashkey,
            'captcha_1': captcha.response
        }
        request = RequestFactory().post(reverse("authentication:login"),
                                        context,
                                        follow=True)

        # Call .views.login()
        login_response = views.login(request)

        # Test printed error message
        self.assertIn(login_response.content.decode("utf-8"),
                      "Data error: Multiple email addresses found")
Esempio n. 6
0
    def test_add_new_user_with_same_mail(self):

        # Set site into Site table
        site = Site.objects.get(id=1)
        site.domain = "localhost:8000"
        site.name = "localhost"
        site.save()

        # Add existing user in database
        User.objects.create_user(username="******", email="*****@*****.**")
        # Test addition of user
        try:
            test_user = User.objects.get(email="*****@*****.**")
            existing_test_user = True
        except:
            existing_test_user = False
        self.assertIs(existing_test_user, True)

        # Set captcha
        captcha = CaptchaStore.objects.get(hashkey=CaptchaStore.generate_key())
        # Set parameters to similate POST
        context = {
            "email": "*****@*****.**",
            'captcha_0': captcha.hashkey,
            'captcha_1': captcha.response
        }
        request = RequestFactory().post(reverse("authentication:login"),
                                        context,
                                        follow=True)

        # Call .views.login()
        login_response = views.login(request)

        # Test good printing of the page
        self.assertInHTML(
            "Un mail est un route avec un lien magique qui vous permettra de vous connecter.",
            login_response.content.decode("utf-8"))
Esempio n. 7
0
    def test_add_new_user_with_one_password(self):

        # Set site into Site table
        site = Site.objects.get(id=1)
        site.domain = "localhost:8000"
        site.name = "localhost"
        site.save()

        # Set captcha
        captcha = CaptchaStore.objects.get(hashkey=CaptchaStore.generate_key())
        # Set parameters to similate POST
        context = {
            "email": "*****@*****.**",
            'captcha_0': captcha.hashkey,
            'captcha_1': captcha.response,
            'password1': "secret_password",
            'password2': ""
        }
        request = RequestFactory().post(reverse("authentication:login"),
                                        context,
                                        follow=True)

        # Call .views.login()
        login_response = views.login(request)

        # Test good printing of the page
        self.assertInHTML("Veuillez entrer à nouveau le mot de passe.",
                          login_response.content.decode("utf-8"))

        # Get user and test creation in User table
        try:
            user = User.objects.get(email="*****@*****.**")
            existing_user = True
        except:
            existing_user = False
        self.assertIs(existing_user, False)