Skip to content
Snippets Groups Projects
Commit dc1dfd4f authored by Elias Larsen's avatar Elias Larsen
Browse files

validate test passer ikke

parent 5671dd09
No related branches found
No related tags found
1 merge request!4Userserializer automated tests
Pipeline #114683 passed
from django.test import TestCase
from .serializers import UserSerializer
from django.contrib.auth import get_user_model
from rest_framework import serializers
class UserSerializerTestCase(TestCase):
def setUp(self):
self.user_model = get_user_model()
def test_create(self):
data = {
user = self.user_model(
username="test",
email="test@test.com",
phone_number="12345678",
country="Norway",
city="Oslo",
street_address="address 10"
)
password = "password"
user.set_password(password)
user.save()
self.data = {
"username": "testCreate",
"email": "test@test.com",
"password": "1",
......@@ -18,9 +28,25 @@ class UserSerializerTestCase(TestCase):
"city": "Oslo",
"street_address": "address 10"
}
user_create = UserSerializer.create(UserSerializer(), validated_data=data)
self.data1 = {
"username": "testCreate",
"email": "test@test.com",
"password": "",
"password1": "",
"phone_number": "12345678",
"country": "Norway",
"city": "Oslo",
"street_address": "address 10"
}
def test_create(self):
user_create = UserSerializer.create(UserSerializer(), validated_data=self.data)
self.assertEqual(self.user_model.objects.get(username="testCreate"), user_create)
def test_validate_password(self):
response = UserSerializer.validate_password(UserSerializer(), {})
self.assertEqual(response, {})
response = UserSerializer(data=self.data1).validate_password(value="WrongPassword")
self.assertRaises(
serializers.ValidationError,
UserSerializer.validate_password,
UserSerializer(data=self.data1),
response)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment