def test_assemble_actions_db_mock_sqlite(self): """test run func and mock libs.""" from melissa.actions_db import assemble_actions_db with mock.patch('melissa.actions_db.sqlite3') as mock_sq: assemble_actions_db() # preparation sql_cmd_basename = 'test_actions_db_sql_command.txt' script_folder = os.path.dirname(os.path.realpath(__file__)) sql_cmd_path = os.path.join(script_folder, 'test_data', sql_cmd_basename) with open(sql_cmd_path) as f: sql_cmds = f.read().splitlines() # testing assert len(mock_sq.mock_calls) == 239 # connect assert mock_sq.connect.call_count == 1 mock_sq.connect.assert_called_once_with(':memory:', check_same_thread=False) # connect().cursor mock_sq.connect.return_value.cursor.assert_called_once_with() # connect().cursor().executescript (mock_sq.connect.return_value.cursor.return_value.executescript. assert_called_once_with(self.exec_script_arg)) # connect().commit assert mock_sq.connect.return_value.commit.call_count == 18 mock_sq.connect.return_value.commit.assert_called_with() # connect().cursor().execute assert len(mock_sq.connect.return_value.cursor.return_value.execute. mock_calls) == 218 for cmd in sql_cmds: assert mock.call(cmd) in (mock_sq.connect.return_value.cursor. return_value.execute.mock_calls)
def test_assemble_actions_db_mock_sqlite(self, m_load_profile): """test run func and mock libs.""" from melissa.actions_db import assemble_actions_db with mock.patch('melissa.actions_db.sqlite3') as mock_sq: assemble_actions_db() # preparation sql_cmd_basename = 'test_actions_db_sql_command.txt' script_folder = os.path.dirname(os.path.realpath(__file__)) sql_cmd_path = os.path.join( script_folder, 'test_data', sql_cmd_basename) with open(sql_cmd_path) as f: sql_cmds = f.read().splitlines() # testing assert len(mock_sq.mock_calls) == 239 # connect assert mock_sq.connect.call_count == 1 mock_sq.connect.assert_called_once_with( ':memory:', check_same_thread=False) # connect().cursor mock_sq.connect.return_value.cursor.assert_called_once_with() # connect().cursor().executescript (mock_sq.connect.return_value.cursor.return_value .executescript.assert_called_once_with(self.exec_script_arg)) # connect().commit mock_sq.connect.return_value.commit.assert_called_with() # test sql commands. call_result = ( mock_sq.connect.return_value.cursor.return_value .execute.mock_calls) call_result_args = [x[1][0] for x in call_result] non_exist_expected_call = [ x for x in sql_cmds if x not in call_result_args] not_expected_call = [ x for x in call_result_args if x not in sql_cmds] # connect().cursor().execute err_msg = ( 'Expected calls which are not exist on actual call:\n{}\n' 'Actual calls which are not expected:\n{}' ) err_msg = err_msg.format( '\n'.join(non_exist_expected_call), '\n'.join(not_expected_call), ) assert len(call_result_args) == len(sql_cmds), err_msg for cmd in sql_cmds: assert mock.call(cmd) in call_result, err_msg
def test_assemble_actions_db_mock_sqlite(self, m_load_profile): """test run func and mock libs.""" from melissa.actions_db import assemble_actions_db with mock.patch('melissa.actions_db.sqlite3') as mock_sq: assemble_actions_db() # preparation sql_cmd_basename = 'test_actions_db_sql_command.txt' script_folder = os.path.dirname(os.path.realpath(__file__)) sql_cmd_path = os.path.join( script_folder, 'test_data', sql_cmd_basename) with open(sql_cmd_path) as f: sql_cmds = f.read().splitlines() # testing assert len(mock_sq.mock_calls) == 240 # connect assert mock_sq.connect.call_count == 1 mock_sq.connect.assert_called_once_with( ':memory:', check_same_thread=False) # connect().cursor mock_sq.connect.return_value.cursor.assert_called_once_with() # connect().cursor().executescript (mock_sq.connect.return_value.cursor.return_value .executescript.assert_called_once_with(self.exec_script_arg)) # connect().commit mock_sq.connect.return_value.commit.assert_called_with() # test sql commands. call_result = ( mock_sq.connect.return_value.cursor.return_value .execute.mock_calls) call_result_args = [x[1][0] for x in call_result] non_exist_expected_call = [ x for x in sql_cmds if x not in call_result_args] not_expected_call = [ x for x in call_result_args if x not in sql_cmds] # connect().cursor().execute err_msg = ( 'Expected calls which are not exist on actual call:\n{}\n' 'Actual calls which are not expected:\n{}' ) err_msg = err_msg.format( '\n'.join(non_exist_expected_call), '\n'.join(not_expected_call), ) assert len(call_result_args) == len(sql_cmds), err_msg for cmd in sql_cmds: assert mock.call(cmd) in call_result, err_msg
def test_assemble_actions_db(self): """test run func.""" from melissa.actions_db import assemble_actions_db assemble_actions_db()
def test_assemble_actions_db(self, m_load_profile): """test run func.""" from melissa.actions_db import assemble_actions_db assemble_actions_db()