# Path: account/factories.py
# class AccountFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Account
# 
#     user = factory.SubFactory(UserFactory)
# 
# class RelationshipFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Relationship
# 
#     owner = factory.SubFactory(AccountFactory)
#     follow = factory.SubFactory(AccountFactory)
# 
# DEFAULT_PASSWORD = 'abc@123'


from unittest.mock import patch, MagicMock
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.files.uploadedfile import SimpleUploadedFile
from account.factories import AccountFactory, RelationshipFactory, DEFAULT_PASSWORD
    def test_get_following_anonymous(self):
        response = self.client.get(reverse('following', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_following_logged_in(self):
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.get(reverse('following', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_followers_anonymous(self):
        response = self.client.get(reverse('followers', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_followers_logged_in(self):
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.get(reverse('followers', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_follow_other_user(self):
        user2 = AccountFactory.create().user
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(reverse('account_follow', args=[user2.username]))
        self.assertRedirects(response, reverse('profile', args=[user2.username]))

    def test_follow_following_user(self):
        account2 = AccountFactory.create()

# Path: account/factories.py
# class AccountFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Account
# 
#     user = factory.SubFactory(UserFactory)
# 
# class RelationshipFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Relationship
# 
#     owner = factory.SubFactory(AccountFactory)
#     follow = factory.SubFactory(AccountFactory)
# 
# DEFAULT_PASSWORD = 'abc@123'


# Path: account/tests.py
from unittest.mock import patch, MagicMock
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.core.files.uploadedfile import SimpleUploadedFile
from account.factories import AccountFactory, RelationshipFactory, DEFAULT_PASSWORD

    def test_get_following_anonymous(self):
        response = self.client.get(reverse('following', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_following_logged_in(self):
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.get(reverse('following', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_followers_anonymous(self):
        response = self.client.get(reverse('followers', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_get_followers_logged_in(self):
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.get(reverse('followers', args=[self.user.username]))
        self.assertEqual(response.status_code, 200)
        self.assertTemplateUsed(response, 'account/user.html')

    def test_follow_other_user(self):
        user2 = AccountFactory.create().user
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(reverse('account_follow', args=[user2.username]))
        self.assertRedirects(response, reverse('profile', args=[user2.username]))

    def test_follow_following_user(self):
        account2 = AccountFactory.create()

        RelationshipFactory.create(owner=self.account, follow=account2)