Best Python code snippet using avocado_python
unit_testing.py
Source:unit_testing.py
...46 slotLeft=2547 )48 def tearDown(self):49 self.c2 = None50 def test_get_dict(self):51 self.assertEqual(self.c2.get_dict(), {52 "courseName": 'Introduction to life', 53 "cohortName": "G0",54 "enrollmentStartDate": "01 Sep 1998",55 "enrollmentStartTime": "00:00", 56 "enrollmentEndDate": "28 Oct 1998", 57 "enrollmentEndTime": "23:59", 58 "cohortStartDate": "01 Nov 1998", 59 "cohortStartTime": "08:00", 60 "cohortEndDate": "30 Nov 1998", 61 "cohortEndTime": "20:00", 62 "trainerName": "Marcus", 63 "cohortSize": 30, 64 "slotLeft": 2565 })66 def test_get_enrollment_info(self):67 self.assertEqual(self.c2.get_enrollment_info(), {68 "courseName": 'Introduction to life', 69 "cohortName": "G0",70 "cohortStartDate": "01 Nov 1998", 71 "cohortStartTime": "08:00", 72 "cohortEndDate": "30 Nov 1998", 73 "cohortEndTime": "20:00", 74 "trainerName": "Marcus", 75 "cohortSize": 30, 76 "slotLeft": 2577 })78 def test_get_slotLeft(self):79 self.assertEqual(self.c2.get_slotLeft(), 25)80 def test_get_trainerName(self):81 self.assertEqual(self.c2.get_trainerName(), "Marcus") 82 def test_reduce_slot(self):83 # initial slot = 2584 self.assertEqual(self.c2.get_slotLeft(), 25)85 # reduce slot86 self.c2.reduce_slot()87 # check if slot reduced by 1; 2488 self.assertEqual(self.c2.get_slotLeft(), 24)89 def test_set_enrollment_details(self):90 # check initial enrollment details91 self.assertEqual(self.c2.get_dict(), {92 "courseName": 'Introduction to life', 93 "cohortName": "G0",94 "enrollmentStartDate": "01 Sep 1998",95 "enrollmentStartTime": "00:00", 96 "enrollmentEndDate": "28 Oct 1998", 97 "enrollmentEndTime": "23:59", 98 "cohortStartDate": "01 Nov 1998", 99 "cohortStartTime": "08:00", 100 "cohortEndDate": "30 Nov 1998", 101 "cohortEndTime": "20:00", 102 "trainerName": "Marcus", 103 "cohortSize": 30, 104 "slotLeft": 25105 })106 # update enrollment details107 self.c2.set_enrollment_details("05 Sep 1998", "12:00", "25 Oct 1998", "23:00")108 # check updated enrollment details109 self.assertEqual(self.c2.get_dict(), {110 "courseName": 'Introduction to life', 111 "cohortName": "G0",112 "enrollmentStartDate": "05 Sep 1998",113 "enrollmentStartTime": "12:00", 114 "enrollmentEndDate": "25 Oct 1998", 115 "enrollmentEndTime": "23:00", 116 "cohortStartDate": "01 Nov 1998", 117 "cohortStartTime": "08:00", 118 "cohortEndDate": "30 Nov 1998", 119 "cohortEndTime": "20:00", 120 "trainerName": "Marcus", 121 "cohortSize": 30, 122 "slotLeft": 25123 })124# shathees125class TestBadges(unittest.TestCase):126 def setUp(self):127 self.b1 = badges(employeeName="Alice", badges="Introduction to life", cohortName="G0")128 def tearDown(self):129 self.b1 = None130 def test_get_badges(self):131 self.assertEqual(self.b1.get_badges(), "Introduction to life")132 def get_badges_cohort(self):133 self.assertEqual(self.b1.get_badges_cohort(), {134 'badges': "Introduction to life",135 'cohortName': "G0"136 })137# marcus138class TestEnrollment(unittest.TestCase):139 def setUp(self):140 self.e2 = enrollment(employeeName="Alice", courseNameEnrolled="Introduction to life", cohortNameEnrolled="G0", recent=1)141 def tearDown(self):142 self.e2 = None143 def test_get_enrollment_info(self):144 self.assertEqual(self.e2.get_enrollment_info(), {145 'courseNameEnrolled' : "Introduction to life",146 'cohortNameEnrolled' : "G0"147 })148 def test_get_employeeName(self):149 self.assertEqual(self.e2.get_employeeName(), "Alice")150 def test_get_dict(self):151 self.assertEqual(self.e2.get_dict(), {152 'employeeName': 'Alice', 153 'courseNameEnrolled': 154 'Introduction to life', 155 'cohortNameEnrolled': 'G0', 156 'recent': 1157 })158# shi ting159class TestEnrollmentRequest(unittest.TestCase):160 def setUp(self):161 self.e3 = enrollmentRequest(courseNameRequest="Introduction to life", cohortNameRequest="G0", learnerName="Bob")162 def tearDown(self):163 self.e3 = None164 def test_get_dict(self):165 self.assertEqual(self.e3.get_dict(), {166 "courseNameRequest": "Introduction to life",167 "cohortNameRequest": "G0",168 "learnerName": "Bob"169 })170# shi ting171class TestChapter(unittest.TestCase):172 def setUp(self):173 self.c3 = chapter(174 courseName="Introduction to life",175 cohortName="G1",176 chapterID=1,177 duration=60,178 graded=0179 )180 def tearDown(self):181 self.c3 = None182 def test_get_dict(self):183 self.assertEqual(self.c3.get_dict(), {184 "courseName":"Introduction to life",185 "cohortName":"G1",186 "chapterID":1,187 "duration":60,188 "graded":0189 })190 def test_update_chapter_data(self):191 # Initial chapter data; duration = 60, graded=0192 self.assertEqual(self.c3.get_dict(), {193 "courseName":"Introduction to life",194 "cohortName":"G1",195 "chapterID":1,196 "duration":60,197 "graded":0198 })199 # update chapter data; duration = 120, graded= 1200 self.c3.update_chapter_data(duration=120, graded=1)201 # Check if chapter data updated202 self.assertEqual(self.c3.get_dict(), {203 "courseName":"Introduction to life",204 "cohortName":"G1",205 "chapterID":1,206 "duration":120,207 "graded":1208 })209# vera210class TestQuestion(unittest.TestCase):211 def setUp(self):212 self.q1 = question(213 courseName="Introduction to life",214 cohortName="G1",215 chapterID=1,216 questionID=1,217 questionText="What is the meaning of our existence?"218 )219 def tearDown(self):220 self.q1 = None221 def test_get_dict(self):222 self.assertEqual(self.q1.get_dict(), {223 "courseName":"Introduction to life",224 "cohortName":"G1",225 "chapterID":1,226 "questionID":1,227 "questionText":"What is the meaning of our existence?"228 })229# marcus230class TestOptions(unittest.TestCase):231 def setUp(self):232 self.o1 = options(233 courseName="Introduction to life",234 cohortName="G1",235 chapterID=1,236 questionID=1,237 optionID=1,238 optionText="Meaning is like an equation - add or subtract value variables, and you get more or less meaning.",239 isRight=1240 )241 def tearDown(self):242 self.o1 = None243 def test_get_dict(self):244 self.assertEqual(self.o1.get_dict(), {245 "courseName":"Introduction to life",246 "cohortName":"G1",247 "chapterID":1,248 "questionID":1,249 "optionID":1,250 "optionText":"Meaning is like an equation - add or subtract value variables, and you get more or less meaning.",251 "isRight":1252 })253# charles254class TestMaterials(unittest.TestCase):255 def setUp(self):256 self.m1 = materials(257 courseName="Introduction to life",258 cohortName="G1",259 chapterID=1,260 materialID=1,261 materialURL= "abcd"262 )263 def tearDown(self):264 self.m1 = None265 def test_get_dict(self):266 self.assertEqual(self.m1.get_dict(), {267 "courseName":"Introduction to life",268 "cohortName":"G1",269 "chapterID":1,270 "materialID":1,271 "materialURL":"abcd"272 })273 def test_get_url(self):274 self.assertEqual(self.m1.get_url(), "abcd")275 def test_get_materialID(self):276 self.assertEqual(self.m1.get_materialID(), 1)277# charles278class TestmaterialStatus(unittest.TestCase):279 def setUp(self):280 self.o1 = materialStatus(281 courseName="Introduction to life",282 cohortName="G1",283 chapterID=1,284 materialID=1,285 employeeName='Bob',286 done = 0287 )288 def tearDown(self):289 self.o1 = None290 def test_get_dict(self):291 self.assertEqual(self.o1.get_dict(), {292 "courseName":"Introduction to life",293 "cohortName":"G1",294 "chapterID":1,295 "materialID":1,296 "employeeName":"Bob",297 "done":0298 })299 def test_status(self):300 self.assertEqual(self.o1.get_status(), 0)301 def test_update_status(self):302 # initial status303 self.assertEqual(self.o1.get_status(), 0)304 # update status305 self.o1.update_status()306 # check status update307 self.assertEqual(self.o1.get_status(), 1)308# charles309class TestuserAttempt(unittest.TestCase):310 def setUp(self):311 self.m1 = userAttempt(312 employeeName = "Bob",313 courseName="Introduction to life",314 cohortName="G1",315 chapterID= 1,316 questionID= 1,317 choiceID= 1,318 marks = 1319 )320 def tearDown(self):321 self.m1 = None322 def test_get_dict(self):323 self.assertEqual(self.m1.get_dict(), {324 "employeeName" : "Bob",325 "courseName":"Introduction to life",326 "cohortName":"G1",327 "chapterID":1,328 "questionID":1,329 "choiceID": 1,330 "marks": 1331 })332 def test_get_choiceID(self):333 self.assertEqual(self.m1.get_choice(), 1)334 335if __name__ == "__main__":336 unittest.main()
test_resources.py
Source:test_resources.py
1import unittest2from ingresse_acl.resources import *3class testSdkResource(unittest.TestCase):4 def test_get_dict(self):5 expected = None6 item = SdkResource()7 self.assertEqual(expected, item.get_dict())8class testUser(unittest.TestCase):9 def test_get_dict(self):10 expected = {"id": 1, "email": "user1@ing.com", "ingresseId": 1}11 item = User(expected)12 self.assertItemsEqual(expected, item.get_dict())13class testRole(unittest.TestCase):14 def test_get_dict(self):15 expected = {16 "id": 1,17 "name": "name-1",18 "alias": "alias 1",19 "description": "desc 1",20 "system": True21 }22 item = Role(expected)23 self.assertItemsEqual(expected, item.get_dict())24class testPermission(unittest.TestCase):25 def test_get_dict(self):26 expected = {27 "id": 1,28 "name": "name-1",29 "alias": "alias 1",30 "description": "desc 1"31 }32 item = Permission(expected)33 self.assertItemsEqual(expected, item.get_dict())34class testResource(unittest.TestCase):35 def test_get_dict(self):36 expected = {37 "id": 1,38 "name": "name-1",39 "alias": "alias 1",40 "description": "desc 1"41 }42 item = Resource(expected)43 self.assertItemsEqual(expected, item.get_dict())44class testContext(unittest.TestCase):45 def test_get_dict(self):46 expected = {47 "id": 1,48 "name": "name-1",49 "alias": "alias 1",50 "description": "desc 1"51 }52 item = Context(expected)53 self.assertItemsEqual(expected, item.get_dict())54class testRolePermission(unittest.TestCase):55 def test_get_dict(self):56 perm = {57 "permission": "perm",58 "resourceName": "res-1",59 "contextName": "ctx-1",60 "resourceValue": "val1",61 "contextValue": "val2"62 }63 item = RolePermission(perm)64 expected = {65 "permission": "perm",66 "resource": "res-1",67 "resourceValue": "val1",68 "context": "ctx-1",69 "contextValue": "val2"70 }71 self.assertItemsEqual(expected, item.get_dict())72class testUserPermission(unittest.TestCase):73 def test_get_dict(self):74 perm = {75 "permission": "perm",76 "resourceName": "res-1",77 "contextName": "ctx-1",78 "resourceValue": "val1",79 "contextValue": "val2"80 }81 item = UserPermission(perm)82 expected = {83 "permission": "perm",84 "resource": "res-1",85 "resourceValue": "val1",86 "context": "ctx-1",87 "contextValue": "val2"...
csv_parser.py
Source:csv_parser.py
...64def test_parse_line():65 assert parse_line('"c,d","e\\"f"') == ['c,d', 'e"f']66 assert parse_line('"c,d","e\\"f\\"') == ['c,d', 'e"f"']67 assert parse_line('"c,d","\\"e\\"f\\"') == ['c,d', '"e"f"']68def test_get_dict():69 assert get_dict(["col1","col2"],70 ["dat1","dat2"]) == {'col2': 'dat2', 'col1': 'dat1'}71def test_parse_csv():72 assert parse_csv('column1,column2\n"a",b\n"c,d","e\\"f"') == [73 {'column1': 'a', 'column2': 'b'}, {'column1': 'c,d', 'column2': 'e"f'}]74 assert parse_csv('column1,column2\n"a",b\n"c,d","\\"e\\"f\\"') == [75 {'column1': 'a', 'column2': 'b'}, {'column1': 'c,d', 'column2': '"e"f"'}]76if __name__ == "__main__":77 test_parse_line()78 test_get_dict()...
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!!