Best Python code snippet using localstack_python
test_toolkit.py
Source:test_toolkit.py
1# encoding: utf-82from nose.tools import assert_equal, assert_raises, assert_true, raises3from ckan.plugins import toolkit as tk4class TestCheckCkanVersion(object):5 @classmethod6 def setup_class(cls):7 # save the ckan version so it can be restored at the end of the test8 cls.__original_ckan_version = tk.ckan.__version__9 @classmethod10 def teardown_class(cls):11 # restore the correct ckan version12 tk.ckan.__version__ = cls.__original_ckan_version13 # test name numbers refer to:14 # * number of numbers in the ckan version15 # * number of numbers in the checked version16 # * the index of the number being tested in the checked version17 def test_min_111_lt(self):18 tk.ckan.__version__ = '2'19 assert_equal(tk.check_ckan_version(min_version='1'), True)20 def test_min_111_eq(self):21 tk.ckan.__version__ = '2'22 assert_equal(tk.check_ckan_version(min_version='2'), True)23 def test_min_111_gt(self):24 tk.ckan.__version__ = '2'25 assert_equal(tk.check_ckan_version(min_version='3'), False)26 def test_min_211_lt(self):27 tk.ckan.__version__ = '2.1'28 assert_equal(tk.check_ckan_version(min_version='1'), True)29 def test_min_211_gt(self):30 tk.ckan.__version__ = '2.1'31 assert_equal(tk.check_ckan_version(min_version='3'), False)32 def test_min_221_lt(self):33 tk.ckan.__version__ = '2.1'34 assert_equal(tk.check_ckan_version(min_version='1.1'), True)35 def test_min_221_eq(self):36 tk.ckan.__version__ = '2.1'37 assert_equal(tk.check_ckan_version(min_version='2.1'), True)38 def test_min_221_gt(self):39 tk.ckan.__version__ = '2.1'40 assert_equal(tk.check_ckan_version(min_version='3.1'), False)41 def test_min_222_lt(self):42 tk.ckan.__version__ = '1.5'43 assert_equal(tk.check_ckan_version(min_version='1.4'), True)44 def test_min_222_gt(self):45 tk.ckan.__version__ = '1.5'46 assert_equal(tk.check_ckan_version(min_version='1.6'), False)47 def test_min_231_lt(self):48 tk.ckan.__version__ = '2.2'49 assert_equal(tk.check_ckan_version(min_version='1.2.3'), True)50 def test_min_231_gt(self):51 tk.ckan.__version__ = '2.2'52 assert_equal(tk.check_ckan_version(min_version='3.2.1'), False)53 def test_min_232_lt(self):54 tk.ckan.__version__ = '2.2'55 assert_equal(tk.check_ckan_version(min_version='2.1.3'), True)56 def test_min_232_gt(self):57 tk.ckan.__version__ = '2.2'58 assert_equal(tk.check_ckan_version(min_version='2.3.0'), False)59 def test_min_233_lt(self):60 tk.ckan.__version__ = '2.2'61 assert_equal(tk.check_ckan_version(min_version='2.1.3'), True)62 def test_min_233_gt(self):63 tk.ckan.__version__ = '2.2'64 assert_equal(tk.check_ckan_version(min_version='2.2.1'), False)65 def test_min_321_lt(self):66 tk.ckan.__version__ = '1.5.1'67 assert_equal(tk.check_ckan_version(min_version='0.6'), True)68 def test_min_321_gt(self):69 tk.ckan.__version__ = '1.5.1'70 assert_equal(tk.check_ckan_version(min_version='2.4'), False)71 def test_min_322_lt(self):72 tk.ckan.__version__ = '1.5.1'73 assert_equal(tk.check_ckan_version(min_version='1.5'), True)74 def test_min_322_gt(self):75 tk.ckan.__version__ = '1.5.1'76 assert_equal(tk.check_ckan_version(min_version='1.6'), False)77 def test_min_331_lt(self):78 tk.ckan.__version__ = '1.5.1'79 assert_equal(tk.check_ckan_version(min_version='0.5.1'), True)80 def test_min_331_eq(self):81 tk.ckan.__version__ = '1.5.1'82 assert_equal(tk.check_ckan_version(min_version='1.5.1'), True)83 def test_min_331_gt(self):84 tk.ckan.__version__ = '1.5.1'85 assert_equal(tk.check_ckan_version(min_version='1.5.2'), False)86 def test_min_332_lt(self):87 tk.ckan.__version__ = '1.5.1'88 assert_equal(tk.check_ckan_version(min_version='1.4.1'), True)89 def test_min_332_gt(self):90 tk.ckan.__version__ = '1.5.1'91 assert_equal(tk.check_ckan_version(min_version='1.6.1'), False)92 def test_min_333_lt(self):93 tk.ckan.__version__ = '1.5.1'94 assert_equal(tk.check_ckan_version(min_version='1.5.0'), True)95 def test_min_333_gt(self):96 tk.ckan.__version__ = '1.5.1'97 assert_equal(tk.check_ckan_version(min_version='1.5.2'), False)98 def test_max_111_lt(self):99 tk.ckan.__version__ = '2'100 assert_equal(tk.check_ckan_version(max_version='1'), False)101 def test_max_111_eq(self):102 tk.ckan.__version__ = '2'103 assert_equal(tk.check_ckan_version(max_version='2'), True)104 def test_max_111_gt(self):105 tk.ckan.__version__ = '2'106 assert_equal(tk.check_ckan_version(max_version='3'), True)107 def test_max_211_lt(self):108 tk.ckan.__version__ = '2.1'109 assert_equal(tk.check_ckan_version(max_version='1'), False)110 def test_max_211_gt(self):111 tk.ckan.__version__ = '2.1'112 assert_equal(tk.check_ckan_version(max_version='3'), True)113 def test_max_221_lt(self):114 tk.ckan.__version__ = '2.1'115 assert_equal(tk.check_ckan_version(max_version='1.1'), False)116 def test_max_221_eq(self):117 tk.ckan.__version__ = '2.1'118 assert_equal(tk.check_ckan_version(max_version='2.1'), True)119 def test_max_221_gt(self):120 tk.ckan.__version__ = '2.1'121 assert_equal(tk.check_ckan_version(max_version='3.1'), True)122 def test_max_222_lt(self):123 tk.ckan.__version__ = '1.5'124 assert_equal(tk.check_ckan_version(max_version='1.4'), False)125 def test_max_222_gt(self):126 tk.ckan.__version__ = '1.5'127 assert_equal(tk.check_ckan_version(max_version='1.6'), True)128 def test_max_231_lt(self):129 tk.ckan.__version__ = '2.2'130 assert_equal(tk.check_ckan_version(max_version='1.2.3'), False)131 def test_max_231_gt(self):132 tk.ckan.__version__ = '2.2'133 assert_equal(tk.check_ckan_version(max_version='3.2.1'), True)134 def test_max_232_lt(self):135 tk.ckan.__version__ = '2.2'136 assert_equal(tk.check_ckan_version(max_version='2.1.3'), False)137 def test_max_232_gt(self):138 tk.ckan.__version__ = '2.2'139 assert_equal(tk.check_ckan_version(max_version='2.3.0'), True)140 def test_max_233_lt(self):141 tk.ckan.__version__ = '2.2'142 assert_equal(tk.check_ckan_version(max_version='2.1.3'), False)143 def test_max_233_gt(self):144 tk.ckan.__version__ = '2.2'145 assert_equal(tk.check_ckan_version(max_version='2.2.1'), True)146 def test_max_321_lt(self):147 tk.ckan.__version__ = '1.5.1'148 assert_equal(tk.check_ckan_version(max_version='0.6'), False)149 def test_max_321_gt(self):150 tk.ckan.__version__ = '1.5.1'151 assert_equal(tk.check_ckan_version(max_version='2.4'), True)152 def test_max_322_lt(self):153 tk.ckan.__version__ = '1.5.1'154 assert_equal(tk.check_ckan_version(max_version='1.5'), False)155 def test_max_322_gt(self):156 tk.ckan.__version__ = '1.5.1'157 assert_equal(tk.check_ckan_version(max_version='1.6'), True)158 def test_max_331_lt(self):159 tk.ckan.__version__ = '1.5.1'160 assert_equal(tk.check_ckan_version(max_version='0.5.1'), False)161 def test_max_331_eq(self):162 tk.ckan.__version__ = '1.5.1'163 assert_equal(tk.check_ckan_version(max_version='1.5.1'), True)164 def test_max_331_gt(self):165 tk.ckan.__version__ = '1.5.1'166 assert_equal(tk.check_ckan_version(max_version='1.5.2'), True)167 def test_max_332_lt(self):168 tk.ckan.__version__ = '1.5.1'169 assert_equal(tk.check_ckan_version(max_version='1.4.1'), False)170 def test_max_332_gt(self):171 tk.ckan.__version__ = '1.5.1'172 assert_equal(tk.check_ckan_version(max_version='1.6.1'), True)173 def test_max_333_lt(self):174 tk.ckan.__version__ = '1.5.1'175 assert_equal(tk.check_ckan_version(max_version='1.5.0'), False)176 def test_max_333_gt(self):177 tk.ckan.__version__ = '1.5.1'178 assert_equal(tk.check_ckan_version(max_version='1.5.2'), True)179class TestRequiresCkanVersion(object):180 @classmethod181 def setup_class(cls):182 # save the ckan version so it can be restored at the end of the test183 cls.__original_ckan_version = tk.ckan.__version__184 @classmethod185 def teardown_class(cls):186 # restore the correct ckan version187 tk.ckan.__version__ = cls.__original_ckan_version188 # Assume the min_version and max_version params work ok since they are just189 # passed to check_ckan_version which is tested above.190 def test_no_raise(self):191 tk.ckan.__version__ = '2'192 tk.requires_ckan_version(min_version='2')193 def test_raise(self):194 tk.ckan.__version__ = '2'195 assert_raises(tk.CkanVersionException,196 tk.requires_ckan_version, min_version='3')197class TestToolkitHelper(object):198 def test_call_helper(self):199 # the null_function would return ''200 assert_true(tk.h.icon_url('x'))201 def test_tk_helper_attribute_error_on_missing_helper(self):202 assert_raises(AttributeError, getattr,203 tk.h, 'not_a_real_helper_function')204 @raises(AttributeError)205 def test_tk_helper_as_attribute_missing_helper(self):206 '''Directly attempt access to module function'''207 tk.h.nothere()208 @raises(tk.HelperError)209 def test_tk_helper_as_item_missing_helper(self):210 '''Directly attempt access as item'''...
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!!