# Path: account/factories.py
# class AccountFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Account
# 
#     user = factory.SubFactory(UserFactory)
# 
# DEFAULT_PASSWORD = 'abc@123'
# 
# Path: link/factories.py
# class PostFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Post
# 
#     owner = factory.SubFactory(AccountFactory)
#     publisher = factory.SubFactory(AccountFactory)
#     url = 'http://test.tst'
#     type = 'html'
#     title = factory.sequence(lambda n: 'Title Link Test {}'.format(n))
#     summary = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
#     text = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
#     image_url = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
# 
# class ReactionFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Reaction
# 
#     owner = factory.SubFactory(AccountFactory)
#     post = factory.SubFactory(PostFactory)


import requests
from unittest.mock import patch
from django.test import TestCase
from django.core.urlresolvers import reverse
from account.factories import AccountFactory, DEFAULT_PASSWORD
from link.factories import PostFactory, ReactionFactory
            </html>
        '''

        mock_req.return_value.headers = {'Content-Type': 'text/html'}
        mock_article.return_value.html = html
        mock_article.return_value.text = html
        mock_article.return_value.publish_date = None

        url_post = 'http://test.fleeg/valid-og-link'
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(reverse('link_new'), data={'url': url_post})
        self.assertRedirects(response, reverse('home'))
        self.assertEqual(self.account.posts.all().count(), 3)

    def test_add_as_my_link_from_post(self):
        url = '{0}?next={1}'.format(reverse('link_add', args=[self.other_user_post.id]),
                                    reverse('home'))
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(url)
        self.assertRedirects(response, reverse('home'))

    def test_react_on_post(self):
        url = '{0}?next={1}'.format(reverse('link_react', args=[self.other_user_post.id]),
                                    reverse('home'))
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(url)
        self.assertRedirects(response, reverse('home'))

    def test_unreact_on_post(self):
        post_with_reaction = PostFactory.create(owner=self.other_user, publisher=self.other_user,)

# Path: account/factories.py
# class AccountFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Account
# 
#     user = factory.SubFactory(UserFactory)
# 
# DEFAULT_PASSWORD = 'abc@123'
# 
# Path: link/factories.py
# class PostFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Post
# 
#     owner = factory.SubFactory(AccountFactory)
#     publisher = factory.SubFactory(AccountFactory)
#     url = 'http://test.tst'
#     type = 'html'
#     title = factory.sequence(lambda n: 'Title Link Test {}'.format(n))
#     summary = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
#     text = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
#     image_url = factory.sequence(lambda n: 'Summary Link Test {}'.format(n))
# 
# class ReactionFactory(factory.DjangoModelFactory):
#     class Meta:
#         model = Reaction
# 
#     owner = factory.SubFactory(AccountFactory)
#     post = factory.SubFactory(PostFactory)


# Path: link/tests.py
import requests
from unittest.mock import patch
from django.test import TestCase
from django.core.urlresolvers import reverse
from account.factories import AccountFactory, DEFAULT_PASSWORD
from link.factories import PostFactory, ReactionFactory

            </html>
        '''

        mock_req.return_value.headers = {'Content-Type': 'text/html'}
        mock_article.return_value.html = html
        mock_article.return_value.text = html
        mock_article.return_value.publish_date = None

        url_post = 'http://test.fleeg/valid-og-link'
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(reverse('link_new'), data={'url': url_post})
        self.assertRedirects(response, reverse('home'))
        self.assertEqual(self.account.posts.all().count(), 3)

    def test_add_as_my_link_from_post(self):
        url = '{0}?next={1}'.format(reverse('link_add', args=[self.other_user_post.id]),
                                    reverse('home'))
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(url)
        self.assertRedirects(response, reverse('home'))

    def test_react_on_post(self):
        url = '{0}?next={1}'.format(reverse('link_react', args=[self.other_user_post.id]),
                                    reverse('home'))
        self.client.login(username=self.user.username, password=DEFAULT_PASSWORD)
        response = self.client.post(url)
        self.assertRedirects(response, reverse('home'))

    def test_unreact_on_post(self):
        post_with_reaction = PostFactory.create(owner=self.other_user, publisher=self.other_user,)

        ReactionFactory.create(owner=self.account, post=post_with_reaction)