Esempio n. 1
0
class ViewTestCase(TestCase):
    def setUp(self):
        super(ViewTestCase, self).setUp()
        self.view = ChatterBotView()

    def test_validate_text(self):
        try:
            self.view.validate({'text': 'How are you?'})
        except ValidationError:
            self.fail('Test raised ValidationError unexpectedly!')

    def test_validate_invalid_text(self):
        with self.assertRaises(ValidationError):
            self.view.validate({'type': 'classmethod'})
Esempio n. 2
0
class ViewTestCase(TestCase):
    def setUp(self):
        super(ViewTestCase, self).setUp()
        self.view = ChatterBotView()

    def test_validate_text(self):
        try:
            self.view.validate({"text": "How are you?"})
        except ValidationError:
            self.fail("Test raised ValidationError unexpectedly!")

    def test_validate_invalid_text(self):
        with self.assertRaises(ValidationError):
            self.view.validate({"type": "classmethod"})
Esempio n. 3
0
class ViewTestCase(TestCase):
    def setUp(self):
        super(ViewTestCase, self).setUp()
        self.view = ChatterBotView()

    def test_validate_text(self):
        try:
            self.view.validate({'text': 'How are you?'})
        except ValidationError:
            self.fail('Test raised ValidationError unexpectedly!')

    def test_validate_invalid_text(self):
        with self.assertRaises(ValidationError):
            self.view.validate({'type': 'classmethod'})

    def test_get_chat_session(self):
        session = self.view.chatterbot.conversation_sessions.new()
        mock_response = MockResponse(session.id_string)
        get_session = self.view.get_chat_session(mock_response)

        self.assertEqual(session.id_string, get_session.id_string)

    def test_get_chat_session_invalid(self):
        mock_response = MockResponse('--invalid--')
        session = self.view.get_chat_session(mock_response)

        self.assertNotEqual(session.id_string, 'test-session-id')

    def test_get_chat_session_no_session(self):
        mock_response = MockResponse(None)
        mock_response.session = {}
        session = self.view.get_chat_session(mock_response)

        self.assertNotEqual(session.id_string, 'test-session-id')
Esempio n. 4
0
class ViewTestCase(TestCase):

    def setUp(self):
        super(ViewTestCase, self).setUp()
        self.view = ChatterBotView()

    def test_validate_text(self):
        try:
            self.view.validate({
                'text': 'How are you?'
            })
        except ValidationError:
            self.fail('Test raised ValidationError unexpectedly!')

    def test_validate_invalid_text(self):
        with self.assertRaises(ValidationError):
            self.view.validate({
                'type': 'classmethod'
            })

    def test_get_conversation(self):
        conversation_id = self.view.chatterbot.storage.create_conversation()

        mock_response = MockResponse(conversation_id)
        conversation = self.view.get_conversation(mock_response)

        self.assertEqual(conversation_id, conversation.id)

    def test_get_conversation_invalid(self):
        mock_response = MockResponse(0)
        session = self.view.get_conversation(mock_response)

        self.assertNotEqual(session.id, 'test-session-id')

    def test_get_conversation_nonexistent(self):
        mock_response = MockResponse(None)
        mock_response.session = {}
        session = self.view.get_conversation(mock_response)

        self.assertNotEqual(session.id, 'test-session-id')
Esempio n. 5
0
class ViewTestCase(TestCase):

    def setUp(self):
        super(ViewTestCase, self).setUp()
        self.view = ChatterBotView()

    def test_validate_text(self):
        try:
            self.view.validate({
                'text': 'How are you?'
            })
        except ValidationError:
            self.fail('Test raised ValidationError unexpectedly!')

    def test_validate_invalid_text(self):
        with self.assertRaises(ValidationError):
            self.view.validate({
                'type': 'classmethod'
            })

    def test_get_chat_session(self):
        session = self.view.chatterbot.conversation_sessions.new()
        mock_response = MockResponse(session.id_string)
        get_session = self.view.get_chat_session(mock_response)

        self.assertEqual(session.id_string, get_session.id_string)

    def test_get_chat_session_invalid(self):
        mock_response = MockResponse('--invalid--')
        session = self.view.get_chat_session(mock_response)

        self.assertNotEqual(session.id_string, 'test-session-id')

    def test_get_chat_session_no_session(self):
        mock_response = MockResponse(None)
        mock_response.session = {}
        session = self.view.get_chat_session(mock_response)

        self.assertNotEqual(session.id_string, 'test-session-id')
Esempio n. 6
0
 def setUp(self):
     super(ViewTestCase, self).setUp()
     self.view = ChatterBotView()