# Path: django_ratings/karma.py
# class KarmaSources(object):
#     def __init__(self):
#     def register(self, model, owner_getter, weight=1):
#     def get_owner(self, instance):
#     def registered_content_types(self):
# 
# Path: django_ratings/models.py
# class TotalRate(models.Model):
#     """
#     save all rating for individual object.
#     """
#     target_ct = models.ForeignKey(ContentType, db_index=True)
#     target_id = models.PositiveIntegerField(_('Object ID'))
#     target = generic.GenericForeignKey('target_ct', 'target_id')
#     amount = models.DecimalField(_('Amount'), max_digits=10, decimal_places=2)
# 
#     objects = TotalRateManager()
# 
#     def __unicode__(self):
#         return u'%s points for %s' % (self.amount, self.target)
# 
#     class Meta:
#         verbose_name = _('Total rate')
#         verbose_name_plural = _('Total rates')
#         unique_together = (('target_ct', 'target_id',),)
# 
# class UserKarma(models.Model):
#     user = models.ForeignKey(User, primary_key=True)
#     karma = models.DecimalField(_('Karma'), max_digits=10, decimal_places=2)
# 
#     objects = UserKarmaManager()
# 
#     class Meta:
#         verbose_name = _("User's karma")
#         verbose_name_plural = _("Users' karmas")


from django.contrib.auth.models import User, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django_ratings import karma
from django_ratings.models import TotalRate, UserKarma
from helpers import SimpleRateTestCase



class KarmaTestCase(SimpleRateTestCase):
    def setUp(self):
        super(KarmaTestCase, self).setUp()
        self.user = User.objects.create(
                username='some_username',
                password=UNUSABLE_PASSWORD
            )

    def tearDown(self):
        super(KarmaTestCase, self).tearDown()
        karma.sources = karma.KarmaSources()

class TestKarmaCalculation(KarmaTestCase):
    def setUp(self):
        super(TestKarmaCalculation, self).setUp()
        karma.sources.register(ContentType, lambda u: self.user)

    def test_karma_doesnt_get_created_when_no_applicable_ratings(self):

# Path: django_ratings/karma.py
# class KarmaSources(object):
#     def __init__(self):
#     def register(self, model, owner_getter, weight=1):
#     def get_owner(self, instance):
#     def registered_content_types(self):
# 
# Path: django_ratings/models.py
# class TotalRate(models.Model):
#     """
#     save all rating for individual object.
#     """
#     target_ct = models.ForeignKey(ContentType, db_index=True)
#     target_id = models.PositiveIntegerField(_('Object ID'))
#     target = generic.GenericForeignKey('target_ct', 'target_id')
#     amount = models.DecimalField(_('Amount'), max_digits=10, decimal_places=2)
# 
#     objects = TotalRateManager()
# 
#     def __unicode__(self):
#         return u'%s points for %s' % (self.amount, self.target)
# 
#     class Meta:
#         verbose_name = _('Total rate')
#         verbose_name_plural = _('Total rates')
#         unique_together = (('target_ct', 'target_id',),)
# 
# class UserKarma(models.Model):
#     user = models.ForeignKey(User, primary_key=True)
#     karma = models.DecimalField(_('Karma'), max_digits=10, decimal_places=2)
# 
#     objects = UserKarmaManager()
# 
#     class Meta:
#         verbose_name = _("User's karma")
#         verbose_name_plural = _("Users' karmas")


# Path: tests/unit_project/test_karma.py
from django.contrib.auth.models import User, UNUSABLE_PASSWORD
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ImproperlyConfigured
from django_ratings import karma
from django_ratings.models import TotalRate, UserKarma
from helpers import SimpleRateTestCase




class KarmaTestCase(SimpleRateTestCase):
    def setUp(self):
        super(KarmaTestCase, self).setUp()
        self.user = User.objects.create(
                username='some_username',
                password=UNUSABLE_PASSWORD
            )

    def tearDown(self):
        super(KarmaTestCase, self).tearDown()
        karma.sources = karma.KarmaSources()

class TestKarmaCalculation(KarmaTestCase):
    def setUp(self):
        super(TestKarmaCalculation, self).setUp()
        karma.sources.register(ContentType, lambda u: self.user)

    def test_karma_doesnt_get_created_when_no_applicable_ratings(self):

        UserKarma.objects.total_rate_to_karma()