# Path: tests/drf/cases.py
# class MongoengineCase(SimpleTestCase):
#     @classmethod
#     def setUpClass(cls):
#         super(MongoengineCase, cls).setUpClass()
#         mongoengine.connection.disconnect()
#         mongoengine.connect('test_djangular')
#         cls.setUpClassData()
# 
#     @classmethod
#     def setUpClassData(cls):
#         pass
# 
#     @classmethod
#     def tearDownClass(cls):
#         connection = mongoengine.connection.get_connection()
#         connection.drop_database('test_djangular')
#         mongoengine.connection.disconnect()
# 
# Path: tests/drf/mocks.py

# 
# Path: authentication/models.py
# class User(AbstractUser):
#     tagline = StringField(max_length=140, required=False)
#     created_at = DateTimeField(default=datetime.utcnow)
#     updated_at = DateTimeField()
# 
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = ['username']


import json
from bson import ObjectId
from django.test.client import Client
from tests.drf.cases import MongoengineCase
from tests.drf.mocks import mock_user1, mock_user2
from authentication.models import User
        response = self.client.post('/api/v1/auth/login/',
                                    data=json.dumps({"email": mock_user2["email"], "password": mock_user2["password"]}),
                                    content_type="application/json")
        self.assertEquals(response.status_code, 200)
        user = json.loads(response.content)
        self.assertEquals(user["username"], mock_user2["username"])
        user["password"] = "new"
        user["confirm_password"] = "new"
        user["tagline"] = "new tagline"
        response = self.client.put('/api/v1/users/%s/' % user["id"], data=json.dumps(user), content_type="application/json")
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'new tagline')
        response = self.client.delete('/api/v1/users/%s/' % user["id"])
        self.assertEquals(response.status_code, 204)

    def test_errors(self):
        response = self.client.get('/api/v1/users/%s/' % ObjectId())
        self.assertEquals(response.status_code, 404)
        response = self.client.post('/api/v1/users/', data=json.dumps({"wrong_data": "sure"}), content_type="application/json")
        self.assertEquals(response.status_code, 400)
        response = self.client.post('/api/v1/auth/login/',
                                    data=json.dumps({"email": mock_user2["email"], "password": mock_user2["password"]}),
                                    content_type="application/json")
        self.assertEquals(response.status_code, 200)
        user = User.objects.get(id=json.loads(response.content)["id"])
        response = self.client.put('/api/v1/users/%s/' % user.id, data=json.dumps({"wrong_data": "sure"}), content_type="application/json")
        self.assertEquals(response.status_code, 400)
        user.is_active = False
        user.save()
        response = self.client.post('/api/v1/auth/login/',

# Path: tests/drf/cases.py
# class MongoengineCase(SimpleTestCase):
#     @classmethod
#     def setUpClass(cls):
#         super(MongoengineCase, cls).setUpClass()
#         mongoengine.connection.disconnect()
#         mongoengine.connect('test_djangular')
#         cls.setUpClassData()
# 
#     @classmethod
#     def setUpClassData(cls):
#         pass
# 
#     @classmethod
#     def tearDownClass(cls):
#         connection = mongoengine.connection.get_connection()
#         connection.drop_database('test_djangular')
#         mongoengine.connection.disconnect()
# 
# Path: tests/drf/mocks.py

# 
# Path: authentication/models.py
# class User(AbstractUser):
#     tagline = StringField(max_length=140, required=False)
#     created_at = DateTimeField(default=datetime.utcnow)
#     updated_at = DateTimeField()
# 
# 
#     USERNAME_FIELD = 'email'
#     REQUIRED_FIELDS = ['username']


# Path: authentication/test.py
import json
from bson import ObjectId
from django.test.client import Client
from tests.drf.cases import MongoengineCase
from tests.drf.mocks import mock_user1, mock_user2
from authentication.models import User

        response = self.client.post('/api/v1/auth/login/',
                                    data=json.dumps({"email": mock_user2["email"], "password": mock_user2["password"]}),
                                    content_type="application/json")
        self.assertEquals(response.status_code, 200)
        user = json.loads(response.content)
        self.assertEquals(user["username"], mock_user2["username"])
        user["password"] = "new"
        user["confirm_password"] = "new"
        user["tagline"] = "new tagline"
        response = self.client.put('/api/v1/users/%s/' % user["id"], data=json.dumps(user), content_type="application/json")
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'new tagline')
        response = self.client.delete('/api/v1/users/%s/' % user["id"])
        self.assertEquals(response.status_code, 204)

    def test_errors(self):
        response = self.client.get('/api/v1/users/%s/' % ObjectId())
        self.assertEquals(response.status_code, 404)
        response = self.client.post('/api/v1/users/', data=json.dumps({"wrong_data": "sure"}), content_type="application/json")
        self.assertEquals(response.status_code, 400)
        response = self.client.post('/api/v1/auth/login/',
                                    data=json.dumps({"email": mock_user2["email"], "password": mock_user2["password"]}),
                                    content_type="application/json")
        self.assertEquals(response.status_code, 200)
        user = User.objects.get(id=json.loads(response.content)["id"])
        response = self.client.put('/api/v1/users/%s/' % user.id, data=json.dumps({"wrong_data": "sure"}), content_type="application/json")
        self.assertEquals(response.status_code, 400)
        user.is_active = False
        user.save()
        response = self.client.post('/api/v1/auth/login/',

                                    data=json.dumps({"email": mock_user2["email"], "password": mock_user2["password"]}),