# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase
from django.contrib.auth.models import User
from api import serializers


class RegisterSerializerTest(TestCase):
    """
    Tests all parameters of RegisterSerializer
    """

    def setUp(self):
        self.user = User.objects.create_user(username="testuser", email="<EMAIL>", password="<PASSWORD>",
                                             first_name="Test", last_name="User")

    def test_register_success(self):

        data = {
            'username': 'testuser1',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertTrue(serializer.is_valid())

    def test_register_existing_username(self):
        data = {
            'username': 'testuser',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())

    def test_register_existing_email(self):
        data = {
            'username': 'testuser3',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())

    def test_register_null_username(self):

        data = {
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['username']), 1)

    def test_register_null_email(self):

        data = {
            'username': 'testuser5',
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['email']), 1)

    def test_register_null_password(self):

        data = {
            'username': 'testuser6',
            'email': "<EMAIL>",
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['password']), 1)

    def test_register_null_confirm_password(self):

        data = {
            'username': 'testuser7',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['password_confirm']), 1)

    def test_register_null_first_name(self):

        data = {
            'username': 'testuser8',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['first_name']), 1)

    def test_register_null_last_name(self):

        data = {
            'username': 'testuser9',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['last_name']), 1)

    def test_register_null_incorrect_matching_passwords(self):

        data = {
            'username': 'testuser10',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['non_field_errors']), 1)

# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.test import TestCase
from django.contrib.auth.models import User
from api import serializers


class RegisterSerializerTest(TestCase):
    """
    Tests all parameters of RegisterSerializer
    """

    def setUp(self):
        self.user = User.objects.create_user(username="testuser", email="<EMAIL>", password="<PASSWORD>",
                                             first_name="Test", last_name="User")

    def test_register_success(self):

        data = {
            'username': 'testuser1',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertTrue(serializer.is_valid())

    def test_register_existing_username(self):
        data = {
            'username': 'testuser',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())

    def test_register_existing_email(self):
        data = {
            'username': 'testuser3',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())

    def test_register_null_username(self):

        data = {
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['username']), 1)

    def test_register_null_email(self):

        data = {
            'username': 'testuser5',
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['email']), 1)

    def test_register_null_password(self):

        data = {
            'username': 'testuser6',
            'email': "<EMAIL>",
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['password']), 1)

    def test_register_null_confirm_password(self):

        data = {
            'username': 'testuser7',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['password_confirm']), 1)

    def test_register_null_first_name(self):

        data = {
            'username': 'testuser8',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['first_name']), 1)

    def test_register_null_last_name(self):

        data = {
            'username': 'testuser9',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['last_name']), 1)

    def test_register_null_incorrect_matching_passwords(self):

        data = {
            'username': 'testuser10',
            'email': "<EMAIL>",
            'password': '<PASSWORD>',
            'password_confirm': '<PASSWORD>',
            'first_name': "Test",
            'last_name': "User"
        }

        serializer = serializers.RegisterSerializer(data=data)
        self.assertFalse(serializer.is_valid())
        self.assertEqual(len(serializer.errors['non_field_errors']), 1)

# -*- coding: utf-8 -*- Tests all parameters of RegisterSerializer