def test_register_not_matching_password(self):
     data = self._get_register_user_data(password='******',
                                         password_confirm='testpassword2')
     request = self.factory.post('', data)
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)
    def test_register_ok(self):
        data = self._get_register_user_data(password='******')
        request = self.factory.post('', data)
        time_before = math.floor(time.time())
        with self.assert_one_mail_sent() as sent_emails:
            response = register(request)
        time_after = math.ceil(time.time())
        self.assert_valid_response(response, status.HTTP_201_CREATED)
        user_id = response.data['id']
        # Check database state.
        user = self.user_class.objects.get(id=user_id)
        self.assertEqual(user.username, data['username'])
        self.assertTrue(user.check_password(data['password']))
        self.assertFalse(user.is_active)
        # Check verification e-mail.
        sent_email = sent_emails[0]
        self.assertEqual(
            sent_email.from_email,
            REST_REGISTRATION_WITH_VERIFICATION['VERIFICATION_FROM_EMAIL'],
        )
        self.assertListEqual(sent_email.to, [data['email']])
        url = self.assert_one_url_line_in_text(sent_email.body)

        verification_data = self.assert_valid_verification_url(
            url,
            expected_path=REGISTER_VERIFICATION_URL,
            expected_query_keys={'signature', 'user_id', 'timestamp'},
        )
        url_user_id = int(verification_data['user_id'])
        self.assertEqual(url_user_id, user_id)
        url_sig_timestamp = int(verification_data['timestamp'])
        self.assertGreaterEqual(url_sig_timestamp, time_before)
        self.assertLessEqual(url_sig_timestamp, time_after)
        signer = RegisterSigner(verification_data)
        signer.verify()
 def test_register_password_same_as_username(self):
     username = '******'
     data = self._get_register_user_data(username=username,
                                         password=username)
     request = self.factory.post('', data)
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)
    def test_register_same_username(self):
        self.create_test_user(username='******')

        data = self._get_register_user_data(username='******',
                                            password='******')
        request = self.factory.post('', data)
        with self.assert_no_mail_sent():
            response = register(request)
        self.assert_invalid_response(response, status.HTTP_400_BAD_REQUEST)
 def test_register_not_matching_password(self):
     username = '******'
     password = '******'
     request = self.factory.post('', {
         'username': username,
         'password': password,
         'password_confirm': 'blah',
     })
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)
 def test_register_password_same_as_username(self):
     username = '******'
     password = username
     request = self.factory.post('', {
         'username': username,
         'password': password,
         'password_confirm': password,
     })
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)
 def test_register_without_verification_ok(self):
     data = self._get_register_user_data(password='******')
     request = self.factory.post('', data)
     with self.assert_no_mail_sent():
         response = register(request)
     self.assert_valid_response(response, status.HTTP_201_CREATED)
     user_id = response.data['id']
     user = self.user_class.objects.get(id=user_id)
     self.assertEqual(user.username, data['username'])
     self.assertTrue(user.check_password(data['password']))
     self.assertTrue(user.is_active)
 def test_register_ok(self):
     username = '******'
     password = '******'
     request = self.factory.post('', {
         'username': username,
         'password': password,
         'password_confirm': password,
     })
     with self.assert_mail_sent():
         response = register(request)
     self.assert_valid_response(response, status.HTTP_201_CREATED)
     user_id = response.data['id']
     user = self.user_class.objects.get(id=user_id)
     self.assertEqual(user.username, username)
     self.assertTrue(user.check_password(password))
     self.assertFalse(user.is_active)
Example #9
0
def Register(request):
    if request.method == "GET":
        register = register_view.register(request)
        print(register.data)
        return register
 def test_register_password_numeric(self):
     data = self._get_register_user_data(password='******')
     request = self.factory.post('', data)
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)
 def test_register_short_password(self):
     data = self._get_register_user_data(password='******')
     request = self.factory.post('', data)
     with self.assert_no_mail_sent():
         response = register(request)
         self.assert_response_is_bad_request(response)