# Path: sequere/tests/celery.py

# 
# Path: sequere/tests/models.py
# class Project(SequereMixin, models.Model):
#     name = models.CharField(max_length=100)
# 
# Path: sequere/app.py
# def get_backend():
# 
# Path: sequere/registry.py
# class SequereRegistry(dict):
#     def __init__(self):
#     def for_model(self, model):
#     def get_identifier(self, instance):
#     def identifiers(self):
#     def unregister(self, name):
#     def register(self, *args, **kwargs):
#     def _register_model(self, model, sequere=None,
#                         name=None, **kwargs):
#     def _register(self, sequere):
# def autodiscover():
# def register(*args, **kwargs):
# 
# Path: sequere/backends/database/models.py
# class Follow(models.Model):
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     from_object_id = models.PositiveIntegerField()
#     from_identifier = models.CharField(max_length=50, db_index=True)
# 
#     to_object_id = models.PositiveIntegerField()
#     to_identifier = models.CharField(max_length=50, db_index=True)
# 
#     is_mutual = models.BooleanField(default=False)
# 
#     objects = FollowManager()
# 
#     class Meta:
#         ordering = ['-created_at', ]
#         app_label = 'sequere'
# 
#     def __str__(self):
#         return '[%s: %d] -> [%s: %d]' % (self.from_identifier,
#                                          self.from_object_id,
#                                          self.to_identifier,
#                                          self.to_object_id)
# 
#     @cached_property
#     def from_instance(self):
#         model = registry.identifiers.get(self.from_identifier)
# 
#         return model.objects.get(pk=self.from_object_id)
# 
#     @cached_property
#     def to_instance(self):
#         model = registry.identifiers.get(self.to_identifier)
# 
#         return model.objects.get(pk=self.to_object_id)


import json
from .celery import app as celery_app  # noqa
from django.test.utils import override_settings
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.conf import settings
from datetime import datetime, timedelta
from exam.decorators import fixture
from exam.cases import Exam
from .models import Project
from sequere import app
from sequere.backends.redis import RedisBackend
from sequere.registry import registry
from sequere.backends.database.models import Follow
        from ..compat import User
        from ..compat import User
        from ..models import follow, get_followings_count, get_followers_count
        from ..models import (follow, get_followings_count,
                              get_followers_count, unfollow)
        from ..models import (follow, get_friends_count,
                              unfollow)
        from ..models import (follow, unfollow, is_following)
        from ..models import follow, get_followers
        from ..models import follow, get_followings
        from ..models import follow
        from ..models import follow
        from .sequere_registry import JoinAction, User
        from sequere.contrib.timeline import Timeline
        from sequere.contrib.timeline import Timeline
        from ..models import (follow, unfollow)
        from .sequere_registry import JoinAction, LikeAction, Project
        from sequere.contrib.timeline import Timeline
        from .sequere_registry import JoinAction, LikeAction
        from sequere.contrib.timeline import get_actions
        from ..models import follow, unfollow
        from .sequere_registry import JoinAction
        from sequere.contrib.timeline import Timeline

        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content.decode())

        self.assertEqual(content['followings_count'], 0)
        self.assertEqual(content['%s_followings_count' % identifier], 0)


@override_settings(SEQUERE_BACKEND='sequere.backends.database.DatabaseBackend')
class DatabaseBackendTests(BaseBackendTests, TestCase):
    def test_from_instance_and_to_instance(self):

        follow(self.user, self.project)

        instance = Follow.objects.all()[0]

        self.assertEqual(instance.to_instance, self.project)
        self.assertEqual(instance.from_instance, self.user)


@override_settings(SEQUERE_TIMELINE_IMPORT_ACTIONS_ON_FOLLOW=True,
                   SEQUERE_TIMELINE_REMOVE_ACTIONS_ON_UNFOLLOW=True,
                   INSTALLED_APPS=settings.INSTALLED_APPS + ['sequere.contrib.timeline', ],
                   SEQUERE_TIMELINE_BACKEND='sequere.contrib.timeline.backends.redis.RedisBackend')
class TimelineTests(FixturesMixin, TestCase):
    def setUp(self):
        super(TimelineTests, self).setUp()

        app.backend = RedisBackend()

# Path: sequere/tests/celery.py

