Best Python code snippet using tox_python
test_create_maven_build.py
Source:test_create_maven_build.py
1import unittest2import mock3import koji4import kojihub5IP = kojihub.InsertProcessor6class TestCreateMavenBuild(unittest.TestCase):7 def setUp(self):8 self.get_build = mock.patch('kojihub.get_build').start()9 self.exports = kojihub.RootExports()10 self.session = mock.MagicMock()11 self.context = mock.patch('kojihub.context').start()12 self.context.session.assertPerm = mock.MagicMock()13 self.InsertProcessor = mock.patch('kojihub.InsertProcessor',14 side_effect=self.getInsert).start()15 self.inserts = []16 self.insert_execute = mock.MagicMock()17 self.get_build_info = {18 'id': 100,19 'name': 'test_name',20 'version': 'test_version',21 'release': 'test_release',22 'epoch': 'test_epoch',23 'owner': 'test_owner',24 'build_id': 2,25 }26 self.build_info = 'test-build-11-12'27 def getInsert(self, *args, **kwargs):28 insert = IP(*args, **kwargs)29 insert.execute = self.insert_execute30 self.inserts.append(insert)31 return insert32 def test_maven_info_empty_dict(self):33 maven_info = {}34 self.get_build.return_value = self.get_build_info35 with self.assertRaises(koji.GenericError) as cm:36 self.exports.createMavenBuild(self.build_info, maven_info)37 self.assertEqual("Maven info is empty", str(cm.exception))38 self.assertEqual(len(self.inserts), 0)39 def test_maven_info_without_some_key(self):40 # maven_info without group_id41 maven_info = {42 'artifact_id': '99',43 'version': '33'44 }45 self.get_build.return_value = self.get_build_info46 with self.assertRaises(koji.GenericError) as cm:47 self.exports.createMavenBuild(self.build_info, maven_info)48 self.assertEqual("Maven info doesn't have mandatory 'group_id' key", str(cm.exception))49 self.assertEqual(len(self.inserts), 0)50 # maven_info without artifact_id51 maven_info = {52 'group_id': '11',53 'version': '33'54 }55 self.get_build.return_value = self.get_build_info56 with self.assertRaises(koji.GenericError) as cm:57 self.exports.createMavenBuild(self.build_info, maven_info)58 self.assertEqual("Maven info doesn't have mandatory 'artifact_id' key", str(cm.exception))59 self.assertEqual(len(self.inserts), 0)60 # maven_info without version61 maven_info = {62 'group_id': '11',63 'artifact_id': '99',64 }65 self.get_build.return_value = self.get_build_info66 with self.assertRaises(koji.GenericError) as cm:67 self.exports.createMavenBuild(self.build_info, maven_info)68 self.assertEqual("Maven info doesn't have mandatory 'version' key", str(cm.exception))69 self.assertEqual(len(self.inserts), 0)70 def test_empty_wrong_format_maven_info(self):71 maven_info = 'maven-wrong-info'72 self.get_build.return_value = self.get_build_info73 with self.assertRaises(koji.GenericError) as cm:74 self.exports.createMavenBuild(self.build_info, maven_info)75 self.assertEqual('Invalid type for maven_info: %s' % type(maven_info), str(cm.exception))76 self.assertEqual(len(self.inserts), 0)77 def test_empty_wrong_format_non_exist_build_info(self):78 maven_info = {79 'group_id': '11',80 'artifact_id': '99',81 'version': '33'82 }83 self.get_build.return_value = None84 with self.assertRaises(koji.GenericError) as cm:85 self.exports.createMavenBuild(self.build_info, maven_info)86 self.assertEqual(87 'Invalid type for build_info: %s' % type(self.build_info), str(cm.exception))88 self.assertEqual(len(self.inserts), 0)89 def test_build_info_without_some_mandatory_key(self):90 maven_info = {91 'group_id': '11',92 'artifact_id': '99',93 'version': '33'94 }95 # build_info without name96 get_build_info = {97 'id': 100,98 'version': 'test_version',99 'release': 'test_release',100 'epoch': 'test_epoch',101 }102 self.get_build.return_value = None103 with self.assertRaises(koji.GenericError) as cm:104 self.exports.createMavenBuild(get_build_info, maven_info)105 self.assertEqual("Build info doesn't have mandatory 'name' key", str(cm.exception))106 self.assertEqual(len(self.inserts), 0)107 # build_info without version108 get_build_info = {109 'id': 100,110 'name': 'test_name',111 'release': 'test_release',112 'epoch': 'test_epoch',113 }114 self.get_build.return_value = None115 with self.assertRaises(koji.GenericError) as cm:116 self.exports.createMavenBuild(get_build_info, maven_info)117 self.assertEqual("Build info doesn't have mandatory 'version' key", str(cm.exception))118 self.assertEqual(len(self.inserts), 0)119 # build_info without release120 get_build_info = {121 'id': 100,122 'name': 'test_name',123 'version': 'test_version',124 'epoch': 'test_epoch',125 }126 self.get_build.return_value = None127 with self.assertRaises(koji.GenericError) as cm:128 self.exports.createMavenBuild(get_build_info, maven_info)129 self.assertEqual("Build info doesn't have mandatory 'release' key", str(cm.exception))130 self.assertEqual(len(self.inserts), 0)131 # build_info without epoch132 get_build_info = {133 'id': 100,134 'name': 'test_name',135 'version': 'test_version',136 'release': 'test_release',137 }138 self.get_build.return_value = None139 with self.assertRaises(koji.GenericError) as cm:140 self.exports.createMavenBuild(get_build_info, maven_info)141 self.assertEqual("Build info doesn't have mandatory 'epoch' key", str(cm.exception))...
test_create_win_build.py
Source:test_create_win_build.py
1import unittest2import mock3import koji4import kojihub5IP = kojihub.InsertProcessor6class TestCreateWinBuild(unittest.TestCase):7 def setUp(self):8 self.get_build = mock.patch('kojihub.get_build').start()9 self.exports = kojihub.RootExports()10 self.session = mock.MagicMock()11 self.context = mock.patch('kojihub.context').start()12 self.context.session.assertPerm = mock.MagicMock()13 self.InsertProcessor = mock.patch('kojihub.InsertProcessor',14 side_effect=self.getInsert).start()15 self.inserts = []16 self.insert_execute = mock.MagicMock()17 self.get_build_info = {18 'id': 100,19 'name': 'test_name',20 'version': 'test_version',21 'release': 'test_release',22 'epoch': 'test_epoch',23 'owner': 'test_owner',24 'extra': {'extra_key': 'extra_value'},25 'build_id': 2,26 }27 self.build_info = 'test-build-11-12'28 def getInsert(self, *args, **kwargs):29 insert = IP(*args, **kwargs)30 insert.execute = self.insert_execute31 self.inserts.append(insert)32 return insert33 def test_win_info_empty_dict(self):34 win_info = {}35 self.get_build.return_value = self.get_build_info36 with self.assertRaises(koji.GenericError) as cm:37 self.exports.createWinBuild(self.build_info, win_info)38 self.assertEqual("Windows info is empty", str(cm.exception))39 self.assertEqual(len(self.inserts), 0)40 def test_win_info_without_platform(self):41 win_info = {42 'test-key': 'test-value'43 }44 self.get_build.return_value = self.get_build_info45 with self.assertRaises(koji.GenericError) as cm:46 self.exports.createWinBuild(self.build_info, win_info)47 self.assertEqual("Windows info doesn't have mandatory platform key", str(cm.exception))48 self.assertEqual(len(self.inserts), 0)49 def test_empty_wrong_format_win_info(self):50 win_info = 'platform'51 self.get_build.return_value = self.get_build_info52 with self.assertRaises(koji.GenericError) as cm:53 self.exports.createWinBuild(self.build_info, win_info)54 self.assertEqual('Invalid type for win_info: %s' % type(win_info), str(cm.exception))55 self.assertEqual(len(self.inserts), 0)56 def test_empty_wrong_format_non_exist_build_info(self):57 win_info = {58 'platform': 'test-value'59 }60 self.get_build.return_value = None61 with self.assertRaises(koji.GenericError) as cm:62 self.exports.createWinBuild(self.build_info, win_info)63 self.assertEqual(64 'Invalid type for build_info: %s' % type(self.build_info), str(cm.exception))65 self.assertEqual(len(self.inserts), 0)66 def test_build_info_without_some_mandatory_key(self):67 win_info = {68 'platform': 'test-value'69 }70 # build_info without name71 get_build_info = {72 'id': 100,73 'version': 'test_version',74 'release': 'test_release',75 'epoch': 'test_epoch',76 }77 self.get_build.return_value = None78 with self.assertRaises(koji.GenericError) as cm:79 self.exports.createWinBuild(get_build_info, win_info)80 self.assertEqual("Build info doesn't have mandatory 'name' key", str(cm.exception))81 self.assertEqual(len(self.inserts), 0)82 # build_info without version83 get_build_info = {84 'id': 100,85 'name': 'test_name',86 'release': 'test_release',87 'epoch': 'test_epoch',88 }89 self.get_build.return_value = None90 with self.assertRaises(koji.GenericError) as cm:91 self.exports.createWinBuild(get_build_info, win_info)92 self.assertEqual("Build info doesn't have mandatory 'version' key", str(cm.exception))93 self.assertEqual(len(self.inserts), 0)94 # build_info without release95 get_build_info = {96 'id': 100,97 'name': 'test_name',98 'version': 'test_version',99 'epoch': 'test_epoch',100 }101 self.get_build.return_value = None102 with self.assertRaises(koji.GenericError) as cm:103 self.exports.createWinBuild(get_build_info, win_info)104 self.assertEqual("Build info doesn't have mandatory 'release' key", str(cm.exception))105 self.assertEqual(len(self.inserts), 0)106 # build_info without epoch107 get_build_info = {108 'id': 100,109 'name': 'test_name',110 'version': 'test_version',111 'release': 'test_release',112 }113 self.get_build.return_value = None114 with self.assertRaises(koji.GenericError) as cm:115 self.exports.createWinBuild(get_build_info, win_info)116 self.assertEqual("Build info doesn't have mandatory 'epoch' key", str(cm.exception))...
tasks.py
Source:tasks.py
...14 start_time = time()15 data = {}16 sleep(10)17 while True:18 if (jenkins.get_build_info(project_name, number)) == "SUCCESS":19 data["release_status"] = 120 # print(data)21 # Deploy.objects.filter(pk=pk).update(**data)22 break23 elif (jenkins.get_build_info(project_name, number)) == "ABORTED":24 data["release_status"] = 225 # print(data)26 # Deploy.objects.filter(pk=pk).update(**data)27 break28 elif (jenkins.get_build_info(project_name, number)) == "FAILURE" or (time() - start_time) > 600:29 jenkins.stop_build(project_name, number)30 data["release_status"] = 331 # print(data)32 # Deploy.objects.filter(pk=pk).update(**data)33 break34 else:35 console_output = jenkins.get_build_console_output(project_name, number)36 data['console_output'] = console_output37 Deploy.objects.filter(pk=pk).update(**data)38 console_output = jenkins.get_build_console_output(project_name, number)39 data['console_output'] = console_output40 # data['status'] = 441 Deploy.objects.filter(pk=pk).update(**data)42 return project_name4344 # return '[{}] Project release completed.......'.format(project_name)45# return Response(serializer.data)4647# @app.task(name='release')48# def release_code(pk,deploy):49# jenkins = JenkinsApi()50# start_time = time()51# number = jenkins.get_next_build_number(deploy["project_name"])52# data = {}53# sleep(15)54# while True:55# if (jenkins.get_build_info(deploy["project_name"], number)) == "SUCCESS":56# release_status = 157# deploy['release_status'] = release_status58# print(data)59# Deploy.objects.filter(pk=pk).update(**deploy)60#61# break62# elif (jenkins.get_build_info(deploy["project_name"], number)) == "ABORTED":63# release_status = 364# deploy['release_status'] = release_status65# print(data)66# Deploy.objects.filter(pk=pk).update(**deploy)67# # deploy.save()68# break69# # elif (jenkins.get_build_info(project_name, number)) == "FAILURE" or (time() - start_time) > 300:70# elif (jenkins.get_build_info(deploy["project_name"], number)) == "FAILURE":71# release_status = 272# deploy['release_status'] = release_status73# print(data)74# Deploy.objects.filter(pk=pk).update(**deploy)75# # deploy.save()76# break77 # return '[{}] Project release completed.......'.format(project_name)
...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!