Exemple #1
0
 def test_anon_user_register(self):
     """ Testing the correct displaying of the register page when the anonymous user try to create a new account
                                                                     """
     request = self.factory.get(reverse('register'))
     request.user = self.user
     response = register(request)
     self.assertEqual(response.status_code, 200)
Exemple #2
0
    def test_register_citizen(self):
        request = HttpRequest()
        request.method = 'POST'
        request.POST = {
            'id_number': '123456789',
            'password': '******',
            'first_name': 'firstname',
            'last_name': 'lastname',
            'phone_number': '0501234350',
            'email': '*****@*****.**',
            'address': '1234',
        }
        response = register(request)
        self.assertIsInstance(response, HttpResponseRedirect)
        user = Customer.objects.get(username='******')
        self.assertTrue(user.check_password('password'),
                        'Failed to verify password.')
        self.assertEqual(user.first_name, 'firstname')
        self.assertEqual(user.last_name, 'lastname')
        self.assertEqual(user.phone_number, '0501234350')
        self.assertEqual(user.email, '*****@*****.**')
        self.assertEqual(user.address, '1234')

        self.assertFalse(user.is_superuser)
        self.assertFalse(user.is_staff)
        self.assertTrue(user.citizen)
        self.assertFalse(user.secretary)
Exemple #3
0
 def test_register_ok_status(self):
     request = self.factory.get(self.register_url)
     request.session = {}
     request.user = User.objects.create_user('test', 'test.com', 'test')
     response = register(request)
     self.assertEquals(response.status_code, 200)
     print(response.status_code)
     print()
Exemple #4
0
 def test_reject_invalid_registration_data(self):
     request = HttpRequest()
     request.method = 'POST'
     request.POST = {
         'id_number': '12345678b',
         'password': '******',
         'first_name': 'firstname',
         'last_name': 'lastname',
         'phone_number': '0501234350',
         'email': '*****@*****.**',
         'address': '1234',
     }
     response = register(request)
     self.assertNotIsInstance(response, HttpResponseRedirect)
     self.assertEqual(
         Customer.objects.filter(username='******').count(), 0,
         'The user was created.')
Exemple #5
0
    def test_register_post_valid(self):
        path = reverse('register')
        request = self.factory.post(path,
                                    data={
                                        'username': '******',
                                        'email': '*****@*****.**',
                                        'password1': 'hackmehackme',
                                        'password2': 'hackmehackme',
                                    })
        middleware = SessionMiddleware()
        middleware.process_request(request)
        request.session.save()

        middleware = MessageMiddleware()
        middleware.process_request(request)
        request.session.save()

        response = register(request)
        assert response.status_code == 302
        assert reverse('login') in response.url
Exemple #6
0
 def test_register_get_status_code(self):
     path = reverse('register')
     request = RequestFactory().get(path)
     request.method = 'GET'
     response = register(request)
     assert response.status_code == 200
Exemple #7
0
async def create_user(user: validators.RegisterValidator, db: Session = Depends(get_db)):
    return views.register(db, user)
Exemple #8
0
 def test_register_get(self):
     path = reverse('register')
     request = self.factory.get(path)
     response = register(request)
     assert response.status_code == 200
Exemple #9
0
 def test_register_unauthenticated(self):
     path = reverse('register')
     request = self.factory.get(path)
     request.user = AnonymousUser()
     response = register(request)
     assert response.status_code == 200