From ab98309a1386eba5dbd59ca62616214afd01118c Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Jun 03 2016 00:42:10 +0000 Subject: [PATCH 1/2] Add test for get_verify_class() function --- diff --git a/tests/test_hub/test_get_verify_class.py b/tests/test_hub/test_get_verify_class.py new file mode 100644 index 0000000..ae94ed6 --- /dev/null +++ b/tests/test_hub/test_get_verify_class.py @@ -0,0 +1,20 @@ +import unittest +import kojihub +from koji import GenericError +from koji.util import md5_constructor, adler32_constructor + + +class TestGetVerifyClass(unittest.TestCase): + + def test_get_verify_class_generic_error(self): + with self.assertRaises(GenericError): + kojihub.get_verify_class('not_a_real_value') + + def test_get_verify_class_is_none(self): + kojihub.get_verify_class(None) is None + + def test_get_verify_class_is_md5(self): + kojihub.get_verify_class('md5') is md5_constructor + + def test_get_verify_class_is_adler32(self): + kojihub.get_verify_class('adler32') is adler32_constructor From 3f91d4834bd71313a735ae5a6bdaee897fa21ec9 Mon Sep 17 00:00:00 2001 From: Sijis Aviles Date: Jun 03 2016 07:17:07 +0000 Subject: [PATCH 2/2] Add test for get_upload_path() functio --- diff --git a/tests/test_hub/test_get_upload_path.py b/tests/test_hub/test_get_upload_path.py new file mode 100644 index 0000000..f789192 --- /dev/null +++ b/tests/test_hub/test_get_upload_path.py @@ -0,0 +1,53 @@ +import os +import mock +import shutil +import unittest +import kojihub +from koji import GenericError + + +class TestGetUploadPath(unittest.TestCase): + + + def test_get_upload_path_invalid_filename(self): + with self.assertRaises(GenericError): + kojihub.get_upload_path(reldir='', name='. error') + + def test_get_upload_path_invalid_upload_dir_1(self): + with self.assertRaises(GenericError): + kojihub.get_upload_path(reldir='..', name='error') + + def test_get_upload_path_invalid_upload_dir_2(self): + with self.assertRaises(GenericError): + kojihub.get_upload_path(reldir='tasks/1', name='error', create=True) + + def test_get_upload_path_invalid_upload_dir_3(self): + with self.assertRaises(GenericError): + kojihub.get_upload_path(reldir='tasks/1/should_be_number', name='error', create=True) + + @mock.patch('kojihub.context') + @mock.patch('koji.pathinfo.work') + @mock.patch('kojihub.Host') + def test_get_upload_path_invalid_upload_dir_owner(self, host, work, context): + work.return_value = '/tmp' + cursor = mock.MagicMock() + context.cnx.cursor.return_value = cursor + reldir = 'fake/1/1' + fullpath = '{0}/{1}'.format(work.return_value, reldir) + os.makedirs(fullpath) + + with file('{0}/.user'.format(fullpath), 'wb') as f: + f.write('1') + + with self.assertRaises(GenericError): + kojihub.get_upload_path(reldir=reldir, name='error', create=True) + + shutil.rmtree('/tmp/fake') + + @mock.patch('koji.pathinfo.work') + @mock.patch('kojihub.Host') + def test_get_upload_path_invalid_upload_no_dir_owner(self, host, work): + work.return_value = '/tmp' + dir = kojihub.get_upload_path(reldir='tasks/1/1', name='error', create=False) + assert dir == '/tmp/tasks/1/1/error' +