Best Python code snippet using autotest_python
test_models.py
Source:test_models.py
...33 enabled_for_all_courses=enabled_for_all_courses,34 course_id=self.course_id_1,35 enabled_for_course=enabled_for_course_136 ):37 self.assertEqual(PersistentGradesEnabledFlag.feature_enabled(), global_flag)38 self.assertEqual(39 PersistentGradesEnabledFlag.feature_enabled(self.course_id_1),40 global_flag and (enabled_for_all_courses or enabled_for_course_1)41 )42 self.assertEqual(43 PersistentGradesEnabledFlag.feature_enabled(self.course_id_2),44 global_flag and enabled_for_all_courses45 )46 def test_enable_disable_course_flag(self):47 """48 Ensures that the flag, once enabled for a course, can also be disabled.49 """50 with persistent_grades_feature_flags(51 global_flag=True,52 enabled_for_all_courses=False,53 course_id=self.course_id_1,54 enabled_for_course=True55 ):56 self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))57 # Prior to TNL-5698, creating a second object would fail due to db constraints58 with persistent_grades_feature_flags(59 global_flag=True,60 enabled_for_all_courses=False,61 course_id=self.course_id_1,62 enabled_for_course=False63 ):64 self.assertFalse(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))65 def test_enable_disable_globally(self):66 """67 Ensures that the flag, once enabled globally, can also be disabled.68 """69 with persistent_grades_feature_flags(70 global_flag=True,71 enabled_for_all_courses=True,72 ):73 self.assertTrue(PersistentGradesEnabledFlag.feature_enabled())74 self.assertTrue(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))75 with persistent_grades_feature_flags(76 global_flag=True,77 enabled_for_all_courses=False,78 ):79 self.assertTrue(PersistentGradesEnabledFlag.feature_enabled())80 self.assertFalse(PersistentGradesEnabledFlag.feature_enabled(self.course_id_1))81 with persistent_grades_feature_flags(82 global_flag=False,83 ):84 self.assertFalse(PersistentGradesEnabledFlag.feature_enabled())...
test_tacacsplus.py
Source:test_tacacsplus.py
...18 client = mock.MagicMock()19 client.authenticate.side_effect=Exception("foo")20 with mock.patch('awx.sso.backends.django_settings') as settings,\21 mock.patch('awx.sso.backends.logger') as logger,\22 mock.patch('awx.sso.backends.feature_enabled', feature_enabled('enterprise_auth')),\23 mock.patch('tacacs_plus.TACACSClient', return_value=client):24 settings.TACACSPLUS_HOST = 'localhost'25 settings.TACACSPLUS_AUTH_PROTOCOL = 'ascii'26 ret_user = tacacsplus_backend.authenticate(u"user", u"pass")27 assert ret_user is None28 logger.exception.assert_called_once_with(29 "TACACS+ Authentication Error: foo"30 )31def test_client_return_invalid_fails_auth(tacacsplus_backend, feature_enabled):32 auth = mock.MagicMock()33 auth.valid = False34 client = mock.MagicMock()35 client.authenticate.return_value = auth36 with mock.patch('awx.sso.backends.django_settings') as settings,\37 mock.patch('awx.sso.backends.feature_enabled', feature_enabled('enterprise_auth')),\38 mock.patch('tacacs_plus.TACACSClient', return_value=client):39 settings.TACACSPLUS_HOST = 'localhost'40 settings.TACACSPLUS_AUTH_PROTOCOL = 'ascii'41 ret_user = tacacsplus_backend.authenticate(u"user", u"pass")42 assert ret_user is None43def test_client_return_valid_passes_auth(tacacsplus_backend, feature_enabled):44 auth = mock.MagicMock()45 auth.valid = True46 client = mock.MagicMock()47 client.authenticate.return_value = auth48 user = mock.MagicMock()49 user.has_usable_password = mock.MagicMock(return_value=False)50 with mock.patch('awx.sso.backends.django_settings') as settings,\51 mock.patch('awx.sso.backends.feature_enabled', feature_enabled('enterprise_auth')),\52 mock.patch('tacacs_plus.TACACSClient', return_value=client),\53 mock.patch('awx.sso.backends._get_or_set_enterprise_user', return_value=user):54 settings.TACACSPLUS_HOST = 'localhost'55 settings.TACACSPLUS_AUTH_PROTOCOL = 'ascii'56 ret_user = tacacsplus_backend.authenticate(u"user", u"pass")...
Check out the latest blogs from LambdaTest on this topic:
There are times when developers get stuck with a problem that has to do with version changes. Trying to run the code or test without upgrading the package can result in unexpected errors.
Agile project management is a great alternative to traditional methods, to address the customer’s needs and the delivery of business value from the beginning of the project. This blog describes the main benefits of Agile for both the customer and the business.
While there is a huge demand and need to run Selenium Test Automation, the experts always suggest not to automate every possible test. Exhaustive Testing is not possible, and Automating everything is not sustainable.
Hola Testers! Hope you all had a great Thanksgiving weekend! To make this time more memorable, we at LambdaTest have something to offer you as a token of appreciation.
Sometimes, in our test code, we need to handle actions that apparently could not be done automatically. For example, some mouse actions such as context click, double click, drag and drop, mouse movements, and some special key down and key up actions. These specific actions could be crucial depending on the project context.
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!!