from django.core.management import call_command
from django.test import TestCase
import mock

from matchmaker.models import MatchmakerSubmission


class TransferFamiliesTest(TestCase):
    fixtures = ['users', '1kg_project']

    @mock.patch('seqr.management.commands.update_mme_contact.logger.info')
    def test_command(self, mock_logger):
        call_command(
            'update_mme_contact', 'UDNCC@hms.harvard.edu', '--replace-email', 'test_user@broadinstitute.org',
        )
        mock_logger.assert_has_calls([
            mock.call('Updating 1 submissions'),
            mock.call('Done'),
        ])
        self.assertEqual(
            MatchmakerSubmission.objects.get(id=3).contact_href,
            'mailto:test_user@broadinstitute.org,matchmaker@phenomecentral.org',
        )

        mock_logger.reset_mock()
        call_command('update_mme_contact', 'test_user@broadinstitute.org')
        mock_logger.assert_has_calls([
            mock.call('Updating 2 submissions'),
            mock.call('Done'),
        ])
        self.assertEqual( MatchmakerSubmission.objects.get(id=3).contact_href, 'mailto:matchmaker@phenomecentral.org')
        self.assertEqual(MatchmakerSubmission.objects.get(id=1).contact_href, 'mailto:matchmaker@broadinstitute.org')


@@ -40,17 +40,31 @@
 _command
+, CommandError
 %0A
-
 from dja
@@ -88,16 +88,40 @@
 estCase%0A
+from io import StringIO%0A
 import m
@@ -332,16 +332,16 @@
 .info')%0A
-
     def 
@@ -373,16 +373,253 @@
 ogger):%0A
+        out = StringIO()%0A        with self.assertRaises(CommandError) as err:%0A            call_command('update_mme_contact', stdout=out)%0A        self.assertEqual(str(err.exception), 'Error: the following arguments are required: email')%0A%0A
         

add testing for missing arg