# Path: test_project/test_app/models.py
# class Post(BaseSocialModel):
#     user = models.ForeignKey(User, related_name='posts', on_delete=models.CASCADE)
#     title = models.CharField(max_length=100, null=True, blank=True)
#     description = models.TextField(blank=True, null=True)
#     thumbnail = models.ImageField(upload_to="post_photos/thumbnail/", blank=True, null=True)
# 
#     TAG_FIELD = 'description'
# 
#     likes = GenericRelation(Like)
#     flags = GenericRelation(Flag)
#     shares = GenericRelation(Share)
#     related_tags = models.ManyToManyField(Tag, blank=True)
#     comments = GenericRelation(Comment)
#     notifications = GenericRelation(Notification)
# 
#     def likes_count(self):
#         return self.likes.count()
# 
#     def comments_count(self):
#         return self.comments.count()
# 
#     def identifier(self):
#         return "{}".format(self.title)
# 
#     def __unicode__(self):
#         return "{}".format(self.title) if self.title else "Untitled"
# 
#     def url(self):
#         current_site = Site.objects.get_current()
#         return "http://{0}/{1}/{2}/".format(current_site.domain, "post", base62.encode(self.pk))
# 
#     def facebook_og_info(self):
#         return {'action': 'post', 'object': 'cut', 'url': self.url()}
# 
#     def create_social_message(self, provider):
#         message = "{} published by {} on Test Project".format(self.title, self.user.username)
# 
#         # TODO: Sending of messages to post on social media is broken and convoluted at this point, need to refactor
#         if provider == "twitter":
#             return "{}".format(message.encode('utf-8'))
#         else:
#             return "{} {}".format(message.encode('utf-8'), self.url())
# 
# Path: yak/rest_social_network/models.py
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']


import factory
import datetime
from test_project.test_app.models import Post
from django.utils.timezone import now
from oauth2_provider.models import AccessToken, Application
from django.contrib.auth import get_user_model
from yak.rest_social_network.models import Comment


User = get_user_model()


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = User

    email = factory.Sequence(lambda n: 'person{0}@example.com'.format(n))
    username = factory.Sequence(lambda n: 'person{0}'.format(n))

    @staticmethod
    def get_test_application():
        application, created = Application.objects.get_or_create(
            client_type=Application.CLIENT_PUBLIC,
            name="Test App",
            authorization_grant_type=Application.GRANT_PASSWORD,
        )

# Path: test_project/test_app/models.py
# class Post(BaseSocialModel):
#     user = models.ForeignKey(User, related_name='posts', on_delete=models.CASCADE)
#     title = models.CharField(max_length=100, null=True, blank=True)
#     description = models.TextField(blank=True, null=True)
#     thumbnail = models.ImageField(upload_to="post_photos/thumbnail/", blank=True, null=True)
# 
#     TAG_FIELD = 'description'
# 
#     likes = GenericRelation(Like)
#     flags = GenericRelation(Flag)
#     shares = GenericRelation(Share)
#     related_tags = models.ManyToManyField(Tag, blank=True)
#     comments = GenericRelation(Comment)
#     notifications = GenericRelation(Notification)
# 
#     def likes_count(self):
#         return self.likes.count()
# 
#     def comments_count(self):
#         return self.comments.count()
# 
#     def identifier(self):
#         return "{}".format(self.title)
# 
#     def __unicode__(self):
#         return "{}".format(self.title) if self.title else "Untitled"
# 
#     def url(self):
#         current_site = Site.objects.get_current()
#         return "http://{0}/{1}/{2}/".format(current_site.domain, "post", base62.encode(self.pk))
# 
#     def facebook_og_info(self):
#         return {'action': 'post', 'object': 'cut', 'url': self.url()}
# 
#     def create_social_message(self, provider):
#         message = "{} published by {} on Test Project".format(self.title, self.user.username)
# 
#         # TODO: Sending of messages to post on social media is broken and convoluted at this point, need to refactor
#         if provider == "twitter":
#             return "{}".format(message.encode('utf-8'))
#         else:
#             return "{} {}".format(message.encode('utf-8'), self.url())
# 
# Path: yak/rest_social_network/models.py
# class Comment(CoreModel):
#     content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
#     object_id = models.PositiveIntegerField(db_index=True)
#     content_object = GenericForeignKey()
# 
#     TAG_FIELD = 'description'
#     related_tags = models.ManyToManyField(Tag, blank=True)
# 
#     description = models.TextField()
#     user = models.ForeignKey(settings.AUTH_USER_MODEL, related_name="comments", on_delete=models.CASCADE)
# 
#     class Meta:
#         ordering = ['created']


# Path: test_project/test_app/tests/factories.py
import factory
import datetime
from test_project.test_app.models import Post
from django.utils.timezone import now
from oauth2_provider.models import AccessToken, Application
from django.contrib.auth import get_user_model
from yak.rest_social_network.models import Comment



User = get_user_model()


class UserFactory(factory.DjangoModelFactory):
    class Meta:
        model = User

    email = factory.Sequence(lambda n: 'person{0}@example.com'.format(n))
    username = factory.Sequence(lambda n: 'person{0}'.format(n))

    @staticmethod
    def get_test_application():
        application, created = Application.objects.get_or_create(
            client_type=Application.CLIENT_PUBLIC,
            name="Test App",
            authorization_grant_type=Application.GRANT_PASSWORD,
        )

        return application