# Path: user_management/api/avatar/views.py
# class AvatarAPIViewBase(generics.RetrieveUpdateAPIView):
# class ProfileAvatar(AvatarAPIViewBase):
# class UserAvatar(AvatarAPIViewBase):
#     def post(self, *args, **kwargs):
#     def get_object(self):
#     def delete(self, request, *args, **kwargs):
# 
# Path: user_management/models/tests/factories.py
# class AuthTokenFactory(factory.DjangoModelFactory):
#     key = factory.Sequence('key{}'.format)
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = AuthToken
# 
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Sequence('Test User {}'.format)
#     email = factory.Sequence('email{}@example.com'.format)
#     is_active = True
# 
#     class Meta:
#         model = get_user_model()
# 
#     @factory.post_generation
#     def password(self, create, extracted='default password', **kwargs):
#         self.raw_password = extracted
#         self.set_password(self.raw_password)
#         if create:
#             self.save()
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
#     user_factory = UserFactory


from io import BytesIO
from django.contrib.auth import get_user_model
from django.test.client import Client
from django.urls import reverse
from mock import patch
from PIL import Image
from rest_framework import status
from rest_framework.test import APIRequestFactory, force_authenticate
from user_management.api.avatar import views
from user_management.models.tests.factories import AuthTokenFactory, UserFactory
from user_management.models.tests.utils import APIRequestTestCase

    def test_delete_without_avatar(self):
        user = UserFactory.create()
        request = self.create_request('delete', user=user)
        view = self.view_class.as_view()
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_delete_with_avatar(self):
        user = UserFactory.create(avatar=SIMPLE_PNG)
        request = self.create_request('delete', user=user)
        view = self.view_class.as_view()
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        user = User.objects.get(pk=user.pk)
        self.assertFalse(user.avatar)

    def test_send_without_token_header(self):
        """Test support for legacy browsers that cannot support AJAX uploads.

        This shows three things:
         - users can authenticate by submitting the token in the form data.
         - users can use a POST fallback.
         - csrf is not required (the token is equivalent).
        """
        client = Client(enforce_csrf_checks=True)
        user = UserFactory.create()

# Path: user_management/api/avatar/views.py
# class AvatarAPIViewBase(generics.RetrieveUpdateAPIView):
# class ProfileAvatar(AvatarAPIViewBase):
# class UserAvatar(AvatarAPIViewBase):
#     def post(self, *args, **kwargs):
#     def get_object(self):
#     def delete(self, request, *args, **kwargs):
# 
# Path: user_management/models/tests/factories.py
# class AuthTokenFactory(factory.DjangoModelFactory):
#     key = factory.Sequence('key{}'.format)
#     user = factory.SubFactory(UserFactory)
# 
#     class Meta:
#         model = AuthToken
# 
# class UserFactory(factory.DjangoModelFactory):
#     name = factory.Sequence('Test User {}'.format)
#     email = factory.Sequence('email{}@example.com'.format)
#     is_active = True
# 
#     class Meta:
#         model = get_user_model()
# 
#     @factory.post_generation
#     def password(self, create, extracted='default password', **kwargs):
#         self.raw_password = extracted
#         self.set_password(self.raw_password)
#         if create:
#             self.save()
# 
# Path: user_management/models/tests/utils.py
# class APIRequestTestCase(Python2AssertMixin, BaseAPIRequestTestCase):
#     user_factory = UserFactory


# Path: user_management/api/avatar/tests/test_views.py
from io import BytesIO
from django.contrib.auth import get_user_model
from django.test.client import Client
from django.urls import reverse
from mock import patch
from PIL import Image
from rest_framework import status
from rest_framework.test import APIRequestFactory, force_authenticate
from user_management.api.avatar import views
from user_management.models.tests.factories import AuthTokenFactory, UserFactory
from user_management.models.tests.utils import APIRequestTestCase


    def test_delete_without_avatar(self):
        user = UserFactory.create()
        request = self.create_request('delete', user=user)
        view = self.view_class.as_view()
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

    def test_delete_with_avatar(self):
        user = UserFactory.create(avatar=SIMPLE_PNG)
        request = self.create_request('delete', user=user)
        view = self.view_class.as_view()
        response = view(request)

        self.assertEqual(response.status_code, status.HTTP_204_NO_CONTENT)

        user = User.objects.get(pk=user.pk)
        self.assertFalse(user.avatar)

    def test_send_without_token_header(self):
        """Test support for legacy browsers that cannot support AJAX uploads.

        This shows three things:
         - users can authenticate by submitting the token in the form data.
         - users can use a POST fallback.
         - csrf is not required (the token is equivalent).
        """
        client = Client(enforce_csrf_checks=True)
        user = UserFactory.create()

        token = AuthTokenFactory(user=user)