Best Python code snippet using green
test_models.py
Source:test_models.py
...31 @classmethod32 def setUpClass(cls):33 super().setUpClass()34 cls.field = cls.user_meta.get_field("username")35 def test_blank(self):36 self.assertFalse(self.field.blank)37 def test_error_messages(self):38 error_messages = {"unique": "A user with that username already exists."}39 self.assertDictContainsSubset(error_messages, self.field.error_messages)40 def test_help_text(self):41 help_text = (42 "Required. 150 characters or fewer. Letters, digits and @/./+/-/_ only."43 )44 self.assertEqual(self.field.help_text, help_text)45 def test_max_length(self):46 self.assertEqual(self.field.max_length, 150)47 def test_null(self):48 self.assertFalse(self.field.null)49 def test_unique(self):50 self.assertTrue(self.field.unique)51 def test_validators(self):52 self.assertEqual(len(self.field.validators), 2)53 self.assertIsInstance(54 self.field.validators[0],55 import_string("django.contrib.auth.validators.UnicodeUsernameValidator"),56 )57 def test_verbose_name(self):58 self.assertEqual(self.field.verbose_name, "username")59class UserEmailTestCase(UserModelFieldsTestCase):60 @classmethod61 def setUpClass(cls):62 super().setUpClass()63 cls.field = cls.user_meta.get_field("email")64 def test_blank(self):65 self.assertTrue(self.field.blank)66 def test_max_length(self):67 self.assertEqual(self.field.max_length, 254)68 def test_null(self):69 self.assertFalse(self.field.null)70 def test_unique(self):71 self.assertFalse(self.field.unique)72 def test_verbose_name(self):73 self.assertEqual(self.field.verbose_name, "email address")74class UserPasswordTestCase(UserModelFieldsTestCase):75 @classmethod76 def setUpClass(cls):77 super().setUpClass()78 cls.field = cls.user_meta.get_field("password")79 def test_blank(self):80 self.assertFalse(self.field.blank)81 def test_max_length(self):82 self.assertEqual(self.field.max_length, 128)83 def test_null(self):84 self.assertFalse(self.field.null)85 def test_verbose_name(self):86 self.assertEqual(self.field.verbose_name, "password")87class UserFirstNameTestCase(UserModelFieldsTestCase):88 @classmethod89 def setUpClass(cls):90 super().setUpClass()91 cls.field = cls.user_meta.get_field("first_name")92 def test_blank(self):93 self.assertTrue(self.field.blank)94 def test_max_length(self):95 self.assertEqual(self.field.max_length, 150)96 def test_null(self):97 self.assertFalse(self.field.null)98 def test_verbose_name(self):99 self.assertEqual(self.field.verbose_name, "first name")100class UserLastNameTestCase(UserModelFieldsTestCase):101 @classmethod102 def setUpClass(cls):103 super().setUpClass()104 cls.field = cls.user_meta.get_field("last_name")105 def test_blank(self):106 self.assertTrue(self.field.blank)107 def test_max_length(self):108 self.assertEqual(self.field.max_length, 150)109 def test_null(self):110 self.assertFalse(self.field.null)111 def test_verbose_name(self):112 self.assertEqual(self.field.verbose_name, "last name")113class UserIsSuperUserTestCase(UserModelFieldsTestCase):114 @classmethod115 def setUpClass(cls):116 super().setUpClass()117 cls.field = cls.user_meta.get_field("is_superuser")118 def test_blank(self):119 self.assertFalse(self.field.blank)120 def test_default(self):121 self.assertEqual(self.field.default, False)122 def test_help_text(self):123 help_text = "Designates that this user has all permissions without"124 help_text += " explicitly assigning them."125 self.assertEqual(self.field.help_text, help_text)126 def test_null(self):127 self.assertFalse(self.field.null)128 def test_verbose_name(self):129 self.assertEqual(self.field.verbose_name, "superuser status")130class UserIsStaffTestCase(UserModelFieldsTestCase):131 @classmethod132 def setUpClass(cls):133 super().setUpClass()134 cls.field = cls.user_meta.get_field("is_staff")135 def test_blank(self):136 self.assertFalse(self.field.blank)137 def test_default(self):138 self.assertEqual(self.field.default, False)139 def test_help_text(self):140 help_text = "Designates whether the user can log into this admin site."141 self.assertEqual(self.field.help_text, help_text)142 def test_null(self):143 self.assertFalse(self.field.null)144 def test_verbose_name(self):145 self.assertEqual(self.field.verbose_name, "staff status")146class UserIsActiveTestCase(UserModelFieldsTestCase):147 @classmethod148 def setUpClass(cls):149 super().setUpClass()150 cls.field = cls.user_meta.get_field("is_active")151 def test_blank(self):152 self.assertFalse(self.field.blank)153 def test_default(self):154 self.assertEqual(self.field.default, True)155 def test_help_text(self):156 help_text = "Designates whether this user should be treated as active."157 help_text += " Unselect this instead of deleting accounts."158 self.assertEqual(self.field.help_text, help_text)159 def test_null(self):160 self.assertFalse(self.field.null)161 def test_verbose_name(self):162 self.assertEqual(self.field.verbose_name, "active")163class UserDateJoinedTestCase(UserModelFieldsTestCase):164 @classmethod165 def setUpClass(cls):166 super().setUpClass()167 cls.field = cls.user_meta.get_field("date_joined")168 def test_blank(self):169 self.assertFalse(self.field.blank)170 def test_default(self):171 self.assertEqual(self.field.default, import_string("django.utils.timezone.now"))172 def test_null(self):173 self.assertFalse(self.field.null)174 def test_verbose_name(self):175 self.assertEqual(self.field.verbose_name, "date joined")176class UserLastLoginTestCase(UserModelFieldsTestCase):177 @classmethod178 def setUpClass(cls):179 super().setUpClass()180 cls.field = cls.user_meta.get_field("last_login")181 def test_blank(self):182 self.assertTrue(self.field.blank)183 def test_null(self):184 self.assertTrue(self.field.null)185 def test_verbose_name(self):186 self.assertEqual(self.field.verbose_name, "last login")187class UserGroupsTestCase(UserModelFieldsTestCase):188 @classmethod189 def setUpClass(cls):190 super().setUpClass()191 cls.field = cls.user_meta.get_field("groups")192 def test_blank(self):193 self.assertTrue(self.field.blank)194 def test_help_text(self):195 help_text = "The groups this user belongs to."196 help_text += " A user will get all permissions granted to each of their groups."197 self.assertEqual(self.field.help_text, help_text)198 def test_is_relation(self):199 self.assertTrue(self.field.is_relation)200 def test_many_to_many(self):201 self.assertTrue(self.field.many_to_many)202 def test_null(self):203 self.assertFalse(self.field.null)204 def test_related_model(self):205 self.assertEqual(206 self.field.related_model, import_string("django.contrib.auth.models.Group")207 )208 def test_verbose_name(self):209 self.assertEqual(self.field.verbose_name, "groups")210class UserPermissionsTestCase(UserModelFieldsTestCase):211 @classmethod212 def setUpClass(cls):213 super().setUpClass()214 cls.field = cls.user_meta.get_field("user_permissions")215 def test_blank(self):216 self.assertTrue(self.field.blank)217 def test_help_text(self):218 help_text = "Specific permissions for this user."219 self.assertEqual(self.field.help_text, help_text)220 def test_is_relation(self):221 self.assertTrue(self.field.is_relation)222 def test_many_to_many(self):223 self.assertTrue(self.field.many_to_many)224 def test_null(self):225 self.assertFalse(self.field.null)226 def test_related_model(self):227 self.assertEqual(228 self.field.related_model,229 import_string("django.contrib.auth.models.Permission"),...
HW10_Sumit_Oberoi_Test.py
Source:HW10_Sumit_Oberoi_Test.py
1import unittest2from repository import Repository3""" Test class for printable output in PrettyTable """4class TestRepository(unittest.TestCase):5 """ Test class for printable output in PrettyTable """6 def test_student_info(self):7 """Function to test students details """8 test_blank = "/Users/sumitoberoi/Documents/SSW-810/HW09/TestBlank"9 repo = Repository(test_blank)10 self.assertEqual(len(repo.get_students_details()),0)11 self.assertEqual(repo.get_students_details(),[])12 self.assertEqual(repo.get_majors_details(),[])13 test_one_student = "/Users/sumitoberoi/Documents/SSW-810/HW09/TestOneStudent"14 repo = Repository(test_one_student)15 self.assertEqual(len(repo.get_students_details()),1)16 self.assertEqual(repo.get_majors_details(),[['SFEN', ['SSW 810'], []]])17 self.assertEqual(repo.get_students_details()[0], ['10103', 'Jobs, S', 'SFEN', ['SSW 810'], None, []])18 def test_instructor_info(self):19 """Function to test instructors details """20 test_blank = "/Users/sumitoberoi/Documents/SSW-810/HW09/TestBlank"21 repo = Repository(test_blank)22 self.assertEqual(len(repo.get_instructors_details()),0)23 self.assertEqual(repo.get_instructors_details(),[])24 test_one_student = "/Users/sumitoberoi/Documents/SSW-810/HW09/TestOneStudent"25 repo = Repository(test_one_student)26 self.assertEqual(len(repo.get_instructors_details()),1)27 self.assertEqual(repo.get_instructors_details()[0],['98763', 'Cohen, R', 'SFEN', 'SSW 810', 1])28 def test_read_from_db(self):29 """ Method to test read from db """30 dir_path = "/Users/sumitoberoi/Documents/SSW-810/HW09/Stevens"31 db_path = "/Users/sumitoberoi/Documents/SSW-810/HW09/HW11.db"32 repo = Repository(dir_path)33 print("Res",repo.get_instructors_details_from_db(db_path))34 res_expected = [(98762, 'Hawking, S', 'CS', 'CS 501', 1), 35 (98762, 'Hawking, S', 'CS', 'CS 546', 1),36 (98762, 'Hawking, S', 'CS', 'CS 570', 1), (98763, 'Rowland, J', 'SFEN', 'SSW 555', 1),37 (98763, 'Rowland, J', 'SFEN', 'SSW 810', 4), 38 (98764, 'Cohen, R', 'SFEN', 'CS 546', 1)]39 self.assertEqual(repo.get_instructors_details_from_db(db_path), res_expected)40if __name__ == "__main__":...
9a5c08e386564bd0b97b28289b585da5.py
Source:9a5c08e386564bd0b97b28289b585da5.py
2 def hey(self, msg):3 self.inquiry = msg4 return self.resolve()5 def resolve(self):6 if not self.test_blank():7 response = 'Whatever.'8 if self.test_question():9 response = 'Sure.'10 if self.test_caps():11 response = 'Woah, chill out!'12 else:13 response = "Fine. Be that way."14 return response15 def test_blank(self):16 if not self.inquiry or \17 self.inquiry.isspace():18 return True19 else:20 return False21 def test_question(self):22 if self.inquiry.endswith('?'):23 return True24 else:25 return False26 def test_caps(self):27 if self.inquiry.isupper():28 return True29 else:...
13d9da35c4ee404897ec6d76cea5f939.py
Source:13d9da35c4ee404897ec6d76cea5f939.py
2 def hey(self, msg):3 self.inquiry = msg4 return self.resolve()5 def resolve(self):6 if not self.test_blank():7 response = 'Whatever.'8 if self.test_question():9 response = 'Sure.'10 if self.test_caps():11 response = 'Woah, chill out!'12 else:13 response = "Fine. Be that way."14 return response15 def test_blank(self):16 if not self.inquiry or \17 self.inquiry.isspace():18 return True19 else:20 return False21 def test_question(self):22 return self.inquiry.endswith('?')23 def test_caps(self):...
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!!