# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from django.db.models.signals import post_delete
from django.dispatch import receiver

from ..models import Translation

from .base import BaseTestCase
from .translations import FooModel


class SignalsTest(BaseTestCase):
    """
    Tests Linguist Signals.
    """

    def setUp(self):
        self.create_registry()
        self.deleted_count = 0
        post_delete.connect(self.post_delete_listener, sender=FooModel)

    def post_delete_listener(self, sender, instance, **kwargs):
        self.deleted_count += 1

    def test_post_delete(self):
        self.instance.language = 'en'
        self.instance.title = 'Hello'
        self.instance.save()

        self.instance.language = 'fr'
        self.instance.title = 'Bonjour'
        self.instance.save()

        self.assertEqual(Translation.objects.count(), 2)
        self.assertEqual(self.deleted_count, 0)

        self.instance.delete()
        self.assertEqual(self.deleted_count, 1)
        self.assertEqual(Translation.objects.count(), 0)

@@ -244,16 +244,26 @@
 FooModel
+, BarModel
 %0A%0A%0Aclass
@@ -390,208 +390,8 @@
 ry()
-%0A        self.deleted_count = 0%0A        post_delete.connect(self.post_delete_listener, sender=FooModel)%0A%0A    def post_delete_listener(self, sender, instance, **kwargs):%0A        self.deleted_count += 1
 %0A%0A  
@@ -691,16 +691,156 @@
 t(), 2)%0A
+%0A        bar_instance = BarModel()%0A        bar_instance.language = 'fr'%0A        bar_instance.title = 'Bonjour'%0A        bar_instance.save()%0A%0A
         
@@ -860,29 +860,38 @@
 ual(
-self.deleted_
+Translation.objects.
 count
+()
 , 
-0
+3
 )%0A%0A 
@@ -949,30 +949,70 @@
 ual(
-self.deleted_
+Translation.objects.
 count
+()
 , 1)
+%0A%0A        bar_instance.delete()
 %0A   

improve post_delete signal tests.