Fix unit tests

This commit is contained in:
Jorge-Rodriguez 2021-03-08 08:25:48 +02:00
parent 546703f08b
commit f4ca2f1497
No known key found for this signature in database
GPG key ID: 43153D1EFD8F7D90
5 changed files with 87 additions and 32 deletions

View file

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
# Copyright: (c) 2020, Andrew Klychkov (@Andersson007) <aaklychkov@mail.ru>
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb.replication import uses_replica_terminology
from ..utils import dummy_cursor_class
@pytest.mark.parametrize(
'f_output,c_output,c_ret_type',
[
(False, '10.5.0-mariadb', 'dict'),
(True, '10.5.1-mariadb', 'dict'),
(True, '10.6.0-mariadb', 'dict'),
(True, '11.5.1-mariadb', 'dict'),
]
)
def test_uses_replica_terminology(f_output, c_output, c_ret_type):
cursor = dummy_cursor_class(c_output, c_ret_type)
assert uses_replica_terminology(cursor) == f_output

View file

@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from ansible_collections.community.mysql.plugins.module_utils.implementations.mariadb.user import (
supports_identified_by_password,
)
from ..utils import dummy_cursor_class
@pytest.mark.parametrize(
'function_return,cursor_output,cursor_ret_type',
[
(True, '10.5.0-mariadb', 'dict'),
(True, '10.5.1-mariadb', 'dict'),
(True, '10.6.0-mariadb', 'dict'),
(True, '11.5.1-mariadb', 'dict'),
]
)
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.
"""
cursor = dummy_cursor_class(cursor_output, cursor_ret_type)
assert supports_identified_by_password(cursor) == function_return

View file

@ -6,7 +6,7 @@ __metaclass__ = type
import pytest
from ansible_collections.community.mysql.plugins.modules.mysql_replication import uses_replica_terminology
from ansible_collections.community.mysql.plugins.module_utils.implementations.mysql.replication import uses_replica_terminology
from ..utils import dummy_cursor_class
@ -18,13 +18,9 @@ from ..utils import dummy_cursor_class
(False, '8.0.0-mysql', 'list'),
(False, '8.0.11-mysql', 'dict'),
(False, '8.0.21-mysql', 'list'),
(False, '10.5.0-mariadb', 'dict'),
(True, '8.0.22-mysql', 'list'),
(True, '8.1.2-mysql', 'dict'),
(True, '9.0.0-mysql', 'list'),
(True, '10.5.1-mariadb', 'dict'),
(True, '10.6.0-mariadb', 'dict'),
(True, '11.5.1-mariadb', 'dict'),
]
)
def test_uses_replica_terminology(f_output, c_output, c_ret_type):

View file

@ -0,0 +1,33 @@
# -*- coding: utf-8 -*-
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
import pytest
from ansible_collections.community.mysql.plugins.module_utils.implementations.mysql.user import (
supports_identified_by_password,
)
from ..utils import dummy_cursor_class
@pytest.mark.parametrize(
'function_return,cursor_output,cursor_ret_type',
[
(True, '5.5.1-mysql', 'list'),
(True, '5.7.0-mysql', 'dict'),
(False, '8.0.22-mysql', 'list'),
(False, '8.1.2-mysql', 'dict'),
(False, '9.0.0-mysql', 'list'),
(False, '8.0.0-mysql', 'list'),
(False, '8.0.11-mysql', 'dict'),
(False, '8.0.21-mysql', 'list'),
]
)
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.
"""
cursor = dummy_cursor_class(cursor_output, cursor_ret_type)
assert supports_identified_by_password(cursor) == function_return

View file

@ -10,37 +10,10 @@ from ansible_collections.community.mysql.plugins.modules.mysql_user import (
has_grant_on_col,
normalize_col_grants,
sort_column_order,
supports_identified_by_password,
)
from ..utils import dummy_cursor_class
@pytest.mark.parametrize(
'function_return,cursor_output,cursor_ret_type',
[
(True, '5.5.1-mysql', 'list'),
(True, '5.7.0-mysql', 'dict'),
(True, '10.5.0-mariadb', 'dict'),
(True, '10.5.1-mariadb', 'dict'),
(True, '10.6.0-mariadb', 'dict'),
(True, '11.5.1-mariadb', 'dict'),
(False, '8.0.22-mysql', 'list'),
(False, '8.1.2-mysql', 'dict'),
(False, '9.0.0-mysql', 'list'),
(False, '8.0.0-mysql', 'list'),
(False, '8.0.11-mysql', 'dict'),
(False, '8.0.21-mysql', 'list'),
]
)
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.
"""
cursor = dummy_cursor_class(cursor_output, cursor_ret_type)
assert supports_identified_by_password(cursor) == function_return
@pytest.mark.parametrize(
'input_list,grant,output_tuple',
[