Best Python code snippet using autotest_python
test_mngids.py
Source:test_mngids.py
...44 uids = {}45 mngids.parse(content, uids)46 orig = mngids.call_addgroup47 mngids.call_addgroup = lambda x: x48 mngids.parse_cmdline(cmd, uids, {})49 mngids.call_addgroup = orig50 self.assertEquals(cmd[1], '--uid')51 self.assertEquals(cmd[2], '0')52 def test_parsecmdline_group(self):53 cmd = 'adduser --gid nogroup root'.split(' ')54 passwd = 'root:x:0:1:root:/root:/bin/bash'55 group = 'nogroup:x:65534:'56 uids = {}57 gids = {}58 mngids.parse(passwd, uids)59 mngids.parse(group, gids, True)60 mngids.parse_cmdline(cmd, uids, gids)61 self.assertEquals(cmd[1], '--uid')62 self.assertEquals(cmd[2], '0')63 self.assertEquals(cmd[3], '--gid')64 self.assertEquals(cmd[4], '65534')65 def test_parsecmdline_addgroup(self):66 cmd = 'addgroup root'.split(' ')67 content = 'root:x:1:'68 gids = {}69 mngids.parse(content, gids)70 mngids.parse_cmdline(cmd, {}, gids)71 self.assertEquals(cmd[1], '--gid')72 self.assertEquals(cmd[2], '1')73 def test_parsecmdline_addgroup_path(self):74 cmd = './addgroup root'.split(' ')75 content = 'root:x:1:'76 gids = {}77 mngids.parse(content, gids, True)78 mngids.parse_cmdline(cmd, {}, gids)79 self.assertEquals(cmd[1], '--gid')80 self.assertEquals(cmd[2], '1')81 def test_parsecmdline_addgroup_noaction(self):82 cmd = 'addgroup --gid 2 root'.split(' ')83 content = 'root:x:1:'84 gids = {}85 mngids.parse(content, gids, True)86 l = len(cmd)87 mngids.parse_cmdline(cmd, {}, gids)88 self.assertEquals(len(cmd), l)89 self.assertEquals(cmd[2], '1')90 def test_parsecmdline_noaction(self):91 cmd = 'adduser --gid root root'.split(' ')92 l = len(cmd)93 passwd = 'root:x:0:1:root:/root:/bin/bash'94 group = 'root:x:1:'95 uids = {}96 gids = {}97 mngids.parse(passwd, uids)98 mngids.parse(group, gids, True)99 mngids.parse_cmdline(cmd, uids, gids)100 self.assertEquals(cmd[1], '--uid')101 self.assertEquals(cmd[2], '0')102 self.assertEquals(cmd[4], '1')103 self.assertEquals(len(cmd), l + 2)104 def test_parsecmdline_noaction1(self):105 cmd = 'adduser --uid 2 root'.split(' ')106 l = len(cmd)107 content = 'root:x:0:1:root:/root:/bin/bash'108 uids = {}109 mngids.parse(content, uids)110 orig = mngids.call_addgroup111 mngids.call_addgroup = lambda x: x112 mngids.parse_cmdline(cmd, uids, {})113 mngids.call_addgroup = orig114 self.assertEquals(cmd[1], '--gid')115 self.assertEquals(cmd[2], '1')116 self.assertEquals(cmd[4], '0')117 self.assertEquals(len(cmd), l + 2)118 def test_parsecmdline_addgroup_non_exist(self):119 cmd = 'addgroup root'.split(' ')120 content = 'user:x:1000:'121 gids = {}122 mngids.parse(content, gids)123 with self.assertRaises(KeyError):124 mngids.parse_cmdline(cmd, {}, gids)125 def test_parsecmdline_addgroup_without_name(self):126 cmd = 'addgroup -g 1000 -b /root'.split(' ')127 content = 'root:x:1:'128 gids = {}129 mngids.parse(content, gids)130 with self.assertRaises(KeyError):131 mngids.parse_cmdline(cmd, {}, gids)132 def test_parsecmdline_addgroup_with_missing_arg_value(self):133 cmd = 'groupadd --gid root'.split(' ')134 content = 'root:x:1:'135 gids = {}136 mngids.parse(content, gids)137 with self.assertRaises(KeyError):138 mngids.parse_cmdline(cmd, {}, gids)139 def test_parsecmdline_find_gu_name(self):140 # Be sure parse_cmdline is able to find username or groupname141 passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'142 group = 'cloud-users:x:1000:'143 uids = {}144 gids = {}145 mngids.parse(passwd, uids)146 mngids.parse(group, gids, True)147 cmd = ['useradd', 'jenkins', '--shell', '/bin/bash',148 '--gid', 'cloud-users',149 '--comment', 'eNovance Jenkins User', '-m']150 mngids.parse_cmdline(cmd, uids, gids)151 self.assertEquals(cmd[1], '--uid')152 self.assertEquals(cmd[2], '1000')153 self.assertEquals(cmd[7], '1000')154 cmd = ['useradd', '--shell', '/bin/bash',155 '--gid', 'cloud-users',156 '--comment', 'eNovance Jenkins User', '-m', 'jenkins']157 mngids.parse_cmdline(cmd, uids, gids)158 self.assertEquals(cmd[1], '--uid')159 self.assertEquals(cmd[2], '1000')160 self.assertEquals(cmd[6], '1000')161 cmd = ['useradd', '--shell', '/bin/bash',162 '--gid', 'cloud-users', 'jenkins',163 '--comment', 'eNovance Jenkins User', '-m']164 mngids.parse_cmdline(cmd, uids, gids)165 self.assertEquals(cmd[1], '--uid')166 self.assertEquals(cmd[2], '1000')167 self.assertEquals(cmd[6], '1000')168 cmd = ['groupadd', 'cloud-users']169 mngids.parse_cmdline(cmd, uids, gids)170 self.assertEquals(cmd[1], '--gid')171 self.assertEquals(cmd[2], '1000')172 # 1010 is replaced by what we have in gids (usually provided in ids.tables173 cmd = ['groupadd', '--gid', '1010', 'cloud-users', '-o']174 mngids.parse_cmdline(cmd, uids, gids)175 self.assertEquals(cmd[1], '--gid')176 self.assertEquals(cmd[2], '1000')177 cmd = ['groupadd', '--gid', '1010', '-f', 'cloud-users', '-o']178 mngids.parse_cmdline(cmd, uids, gids)179 self.assertEquals(cmd[1], '--gid')180 self.assertEquals(cmd[2], '1000')181 cmd = ['useradd', '--shell', '/bin/bash',182 '--gid', 'cloud-users', '-f', '10', 'jenkins',183 '--comment', 'eNovance Jenkins User', '-m']184 mngids.parse_cmdline(cmd, uids, gids)185 self.assertEquals(cmd[1], '--uid')186 self.assertEquals(cmd[2], '1000')187 self.assertEquals(cmd[6], '1000')188 def test_calls(self):189 passwd = 'jenkins:x:1000:1000::/home/jenkins:/bin/bash'190 group = 'jenkins:x:1000:'191 uids = {'john': ('1001', '1001')}192 gids = {'john': ('1001', '')}193 mngids.parse(passwd, uids)194 mngids.parse(group, gids, True)195 cmd = ['useradd', 'john']196 orig = mngids.call_addgroup197 mngids.call_addgroup = lambda x: x198 mngids.parse_cmdline(cmd, uids, gids)199 mngids.call_addgroup = orig200 self.assertEquals(cmd[1], '--uid')201 self.assertEquals(cmd[2], '1001')202 cmd = ['useradd', 'john', '-u', '1001']203 orig = mngids.call_addgroup204 mngids.call_addgroup = lambda x: x205 mngids.parse_cmdline(cmd, uids, gids)206 mngids.call_addgroup = orig207 self.assertEquals(cmd[1], '--gid')208 self.assertEquals(cmd[2], '1001')209 self.assertEquals(cmd[4], '-u')210 self.assertEquals(cmd[5], '1001')211 cmd = ['useradd', 'john', '-u', '1001', '-g', '1001']212 mngids.parse_cmdline(cmd, uids, gids)213 self.assertEquals(cmd[2], '-u')214 self.assertEquals(cmd[3], '1001')215 self.assertEquals(cmd[4], '-g')216 self.assertEquals(cmd[5], '1001')217 cmd = ['useradd', 'john', '-u', '1001', '-g', '1002']218 with self.assertRaises(KeyError):219 # KeyError: "mngids.py: 1002 not found (--gid) in [('1000', ''), ('1001', '')]"220 mngids.parse_cmdline(cmd, uids, gids)221 uids = {'john': ('1001', '1002')}222 gids = {'john': ('1002', '')}223 mngids.parse(passwd, uids)224 mngids.parse(group, gids, True)225 cmd = ['useradd', 'john', '-u', '1001']226 orig = mngids.call_addgroup227 mngids.call_addgroup = lambda x: x228 mngids.parse_cmdline(cmd, uids, gids)229 mngids.call_addgroup = orig230 self.assertEquals(cmd[1], '--gid')231 self.assertEquals(cmd[2], '1002')232 self.assertEquals(cmd[4], '-u')233 self.assertEquals(cmd[5], '1001')234GROUP = '''root:x:0:235daemon:x:1:236bin:x:2:237sys:x:3:238adm:x:4:ubuntu,syslog239tty:x:5:240disk:x:6:241lp:x:7:242mail:x:8:...
test_cmdline.py
Source:test_cmdline.py
1import pytest2import datetime3from main import parse_cmdline, get_fetch_options4# TODO:5# 1. parse_cmdline()6# 2. How to test for invalid commanlines?7# 3. Assert function called8"""9def test_parse_fetch():10 argv = "fetch"11 args = parse_cmdline(arg)12 assert(False, "Incomplete commandline should not be reached")13"""14def test_parse_fetch_eon():15 argv = ['fetch', 'enag99']16 args = parse_cmdline(argv)17 assert(args.stock == "enag99")18 assert(args.start_date == datetime.date.today())19 assert(args.end_date == datetime.date.today())20 assert(args.intra_day == None)21def test_parse_fetch_start_date():22 argvs = [['fetch','--start-date=1.2.2001', 'enag99'],23 ['fetch','-s', '1.2.2001', 'enag99']]24 for argv in argvs:25 args = parse_cmdline(argv)26 assert(args.stock == "enag99")27 assert(args.start_date == datetime.date(2001, 2, 1))28 assert(args.end_date == datetime.date.today())29def test_parse_fetch_end_date():30 argvs = [['fetch', '--start-date=2.1.2001', '--end-date=2.3.2001', 'enag99'],31 ['fetch', '-s', '2.1.2001', '-e', '2.3.2001', 'enag99']]32 33 for argv in argvs:34 args = parse_cmdline(argv)35 assert(args.stock == "enag99")36 assert(args.start_date == datetime.date(2001, 1, 2))37 assert(args.end_date == datetime.date(2001, 3, 2))38def test_parse_fetch_end_date():39 argvs = [['fetch', '--end-date=3.4.2001', 'enag99'],40 ['fetch', '-e', '3.4.2001', 'enag99']]41 for argv in argvs:42 args = parse_cmdline(argv)43 assert(args.stock == "enag99")44 assert(args.start_date == datetime.date.today())45 assert(args.end_date == datetime.date(2001, 4, 3))46def test_parse_fetch_start_date_formats():47 argv = [ ['fetch', '--start-date=1.2.2001', 'enag99'],48 ['fetch', '--start-date=2.3.2001', 'enag99'] ]49 date = [datetime.date(2001, 2, 1),50 datetime.date(2001, 3, 2)]51 assert(len(argv) == len(date))52 for idx in range(len(argv)):53 args = parse_cmdline(argv[idx])54 assert(args.stock == "enag99")55 assert(args.start_date == date[idx])56def test_parse_fetch_intraday():57 argv = ['fetch', '--intra-day', 'enag99']58 args = parse_cmdline(argv)59 assert(args.stock == "enag99")60 assert(args.start_date == datetime.date.today())61 assert(args.end_date == datetime.date.today())62 assert(args.intra_day == True)63def test_parse_fetch_intraday():64 argv = ['fetch', 'enag99']65 args = parse_cmdline(argv)66 assert(args.stock == "enag99")67 assert(args.start_date == datetime.date.today())68 assert(args.end_date == datetime.date.today())69 assert(args.intra_day == None) # TODO: Do we want it this way?70def test_options_fetch():71 argv = ['fetch', 'enag99']72 options = get_fetch_options(parse_cmdline(argv))73 assert(options['stock'] == "ENAG99")74 assert(options['start_date'] == datetime.date.today())75 assert(options['end_date'] == datetime.date.today())76 assert(options['fetchtype'] == 'daily')77def test_options_fetch_intraday():78 argv = ['fetch', '--intra-day', 'enag99']79 options = get_fetch_options(parse_cmdline(argv))80 assert(options['stock'] == "ENAG99")81 assert(options['start_date'] == datetime.date.today())82 assert(options['end_date'] == datetime.date.today())...
test_cli.py
Source:test_cli.py
1import pytest2from k8s.cli import parse_cmdline, Default3def test_resource_valid():4 assert parse_cmdline(["--resource", "nodes"]).resource == "nodes"5 assert parse_cmdline(["--resource", "deployments"]).resource == "deployments"6 assert parse_cmdline(["--resource", "pods"]).resource == "pods"7def test_resource_invalid():8 with pytest.raises(SystemExit):9 parse_cmdline(["--resource", "node"])10 with pytest.raises(SystemExit):11 parse_cmdline(["--resource", "PODS"])12 with pytest.raises(SystemExit):13 parse_cmdline(["--resource", "Deployments"])14 with pytest.raises(SystemExit):15 parse_cmdline([])16def test_opts():17 def parser(args):18 return parse_cmdline(["--resource", "nodes"] + args)19 assert parser(["--namespace", "test"]).namespace == "test"20 assert parser(["--namespace", "test,test2,test3"]).namespace == "test,test2,test3"21 assert parser(["--debug"]).debug is True22 assert parser(["--insecure"]).insecure is True23 assert parser(["--timeout", "123.0"]).timeout == 123.024 assert parser(["--port", "1234"]).port == 123425 assert parser(["--token", "token123"]).token == "token123"26 assert parser(["--ignore", "IgnoreResource", "--ignore", "IgnoreResourceAgain"]).expressions == ["IgnoreResource", "IgnoreResourceAgain"]27 assert parser(["--selector", "test"]).selector == "test"28 assert parser([]).debug is Default.debug.value29 assert parser([]).insecure is Default.insecure.value30 assert parser([]).timeout is Default.timeout.value31 assert parser([]).port is Default.port.value32 assert parser([]).host is Default.host.value33 assert parser([]).expressions is Default.ignore.value34 assert parser([]).selector is Default.selector.value35def test_token_file():36 def parser(args):37 return parse_cmdline(["--resource", "pods"] + args)38 assert parser(["--token_file", "tests/token.txt"]).token == "test"39def test_no_token_args():40 def parser(args):41 return parse_cmdline(["--resource", "pods"] + args)42 assert not parser(["--token", ""]).token43 assert not parser(["--token_file", ""]).token44 assert not parser(["--token_file", "", "--token", ""]).token45def test_no_namespace_arg():46 def parser(args):47 return parse_cmdline(["--resource", "pods"] + args)...
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!!