# pylint: disable=unused-argument,too-many-arguments,redefined-outer-name
"""
Tests for serializers for profiles REST APIS
"""
import pytest
import factory
from django.core.files.uploadedfile import SimpleUploadedFile
from rest_framework.exceptions import ValidationError

from profiles.factories import UserWebsiteFactory
from profiles.models import Profile, PERSONAL_SITE_TYPE, FACEBOOK_DOMAIN
from profiles.serializers import (
    UserSerializer,
    ProfileSerializer,
    UserWebsiteSerializer,
)

small_gif = (
    b"\x47\x49\x46\x38\x39\x61\x01\x00\x01\x00\x00\x00\x00\x21\xf9\x04"
    b"\x01\x0a\x00\x01\x00\x2c\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02"
    b"\x02\x4c\x01\x00\x3b"
)


def test_serialize_user(user):
    """
    Test serializing a user
    """
    profile = user.profile

    assert UserSerializer(user).data == {
        "id": user.id,
        "username": user.username,
        "profile": {
            "name": profile.name,
            "image": profile.image,
            "image_small": profile.image_small,
            "image_medium": profile.image_medium,
            "image_file": profile.image_file.url,
            "image_small_file": profile.image_small_file.url,
            "image_medium_file": profile.image_medium_file.url,
            "profile_image_small": profile.image_small_file.url,
            "profile_image_medium": profile.image_medium_file.url,
            "bio": profile.bio,
            "headline": profile.headline,
            "username": profile.user.username,
            "placename": profile.location["value"],
        },
    }


def test_serialize_create_user(db, mocker):
    """
    Test creating a user
    """
    profile = {
        "name": "name",
        "image": "image",
        "image_small": "image_small",
        "image_medium": "image_medium",
        "email_optin": True,
        "toc_optin": True,
        "bio": "bio",
        "headline": "headline",
        "placename": "",
    }