From e7260397d021574f4b2082a664a98c868c46092c Mon Sep 17 00:00:00 2001 From: gabriel-logan Date: Sat, 6 Jul 2024 07:34:48 -0300 Subject: [PATCH] refactor: Add unit tests for multiform_validator module --- .github/workflows/python-pr-check.yml | 2 +- .../test_multiform_validator.cpython-311.pyc | Bin 0 -> 5468 bytes packages/python/tests/general.test.py | 152 ------------------ .../python/tests/test_multiform_validator.py | 55 +++++++ 4 files changed, 56 insertions(+), 153 deletions(-) create mode 100644 packages/python/tests/__pycache__/test_multiform_validator.cpython-311.pyc delete mode 100644 packages/python/tests/general.test.py create mode 100644 packages/python/tests/test_multiform_validator.py diff --git a/.github/workflows/python-pr-check.yml b/.github/workflows/python-pr-check.yml index 5579572..2961d50 100644 --- a/.github/workflows/python-pr-check.yml +++ b/.github/workflows/python-pr-check.yml @@ -38,4 +38,4 @@ jobs: - name: Run tests working-directory: ./packages/python run: | - python tests/general.test.py \ No newline at end of file + python -m unittest .\tests\test_multiform_validator.py \ No newline at end of file diff --git a/packages/python/tests/__pycache__/test_multiform_validator.cpython-311.pyc b/packages/python/tests/__pycache__/test_multiform_validator.cpython-311.pyc new file mode 100644 index 0000000000000000000000000000000000000000..dffa77aee9eac1cf83c2644e12a1f2fe9dac614d GIT binary patch literal 5468 zcmdT|O>7&-6`ox#$q`A3l4HqSOKzCfu}r6;M4GlF!;);tlIx;C-j%59>;&0T# z(YXq_u6!UJ$OqHGd?+2tcc;7aJ?Wl&I33RSrhD^!>Aw7)^d1iJ=q!@G_mJ#U_|;b& zy-l;&tMtqMTRiP0eLMom0ap@k9y=8TV{@0-6~oVH>tcnE$1RUWmSbI3aJf)gJ*T}T z*X{`4Mk{9c_bRg^(gSuVvdvCKoDwbBh;$7*(}sp;(SGW5#$Z z2*y@OdH&rsDMx4!KH@AvQ*tXBB`W&joiitvN~D-2QeM)QY!{G=MA4S=4%Z`gE0DcZ zl9q3Q4{1xKjWYPiQW38WKz6ZsO}YzTQ^Ot6weXCyP)FTrzPTudxfdgm@KGw^rCThr0k( z4s|q}D@Rwo7OU;o52g(9m?<9n;~D+!tNQp76a!x~@iiS^+qGJq+`N8eRUf|v#lSfe z=X9qK5k_dR8l69j@?XNu{g;c(rYLWWQx@HBtber)VMkHZI5(ZA1IH}|0t`+t@c-0USrnuV&-B3C(|0B@;&6t;4R@NGC zmD94cF0Zez$oVgF8e}NZMq;DVdQn!PuP9%5`y5oxkXK<^G2Zra`YmW7 zvyYKk|7oop?!;)l($?fB@oovSIisC>T@C(WtIYi)Sh5@Y(2lZH5Dic?Q+8+gIQ3%XM}@bW(y(c}=k zVGF&|A0?9Q^_t;-o1~J~?jSSrgCdPH82^O(p*dTE6L0_a96p|DCkd+xV%1 zq}2Z}(^9-x2_H@-V$n%zypdza$0sh6KHvbF6SR3^{P?kv)X`+3(#;y^nll2|LS^r{ z0!sy>CAyu67TA8mF?$G9v;@e0X7*bC*tid=Bsy8W?IUl%5Ze0ybqn;C7}rNn8RBVE zJpHt+ONu_X0>!{t6K8dtt&5tM7ySIEhB#x2Gf#i4U%#!NUWa1f_e}hr?vz%4a+8(` z$iwfWGR?+oM;10Azi&!V?s82Me2WC%B;je1@W7^}ZX9PkgvxX_wc}3H$c?_jQlqce z@inQ@OU=X6IC5jHmR<>qG0(Gqz|5a*1CXNtG2z(tpjAk| zyf-$$>Fkx8{^Jo72u)$F;A%<9W^SyltiaYdP%7-+XVsNjyC#5S6b?IOwv&nay>{nh zqF!NhA?aj!@4lMBkSg@D=H&CSTg~W@=2wVQjo1z+HAwww%;}hOM+SE$FdZ< z+aT2I3Hu7uHQB;+ot=|l=fTWynzjjanq-~|(%l!c(hGdjp1?G@1Z{Lp&<+6ZcsP#R zMu93jw^3J>o!cl}W#^6$h5LSy{V4Zg?&IVq1b$25IBAZeOnM3=D>oj@bMM%K>TmC 0: - print(RED + 'Failed tests:', failedTests) - print(GREEN + 'Success tests:', successTests) - print(RESET + f'Total tests run: {total_tests}') - else: - print(GREEN + 'All tests passed' + RESET) - print(f'Total tests run: {total_tests}') - -tester() -print('\n') \ No newline at end of file diff --git a/packages/python/tests/test_multiform_validator.py b/packages/python/tests/test_multiform_validator.py new file mode 100644 index 0000000..ec8e754 --- /dev/null +++ b/packages/python/tests/test_multiform_validator.py @@ -0,0 +1,55 @@ +import sys +import os +import unittest + +# Add the parent directory of "src" to the path to allow imports from there +module_path = os.path.join(os.path.dirname(__file__), '..', 'src') +sys.path.append(module_path) + +from multiform_validator import ( + cnpjIsValid, cpfIsValid, getOnlyEmail, identifyFlagCard, + isCreditCardValid, isEmail, isValidImage, passwordStrengthTester, + validateBRPhoneNumber +) + +class TestMultiformValidator(unittest.TestCase): + def test_cnpjIsValid(self): + self.assertEqual(cnpjIsValid('11.444.777/0001-61'), {'isValid': True, 'errorMsg': None}) + self.assertEqual(cnpjIsValid('11.444.777/0001-62'), {'isValid': False, 'errorMsg': 'CNPJ is not valid'}) + + def test_cpfIsValid(self): + self.assertEqual(cpfIsValid('123.456.789-09'), {'isValid': True, 'errorMsg': None}) + self.assertEqual(cpfIsValid('123.456.789-08'), {'isValid': False, 'errorMsg': 'CPF is not valid'}) + + def test_isEmail(self): + self.assertTrue(isEmail('john@email.com')) + self.assertFalse(isEmail('johnemail.com')) + + def test_getOnlyEmail(self): + self.assertEqual(getOnlyEmail('dawdwwud waid wiu wdemail wadwad john@email.com awodi waodOWIawoD'), 'john@email.com') + + def test_identifyFlagCard(self): + self.assertEqual(identifyFlagCard('4111111111111111'), 'Visa') + + def test_isCreditCardValid(self): + self.assertTrue(isCreditCardValid('4111111111111111')) + self.assertFalse(isCreditCardValid('4111111111111112')) + + def test_passwordStrengthTester(self): + self.assertEqual(passwordStrengthTester('123456'), 'weak') + + def test_validateBRPhoneNumber(self): + self.assertEqual(validateBRPhoneNumber('(21) 91234-5678'), {'isValid': True, 'errorMsg': None}) + self.assertEqual(validateBRPhoneNumber('(11) 98765-4321'), {'isValid': True, 'errorMsg': None}) + self.assertEqual(validateBRPhoneNumber('(11) 1111-111'), {'isValid': False, 'errorMsg': 'Invalid phone number'}) + + def test_isValidImage(self): + jpeg_buffer = bytes([0xff, 0xd8, 0xff]) + png_buffer = bytes([0x89, 0x50, 0x4e, 0x47]) + gif_buffer = bytes([0x47, 0x49, 0x46, 0x38]) + self.assertTrue(isValidImage(jpeg_buffer)) + self.assertTrue(isValidImage(png_buffer)) + self.assertTrue(isValidImage(gif_buffer)) + +if __name__ == '__main__': + unittest.main() \ No newline at end of file