forked from OCA/server-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] Add tests to increase coverage
- Loading branch information
Showing
7 changed files
with
110 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Copyright 2016-2017 Versada <https://versada.eu/> | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from . import test_client, test_logutils | ||
from . import test_client, test_logutils, test_processor, test_generalutils |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import typing | ||
from collections import namedtuple | ||
|
||
from odoo.tests import TransactionCase | ||
|
||
from .. import generalutils | ||
|
||
|
||
class TestGeneralUtils(TransactionCase): | ||
def test_is_namedtuple(self): | ||
self.assertFalse(generalutils.is_namedtuple(["a list"])) | ||
self.assertFalse(generalutils.is_namedtuple(("a normal tuple",))) | ||
a_namedtuple = namedtuple("a_namedtuple", ["some_string"]) | ||
self.assertTrue(generalutils.is_namedtuple(a_namedtuple("a namedtuple"))) | ||
|
||
class AnotherNamedtuple(typing.NamedTuple): | ||
some_string: str | ||
|
||
self.assertTrue( | ||
generalutils.is_namedtuple(AnotherNamedtuple("a subclassed namedtuple")) | ||
) | ||
|
||
def test_varmap(self): | ||
top = { | ||
"middle": [ | ||
"a list", | ||
"that contains", | ||
"the outer dict", | ||
], | ||
} | ||
top["middle"].append(top) | ||
|
||
def func(_, two): | ||
return two | ||
|
||
# Don't care about the result, just that we don't get a recursion error | ||
generalutils.varmap(func, top) | ||
|
||
def test_get_environ(self): | ||
fake_environ = { | ||
"REMOTE_ADDR": None, | ||
"SERVER_PORT": None, | ||
"FORBIDDEN_VAR": None, | ||
} | ||
self.assertEqual( | ||
["REMOTE_ADDR", "SERVER_PORT"], | ||
list(key for key, _ in generalutils.get_environ(fake_environ)), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from odoo.tests import TransactionCase | ||
|
||
from .. import processor | ||
|
||
|
||
class TestSanitizers(TransactionCase): | ||
def test_sanitize_password(self): | ||
sanitizer = processor.SanitizePasswordsProcessor() | ||
for password in [ | ||
"1234-5678-9012-3456", | ||
"1234 5678 9012 3456", | ||
"1234 - 5678- -0987---1234", | ||
"123456789012345", | ||
]: | ||
with self.subTest( | ||
password=password, | ||
msg="password should have been sanitized", | ||
): | ||
self.assertEqual( | ||
sanitizer.sanitize(None, password), | ||
sanitizer.MASK, | ||
) | ||
for not_password in [ | ||
"1234", | ||
"hello", | ||
"text long enough", | ||
"numbers and 73X7", | ||
"12345678901234567890", | ||
b"12345678901234567890", | ||
b"1234 5678 9012 3456", | ||
"1234-5678-9012-3456-7890", | ||
]: | ||
with self.subTest( | ||
not_password=password, | ||
msg="not_password should not have been sanitized", | ||
): | ||
self.assertEqual( | ||
sanitizer.sanitize(None, not_password), | ||
not_password, | ||
) | ||
|
||
def test_sanitize_keys(self): | ||
sanitizer = processor.SanitizeKeysProcessor() | ||
self.assertIsNone(sanitizer.sanitize_keys) | ||
|
||
def test_sanitize_none(self): | ||
sanitizer = processor.SanitizePasswordsProcessor() | ||
self.assertIsNone(sanitizer.sanitize(None, None)) |