# Path: unsubscribe/models.py
# def unsubscribe_user( address ):
# 
# Path: signup/models.py
# def create_signup( email, questions ):
# def update_signup( email, questions ):
# def create_or_update_signup( email, questions ):
# def delete_signup( email, sequence ):
# def _signup2json( signup_db ):
# def get_signup( email, sequence ):
# def get_all_user_signups( email ):
# def get_signup_by_invite_code( invite_code ):
# def get_signups( sequence ):
# def get_signups_for_archiving( sequence ):
# def get_new_signups( ):
# def handle_new_signups( ):
# def add_user_to_global_list( email, sequence ):


from django.test import TestCase
from mock import patch
from unsubscribe import models as unsubscribe_model
from signup import models as signup_model


@patch('signup.models.sequence_model.get_current_sequence_number', lambda: 1)
class SimpleTest(TestCase):

    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    @patch('unsubscribe.models.signup_model.delete_signup')
    @patch('unsubscribe.models.signup_model.get_all_user_signups', lambda x: [{'sequence': 1}])
    def test_unsubscribe_user(self, *args):
        unsubscribe_model.unsubscribe_user('user@mail.com')
        self.assertTrue(args[0].called)
        self.assertTrue(args[1].called)
        self.assertTrue(args[2].called)


    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    def test_unsubscribe_signed_up_user(self, remove_list_member, delete_all_unsubscribes):
        signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        unsubscribe_model.unsubscribe_user('dirk@mail.com')
        self.assertTrue(remove_list_member.called)
        self.assertTrue(delete_all_unsubscribes.called)

    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    def test_unsubscribe_signed_upx2_user(self, remove_list_member, delete_all_unsubscribes):
        signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2):
            signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2'})

# Path: unsubscribe/models.py
# def unsubscribe_user( address ):
# 
# Path: signup/models.py
# def create_signup( email, questions ):
# def update_signup( email, questions ):
# def create_or_update_signup( email, questions ):
# def delete_signup( email, sequence ):
# def _signup2json( signup_db ):
# def get_signup( email, sequence ):
# def get_all_user_signups( email ):
# def get_signup_by_invite_code( invite_code ):
# def get_signups( sequence ):
# def get_signups_for_archiving( sequence ):
# def get_new_signups( ):
# def handle_new_signups( ):
# def add_user_to_global_list( email, sequence ):


# Path: unsubscribe/tests/test_models.py
from django.test import TestCase
from mock import patch
from unsubscribe import models as unsubscribe_model
from signup import models as signup_model



@patch('signup.models.sequence_model.get_current_sequence_number', lambda: 1)
class SimpleTest(TestCase):

    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    @patch('unsubscribe.models.signup_model.delete_signup')
    @patch('unsubscribe.models.signup_model.get_all_user_signups', lambda x: [{'sequence': 1}])
    def test_unsubscribe_user(self, *args):
        unsubscribe_model.unsubscribe_user('user@mail.com')
        self.assertTrue(args[0].called)
        self.assertTrue(args[1].called)
        self.assertTrue(args[2].called)


    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    def test_unsubscribe_signed_up_user(self, remove_list_member, delete_all_unsubscribes):
        signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        unsubscribe_model.unsubscribe_user('dirk@mail.com')
        self.assertTrue(remove_list_member.called)
        self.assertTrue(delete_all_unsubscribes.called)

    @patch('unsubscribe.models.mailgun_api.remove_list_member')
    @patch('unsubscribe.models.mailgun_api.delete_all_unsubscribes')
    def test_unsubscribe_signed_upx2_user(self, remove_list_member, delete_all_unsubscribes):
        signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2', 'q3':'a3'})
        with patch('signup.models.sequence_model.get_current_sequence_number', lambda: 2):
            signup_model.create_signup('dirk@mail.com', {'q1':'a1', 'q2':'a2'})

        unsubscribe_model.unsubscribe_user('dirk@mail.com')