Exemplo n.º 1
0
    def test_insert_words_mock_input_and_words_dict(self):
        """test run insert_words with mock input and words as dict."""
        mock_name = 'define'
        mock_con = mock.Mock()
        mock_cur = mock.Mock()
        mock_words = {'define_subject': {'groups': ['define']}}
        mock_priority = mock.Mock()
        from melissa.actions_db import insert_words
        with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            insert_words(mock_con, mock_cur, mock_name, mock_words,
                         mock_priority)

            cur_exec_calls = [
                mock.call("INSERT INTO functions (function, priority) "
                          "values ('define define_subject',0)"),
                mock.call("INSERT INTO word_groups "
                          "(word_group, function, word_count) "
                          "values ('define','define define_subject',1)"),
                mock.call("INSERT INTO words (word, word_group, word_order) "
                          "values ('define','define',0)")
            ]
            mock_con.commit.assert_called_once_with()
            assert len(mock_cur.execute.mock_calls) == 3
            for call in cur_exec_calls:
                assert call in mock_cur.execute.mock_calls
            assert '' in mock_stdout.getvalue()
Exemplo n.º 2
0
 def test_insert_words_mock_input_and_words_list(self):
     """test run insert_words with mock input and words as list."""
     mock_name = 'how'
     mock_con = mock.Mock()
     mock_cur = mock.Mock()
     mock_words = ['how', 'are', 'you']
     mock_priority = mock.Mock()
     from melissa.actions_db import insert_words
     with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         insert_words(mock_con, mock_cur, mock_name, mock_words,
                      mock_priority)
         cur_exec_calls = [
             mock.call("INSERT INTO functions (function, priority) "
                       "values ('{} handle',{})".format(
                           mock_name, mock_priority)),
         ]
         for word in mock_words:
             cur_exec_calls.append(
                 mock.call(
                     "INSERT INTO words (word, word_group, word_order) "
                     "values ('{w}','{w}',0)".format(w=word)))
             cur_exec_calls.append(
                 mock.call("INSERT INTO word_groups "
                           "(word_group, function, word_count) "
                           "values ('{}','{} handle',1)".format(
                               word, mock_name, mock_priority)))
         assert len(mock_cur.execute.mock_calls) == 7
         for call in cur_exec_calls:
             assert call in mock_cur.execute.mock_calls
         mock_con.commit.assert_called_once_with()
         assert '' in mock_stdout.getvalue()
Exemplo n.º 3
0
    def test_insert_words_mock_input_and_words_dict(self, m_load_profile):
        """test run insert_words with mock input and words as dict."""
        mock_name = 'define'
        mock_con = mock.Mock()
        mock_cur = mock.Mock()
        mock_words = {'define_subject': {'groups': ['define']}}
        mock_priority = mock.Mock()
        from melissa.actions_db import insert_words
        with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
            insert_words(
                mock_con, mock_cur, mock_name, mock_words, mock_priority)

            cur_exec_calls = [
                mock.call(
                    "INSERT INTO functions (function, priority) "
                    "values ('define define_subject',0)"),
                mock. call(
                    "INSERT INTO word_groups "
                    "(word_group, function, word_count) "
                    "values ('define','define define_subject',1)"),
                mock.call(
                    "INSERT INTO words (word, word_group, word_order) "
                    "values ('define','define',0)")
            ]
            mock_con.commit.assert_called_once_with()
            assert len(mock_cur.execute.mock_calls) == 3
            for call in cur_exec_calls:
                assert call in mock_cur.execute.mock_calls
            assert '' in mock_stdout.getvalue()
Exemplo n.º 4
0
 def test_insert_words_mock_input_and_words_list(self, m_load_profile):
     """test run insert_words with mock input and words as list."""
     mock_name = 'how'
     mock_con = mock.Mock()
     mock_cur = mock.Mock()
     mock_words = ['how',  'are', 'you']
     mock_priority = mock.Mock()
     from melissa.actions_db import insert_words
     with mock.patch('sys.stdout', new_callable=StringIO) as mock_stdout:
         insert_words(
             mock_con, mock_cur, mock_name, mock_words, mock_priority)
         cur_exec_calls = [
             mock.call(
                 "INSERT INTO functions (function, priority) "
                 "values ('{} handle',{})".format(
                     mock_name, mock_priority)),
         ]
         for word in mock_words:
             cur_exec_calls.append(mock.call(
                 "INSERT INTO words (word, word_group, word_order) "
                 "values ('{w}','{w}',0)".format(w=word)
             ))
             cur_exec_calls.append(mock.call(
                 "INSERT INTO word_groups "
                 "(word_group, function, word_count) "
                 "values ('{}','{} handle',1)".format(
                     word, mock_name, mock_priority)
             ))
         assert len(mock_cur.execute.mock_calls) == 7
         for call in cur_exec_calls:
             assert call in mock_cur.execute.mock_calls
         mock_con.commit.assert_called_once_with()
         assert '' in mock_stdout.getvalue()
Exemplo n.º 5
0
 def test_insert_words_mock_input_and_name_input(self):
     """test run insert_words with mock input."""
     m_name = mock.Mock()
     input_string = 'name'
     for mock_name in (m_name, input_string):
         mock_con = mock.Mock()
         mock_cur = mock.Mock()
         mock_words = mock.Mock()
         mock_priority = mock.Mock()
         from melissa.actions_db import insert_words
         with mock.patch('sys.stdout', new_callable=StringIO) \
                 as mock_stdout:
             insert_words(mock_con, mock_cur, mock_name, mock_words,
                          mock_priority)
             assert ("Invalid WORDS type '<class 'mock.mock.Mock'>' "
                     "for module {}".format(mock_name)
                     ) in mock_stdout.getvalue()
Exemplo n.º 6
0
 def test_insert_words_mock_input_and_name_input(self, m_load_profile):
     """test run insert_words with mock input."""
     m_name = mock.Mock()
     input_string = 'name'
     for mock_name in (m_name, input_string):
         mock_con = mock.Mock()
         mock_cur = mock.Mock()
         mock_words = mock.Mock()
         mock_priority = mock.Mock()
         from melissa.actions_db import insert_words
         with mock.patch('sys.stdout', new_callable=StringIO) \
                 as mock_stdout:
             insert_words(
                 mock_con, mock_cur, mock_name, mock_words, mock_priority)
             assert (
                 "Invalid WORDS type '<class 'mock.mock.Mock'>' "
                 "for module {}".format(mock_name)
             ) in mock_stdout.getvalue()