Skip to content

Commit

Permalink
[IMP] Add tests to increase coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
aisopuro authored and dnplkndll committed Jan 23, 2025
1 parent 2eec0b0 commit ccc6b8c
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sentry/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Sentry
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:88c5722f68e393e581f3bd3dfc08a4350731602583fdce2d407f6efcede43443
!! source digest: sha256:fb1e0787f353def76b80f3aae5948d0b7a9b01d35f2f738a5b96fa28588bab0e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
Expand Down
2 changes: 1 addition & 1 deletion sentry/i18n/sentry.pot
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 16.0\n"
"Project-Id-Version: Odoo Server 17.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
Expand Down
2 changes: 1 addition & 1 deletion sentry/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ <h1 class="title">Sentry</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:88c5722f68e393e581f3bd3dfc08a4350731602583fdce2d407f6efcede43443
!! source digest: sha256:fb1e0787f353def76b80f3aae5948d0b7a9b01d35f2f738a5b96fa28588bab0e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/server-tools/tree/17.0/sentry"><img alt="OCA/server-tools" src="https://img.shields.io/badge/github-OCA%2Fserver--tools-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/server-tools-17-0/server-tools-17-0-sentry"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/server-tools&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This module allows painless <a class="reference external" href="https://sentry.io/">Sentry</a> integration
Expand Down
2 changes: 1 addition & 1 deletion sentry/tests/__init__.py
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
48 changes: 48 additions & 0 deletions sentry/tests/test_generalutils.py
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)),
)
14 changes: 10 additions & 4 deletions sentry/tests/test_logutils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright 2016-2017 Versada <https://versada.eu/>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
import os

from odoo.tests import TransactionCase

from ..logutils import SanitizeOdooCookiesProcessor
from .. import logutils


class TestOdooCookieSanitizer(TransactionCase):
Expand All @@ -17,7 +18,7 @@ def test_cookie_as_string(self):
}
}

proc = SanitizeOdooCookiesProcessor()
proc = logutils.SanitizeOdooCookiesProcessor()
result = proc.process(data)

self.assertTrue("request" in result)
Expand All @@ -33,7 +34,7 @@ def test_cookie_as_string(self):
def test_cookie_as_string_with_partials(self):
data = {"request": {"cookies": "website_lang=en_us;session_id;foo=bar"}}

proc = SanitizeOdooCookiesProcessor()
proc = logutils.SanitizeOdooCookiesProcessor()
result = proc.process(data)

self.assertTrue("request" in result)
Expand All @@ -55,7 +56,7 @@ def test_cookie_header(self):
}
}

proc = SanitizeOdooCookiesProcessor()
proc = logutils.SanitizeOdooCookiesProcessor()
result = proc.process(data)

self.assertTrue("request" in result)
Expand All @@ -67,3 +68,8 @@ def test_cookie_header(self):
f"Session_ID={proc.MASK};"
f"a_session_id_here={proc.MASK}",
)

def test_git_sha_failure(self):
with self.assertRaises(logutils.InvalidGitRepository):
# Assume this test file is not in the repo root
logutils.fetch_git_sha(os.path.dirname(__file__))
48 changes: 48 additions & 0 deletions sentry/tests/test_processor.py
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))

0 comments on commit ccc6b8c

Please sign in to comment.