mirror of
https://github.com/ansible-collections/community.mysql.git
synced 2025-04-20 09:21:25 -07:00
mysql_user: when grant select on columns, the module always report the state has changed (#100)
* mysql_user: fix the module is not idempotent when there is SELECT on columns granted * add changelog fragment * fix * Add unit tests for has_select_on_col function * Add unit tests for sort_column_order function * Add unit tests for handle_select_on_col function * Update a comment
This commit is contained in:
parent
e8dc2f2476
commit
2694464ffb
4 changed files with 232 additions and 3 deletions
|
@ -1,9 +1,16 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from __future__ import (absolute_import, division, print_function)
|
||||
__metaclass__ = type
|
||||
|
||||
import pytest
|
||||
|
||||
from ansible_collections.community.mysql.plugins.modules.mysql_user import supports_identified_by_password
|
||||
from ansible_collections.community.mysql.plugins.modules.mysql_user import (
|
||||
handle_select_on_col,
|
||||
has_select_on_col,
|
||||
sort_column_order,
|
||||
supports_identified_by_password,
|
||||
)
|
||||
from ..utils import dummy_cursor_class
|
||||
|
||||
|
||||
|
@ -26,8 +33,58 @@ from ..utils import dummy_cursor_class
|
|||
)
|
||||
def test_supports_identified_by_password(function_return, cursor_output, cursor_ret_type):
|
||||
"""
|
||||
Tests whether 'CREATE USER %s@%s IDENTIFIED BY PASSWORD %s' is supported, which is currently supported by everything
|
||||
besides MySQL >= 8.0.
|
||||
Tests whether 'CREATE USER %s@%s IDENTIFIED BY PASSWORD %s' is supported,
|
||||
which is currently supported by everything besides MySQL >= 8.0.
|
||||
"""
|
||||
cursor = dummy_cursor_class(cursor_output, cursor_ret_type)
|
||||
assert supports_identified_by_password(cursor) == function_return
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'input_list,output_tuple',
|
||||
[
|
||||
(['INSERT', 'DELETE'], (None, None)),
|
||||
(['SELECT', 'UPDATE'], (None, None)),
|
||||
(['INSERT', 'UPDATE', 'INSERT', 'DELETE'], (None, None)),
|
||||
(['just', 'a', 'random', 'text'], (None, None)),
|
||||
(['SELECT (A, B, C)'], (0, 0)),
|
||||
(['UPDATE', 'SELECT (A, B, C)'], (1, 1)),
|
||||
(['INSERT', 'SELECT (A', 'B)'], (1, 2)),
|
||||
(['SELECT (A', 'B)', 'UPDATE'], (0, 1)),
|
||||
(['INSERT', 'SELECT (A', 'B)', 'UPDATE'], (1, 2)),
|
||||
]
|
||||
)
|
||||
def test_has_select_on_col(input_list, output_tuple):
|
||||
"""Tests has_select_on_col function."""
|
||||
assert has_select_on_col(input_list) == output_tuple
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'input_,output',
|
||||
[
|
||||
('SELECT (A)', 'SELECT (A)'),
|
||||
('SELECT (`A`)', 'SELECT (A)'),
|
||||
('SELECT (A, B)', 'SELECT (A, B)'),
|
||||
('SELECT (`A`, `B`)', 'SELECT (A, B)'),
|
||||
('SELECT (B, A)', 'SELECT (A, B)'),
|
||||
('SELECT (`B`, `A`)', 'SELECT (A, B)'),
|
||||
('SELECT (`B`, `A`, C)', 'SELECT (A, B, C)'),
|
||||
]
|
||||
)
|
||||
def test_sort_column_order(input_, output):
|
||||
"""Tests sort_column_order function."""
|
||||
assert sort_column_order(input_) == output
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
'privileges,start,end,output',
|
||||
[
|
||||
(['UPDATE', 'SELECT (C, B, A)'], 1, 1, ['UPDATE', 'SELECT (A, B, C)']),
|
||||
(['INSERT', 'SELECT (A', 'B)'], 1, 2, ['INSERT', 'SELECT (A, B)']),
|
||||
(['SELECT (`A`', 'B)', 'UPDATE'], 0, 1, ['SELECT (A, B)', 'UPDATE']),
|
||||
(['INSERT', 'SELECT (`B`', 'A', 'C)', 'UPDATE'], 1, 3, ['INSERT', 'SELECT (A, B, C)', 'UPDATE']),
|
||||
]
|
||||
)
|
||||
def test_handle_select_on_col(privileges, start, end, output):
|
||||
"""Tests handle_select_on_col function."""
|
||||
assert handle_select_on_col(privileges, start, end) == output
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue