Пример #1
0
 def setUp(self):
     self.brain = JenniferTestBrain(always_allow_plugins=[JenniferGmailPlugin])
     self.brain.disable_unsure_response()
 def setUp(self):
     self.brain = JenniferTestBrain()
     self.brain.disable_unsure_response()
Пример #3
0
class JenniferGmailPluginTests(unittest.TestCase):

    def setUp(self):
        self.brain = JenniferTestBrain(always_allow_plugins=[JenniferGmailPlugin])
        self.brain.disable_unsure_response()

    def test_counting(self):
        inputs = [
            "count unread emails"
        ]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 2)

        response = client.output_list[0]
        self.assertEqual("JenniferGmailPlugin", response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))
        self.assertIn("checking", response.to_text().lower())

        response = client.output_list[1]
        self.assertEqual("JenniferGmailPlugin", response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        self.assertIn("you have 2 new emails", response.to_text().lower())

    @mock.patch.object(GmailImapWrapper, 'read_message')
    @mock.patch.object(GmailImapWrapper, 'delete_message')
    def test_check_email(self, delete_mock, read_mock):
        inputs = [
            "read my emails",
            "no", "no",  # Email 1
            "no", "no",  # Email 2
            "no", "no",  # Email 3
            "no", "no",  # Email 4
            "no", "no",  # Email 5
            "no", "no",  # Email 6
            "no", "no",  # Email 7
            "no", "no",  # Email 8
            "no", "no",  # Email 9
            "no", "no",  # Email 10
        ]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertGreaterEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual("JenniferGmailPlugin", response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))
        self.assertIn("checking", response.to_text().lower())

        response = client.output_list[1]
        self.assertEqual("JenniferGmailPlugin", response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        self.assertIn("you have", response.to_text().lower())
        self.assertIn("email", response.to_text().lower())

        self.assertFalse(delete_mock.called)
        self.assertFalse(read_mock.called)

    @mock.patch.object(GmailImapWrapper, 'read_message')
    @mock.patch.object(GmailImapWrapper, 'delete_message')
    def test_delete_read_email(self, delete_mock, read_mock):
        inputs = [
            "read my emails",
            "yes", "no",  # Email 1
            "no", "yes",  # Email 2
            "no", "no",   # Email 3
            "no", "no",   # Email 4
            "no", "no",   # Email 5
            "no", "no",   # Email 6
            "no", "no",   # Email 7
            "no", "no",   # Email 8
            "no", "no",   # Email 9
            "no", "no",   # Email 10
        ]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertTrue(delete_mock.called)
        self.assertTrue(read_mock.called)
class JenniferTimePluginTests(unittest.TestCase):
    def setUp(self):
        self.brain = JenniferTestBrain()
        self.brain.disable_unsure_response()

    def test_time(self):
        inputs = ["what time is it?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(JenniferTimePlugin.__name__, response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now()
        should_be_in = [now.strftime(code) for code in ["%M", "%p"]]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())

    def test_date_today(self):
        inputs = ["what is the date?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(JenniferTimePlugin.__name__, response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now()
        should_be_in = [now.strftime(code) for code in ["%A", "%B", "%d", "%Y"]]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())

    def test_date_tomorrow(self):
        inputs = ["what is the date tomorrow?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(JenniferTimePlugin.__name__, response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now() + datetime.timedelta(days=1)
        should_be_in = [now.strftime(code) for code in ["%A", "%B", "%d", "%Y"]]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())
Пример #5
0
 def setUp(self):
     self.brain = JenniferTestBrain(
         always_allow_plugins=[JenniferFindMyIphonePlugin])
Пример #6
0
 def setUp(self):
     self.brain = JenniferTestBrain()
     self.brain.disable_unsure_response()
Пример #7
0
class JenniferTimePluginTests(unittest.TestCase):
    def setUp(self):
        self.brain = JenniferTestBrain()
        self.brain.disable_unsure_response()

    def test_time(self):
        inputs = ["what time is it?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(
            JenniferTimePlugin.__name__,
            response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now()
        should_be_in = [now.strftime(code) for code in ['%M', '%p']]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())

    def test_date_today(self):
        inputs = ["what is the date?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(
            JenniferTimePlugin.__name__,
            response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now()
        should_be_in = [
            now.strftime(code) for code in ['%A', '%B', '%d', '%Y']
        ]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())

    def test_date_tomorrow(self):
        inputs = ["what is the date tomorrow?"]
        client = JenniferTestClient(self.brain, inputs)
        client.run()

        self.assertEqual(len(client.output_list), 1)

        response = client.output_list[0]
        self.assertEqual(
            JenniferTimePlugin.__name__,
            response.response_creator)  # Make sure the time plugin responded
        self.assertTrue(isinstance(response, JenniferResponse))
        self.assertEqual(len(response.segments), 1)

        segment = response.segments[0]
        self.assertTrue(isinstance(segment, JenniferTextResponseSegment))

        now = datetime.datetime.now() + datetime.timedelta(days=1)
        should_be_in = [
            now.strftime(code) for code in ['%A', '%B', '%d', '%Y']
        ]
        for time_str in should_be_in:
            self.assertIn(time_str, response.to_text())
Пример #8
0
 def setUp(self):
     self.brain = JenniferTestBrain()