# 
# Path: sequere/tests/models.py
# class Project(SequereMixin, models.Model):
#     name = models.CharField(max_length=100)
# 
# Path: sequere/app.py
# def get_backend():
# 
# Path: sequere/registry.py
# class SequereRegistry(dict):
#     def __init__(self):
#     def for_model(self, model):
#     def get_identifier(self, instance):
#     def identifiers(self):
#     def unregister(self, name):
#     def register(self, *args, **kwargs):
#     def _register_model(self, model, sequere=None,
#                         name=None, **kwargs):
#     def _register(self, sequere):
# def autodiscover():
# def register(*args, **kwargs):
# 
# Path: sequere/backends/database/models.py
# class Follow(models.Model):
#     created_at = models.DateTimeField(auto_now_add=True)
# 
#     from_object_id = models.PositiveIntegerField()
#     from_identifier = models.CharField(max_length=50, db_index=True)
# 
#     to_object_id = models.PositiveIntegerField()
#     to_identifier = models.CharField(max_length=50, db_index=True)
# 
#     is_mutual = models.BooleanField(default=False)
# 
#     objects = FollowManager()
# 
#     class Meta:
#         ordering = ['-created_at', ]
#         app_label = 'sequere'
# 
#     def __str__(self):
#         return '[%s: %d] -> [%s: %d]' % (self.from_identifier,
#                                          self.from_object_id,
#                                          self.to_identifier,
#                                          self.to_object_id)
# 
#     @cached_property
#     def from_instance(self):
#         model = registry.identifiers.get(self.from_identifier)
# 
#         return model.objects.get(pk=self.from_object_id)
# 
#     @cached_property
#     def to_instance(self):
#         model = registry.identifiers.get(self.to_identifier)
# 
#         return model.objects.get(pk=self.to_object_id)


# Path: sequere/tests/tests.py
import json
from .celery import app as celery_app  # noqa
from django.test.utils import override_settings
from django.test import TestCase
from django.core.urlresolvers import reverse
from django.conf import settings
from datetime import datetime, timedelta
from exam.decorators import fixture
from exam.cases import Exam
from .models import Project
from sequere import app
from sequere.backends.redis import RedisBackend
from sequere.registry import registry
from sequere.backends.database.models import Follow
        from ..compat import User
        from ..compat import User
        from ..models import follow, get_followings_count, get_followers_count
        from ..models import (follow, get_followings_count,
                              get_followers_count, unfollow)
        from ..models import (follow, get_friends_count,
                              unfollow)
        from ..models import (follow, unfollow, is_following)
        from ..models import follow, get_followers
        from ..models import follow, get_followings
        from ..models import follow
        from ..models import follow
        from .sequere_registry import JoinAction, User
        from sequere.contrib.timeline import Timeline
        from sequere.contrib.timeline import Timeline
        from ..models import (follow, unfollow)
        from .sequere_registry import JoinAction, LikeAction, Project
        from sequere.contrib.timeline import Timeline
        from .sequere_registry import JoinAction, LikeAction
        from sequere.contrib.timeline import get_actions
        from ..models import follow, unfollow
        from .sequere_registry import JoinAction
        from sequere.contrib.timeline import Timeline


        self.assertEqual(response.status_code, 200)

        content = json.loads(response.content.decode())

        self.assertEqual(content['followings_count'], 0)
        self.assertEqual(content['%s_followings_count' % identifier], 0)


@override_settings(SEQUERE_BACKEND='sequere.backends.database.DatabaseBackend')
class DatabaseBackendTests(BaseBackendTests, TestCase):
    def test_from_instance_and_to_instance(self):

        follow(self.user, self.project)

        instance = Follow.objects.all()[0]

        self.assertEqual(instance.to_instance, self.project)
        self.assertEqual(instance.from_instance, self.user)


@override_settings(SEQUERE_TIMELINE_IMPORT_ACTIONS_ON_FOLLOW=True,
                   SEQUERE_TIMELINE_REMOVE_ACTIONS_ON_UNFOLLOW=True,
                   INSTALLED_APPS=settings.INSTALLED_APPS + ['sequere.contrib.timeline', ],
                   SEQUERE_TIMELINE_BACKEND='sequere.contrib.timeline.backends.redis.RedisBackend')
class TimelineTests(FixturesMixin, TestCase):
    def setUp(self):
        super(TimelineTests, self).setUp()

        app.backend = RedisBackend()

        app.backend.clear()