#98 Add test cases for delete_build() function
Merged 7 years ago by mikem. Opened 7 years ago by sijis.

@@ -0,0 +1,73 @@ 

+ import mock

+ import unittest

+ import kojihub

+ import time

+ from koji import GenericError

+ from collections import defaultdict

+ 

+ 

+ class TestDeleteBuild(unittest.TestCase):

+ 

+     @mock.patch('kojihub.context')

+     @mock.patch('kojihub.get_build')

+     def test_delete_build_raise_error(self, build, context):

+ 

+         references = ['tags', 'rpms', 'archives', 'images']

+         for ref in references:

+             context = mock.MagicMock()

+             context.session.return_value = context
mikem commented 7 years ago

I'm not that familar with using the mock module. Is it really correct to make this self-referential?

+ 

+             with mock.patch('kojihub.build_references') as refs:

+                 retval = defaultdict(dict)

+                 retval[ref] = True

+                 refs.return_value = retval

+                 with self.assertRaises(GenericError):

+                     kojihub.delete_build(build='', strict=True)

+ 

+     @mock.patch('kojihub.context')

+     @mock.patch('kojihub.get_build')

+     def test_delete_build_return_false(self, build, context):

+ 

+         references = ['tags', 'rpms', 'archives', 'images']

+         for ref in references:

+             context = mock.MagicMock()

+             context.session.return_value = context

+ 

+             with mock.patch('kojihub.build_references') as refs:

+                 retval = defaultdict(dict)

+                 retval[ref] = True

+                 refs.return_value = retval

+                 assert kojihub.delete_build(build='', strict=False) is False

+ 

+     @mock.patch('kojihub.context')

+     @mock.patch('kojihub.get_build')

+     def test_delete_build_check_last_used_raise_error(self, build, context):

+ 

+         references = ['tags', 'rpms', 'archives', 'images', 'last_used']

+         for ref in references:

+             context = mock.MagicMock()

+             context.session.return_value = context

+ 

+             with mock.patch('kojihub.build_references') as refs:

+                 retval = defaultdict(dict)

+                 if ref == 'last_used':

+                     retval[ref] = time.time()+100

+                     refs.return_value = retval

+                     with self.assertRaises(GenericError):

+                         kojihub.delete_build(build='', strict=True)

+ 

+     @mock.patch('kojihub.context')

+     @mock.patch('kojihub.get_build')

+     def test_delete_build_check_last_used_raise_error(self, build, context):

+ 

+         references = ['tags', 'rpms', 'archives', 'images', 'last_used']

+         for ref in references:

+             context = mock.MagicMock()

+             context.session.return_value = context

+ 

+             with mock.patch('kojihub.build_references') as refs:

+                 retval = defaultdict(dict)

+                 if ref == 'last_used':

+                     retval[ref] = time.time()+100

+                     refs.return_value = retval

+                     assert kojihub.delete_build(build='', strict=False) is False

Adding more test cases.

The test for key 'last_used' had to be broken down separately since it contained a time constraint check.

I'm not that familar with using the mock module. Is it really correct to make this self-referential?

You can. Ralph would know the true 'magic' of that. He was using that
snippet for another test case he was using and told me about it.

Sijis
On Jun 7, 2016 4:20 PM, pagure@pagure.io wrote:

mikem commented on the pull-request: Add test cases for delete_build() function that you are following:
I'm not that familar with using the mock module. Is it really correct to make this self-referential?

To reply, visit the link below or just reply to this email
https://pagure.io/koji/pull-request/98

Commit dfaa593 fixes this pull-request

Pull-Request has been merged by mikem@redhat.com

7 years ago
Metadata