Best Python code snippet using Kiwi_python
tests.py
Source:tests.py
...18 email='new-tester@example.com',19 password='password')20 @patch('tcms.core.contrib.auth.models.datetime')21 @patch('tcms.core.contrib.auth.models.random')22 def test_set_random_key(self, random, mock_datetime):23 mock_datetime.datetime.today.return_value = datetime.datetime(2017, 5, 10)24 mock_datetime.timedelta.return_value = datetime.timedelta(7)25 fake_random = 0.1234567826 random.random.return_value = fake_random27 activation_key = UserActivateKey.set_random_key_for_user(self.new_user)28 self.assertEqual(self.new_user, activation_key.user)29 s_random = sha1(str(fake_random).encode('utf-8')).hexdigest()[:5]30 expected_key = sha1('{}{}'.format(31 s_random, self.new_user.username).encode('utf-8')).hexdigest()32 self.assertEqual(expected_key, activation_key.activation_key)33 self.assertEqual(datetime.datetime(2017, 5, 17),34 activation_key.key_expires)35class TestForceToSetRandomKey(TestCase):36 """Test case for UserActivateKey.set_random_key_for_user forcely"""...
test_auth.py
Source:test_auth.py
...20 cls.new_user = User.objects.create(21 username="new-tester", email="new-tester@example.com", password="password"22 )23 @patch("tcms.auth.models.datetime")24 def test_set_random_key(self, mock_datetime):25 mock_datetime.datetime.today.return_value = datetime.datetime(2017, 5, 10)26 mock_datetime.timedelta.return_value = datetime.timedelta(7)27 uak = UserActivateKey.set_random_key_for_user(self.new_user)28 self.assertEqual(self.new_user, uak.user)29 self.assertTrue(is_hex(uak.activation_key), msg="Not a HEX string.")30 self.assertEqual(datetime.datetime(2017, 5, 17), uak.key_expires)31class TestForceToSetRandomKey(TestCase):32 """Test case for UserActivateKey.set_random_key_for_user forcely"""33 @classmethod34 def setUpTestData(cls):35 cls.new_user = User.objects.create(36 username="new-tester", email="new-tester@example.com", password="password"37 )38 cls.origin_activation_key = UserActivateKey.set_random_key_for_user(cls.new_user)...
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!!