Best Python code snippet using stestr_python
auth_test.py
Source:auth_test.py  
...21    expected_count = 322    for x in range(expected_count):23      models.FailedLoginAttempt.create()24    # Set the config to show recaptcha with an end datetime of now.25    config = ufo.get_user_config()26    config.should_show_recaptcha = True27    config.recaptcha_start_datetime = start_datetime28    config.recaptcha_end_datetime = datetime.datetime.now()29    config.save()30    should_show_recaptcha, failed_attempts_count = auth.determine_if_recaptcha_should_be_turned_on_or_off()31    self.assertFalse(should_show_recaptcha)32    self.assertEquals(expected_count, failed_attempts_count)33    self.assertEquals(0, len(models.FailedLoginAttempt.get_all()))34    config = ufo.get_user_config()35    self.assertFalse(config.should_show_recaptcha)36  def testTurnOnRecaptchaIfRecaptchaWasOnAndFailedAttemptsOverMax(self):37    """Test recaptcha turns on if it was on and went over max failed login."""38    start_datetime = datetime.datetime.now()39    # Add enough failed attempts to the DB after start datetime to hit max.40    for x in range(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA):41      models.FailedLoginAttempt.create()42    # Set the config to show recaptcha with an end datetime of now.43    config = ufo.get_user_config()44    config.should_show_recaptcha = True45    config.recaptcha_start_datetime = start_datetime46    initial_delta = datetime.timedelta(minutes=5)47    end_datetime = start_datetime + initial_delta48    config.recaptcha_end_datetime = end_datetime49    config.save()50    test_datetime = datetime.datetime.now()51    should_show_recaptcha, failed_attempts_count = auth.determine_if_recaptcha_should_be_turned_on_or_off()52    self.assertTrue(should_show_recaptcha)53    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,54                      failed_attempts_count)55    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,56                      len(models.FailedLoginAttempt.get_all()))57    config = ufo.get_user_config()58    self.assertTrue(config.should_show_recaptcha)59    self.assertTrue(config.recaptcha_start_datetime >= test_datetime)60    self.assertTrue(config.recaptcha_end_datetime >= test_datetime)61    new_delta = config.recaptcha_end_datetime - config.recaptcha_start_datetime62    self.assertEquals(2*initial_delta, new_delta)63  def testTurnOnRecaptchaIfRecaptchaWasOffAndFailedAttemptsOverMax(self):64    """Test recaptcha turns on if it was off and went over max failed login."""65    # Add enough failed attempts to the DB after start datetime to hit max.66    for x in range(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA):67      models.FailedLoginAttempt.create()68    # Set the config to show recaptcha with an end datetime of now.69    config = ufo.get_user_config()70    config.should_show_recaptcha = False71    config.save()72    test_datetime = datetime.datetime.now()73    should_show_recaptcha, failed_attempts_count = auth.determine_if_recaptcha_should_be_turned_on_or_off()74    self.assertTrue(should_show_recaptcha)75    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,76                      failed_attempts_count)77    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,78                      len(models.FailedLoginAttempt.get_all()))79    config = ufo.get_user_config()80    self.assertTrue(config.should_show_recaptcha)81    self.assertTrue(config.recaptcha_start_datetime >= test_datetime)82    self.assertTrue(config.recaptcha_end_datetime >= test_datetime)83    new_delta = config.recaptcha_end_datetime - config.recaptcha_start_datetime84    default_delta = datetime.timedelta(85        minutes=auth.INITIAL_RECAPTCHA_TIMEFRAME_MINUTES)86    self.assertEquals(default_delta, new_delta)87  def testRecaptchaStaysOffIfNotConfigured(self):88    """Test recaptcha does not turn on if not configured."""89    # Add enough failed attempts to the DB after start datetime to hit max.90    for x in range(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA):91      models.FailedLoginAttempt.create()92    # Set the config to show recaptcha with an end datetime of now.93    config = ufo.get_user_config()94    config.should_show_recaptcha = False95    config.save()96    ufo.RECAPTCHA_ENABLED_FOR_APP = False97    test_datetime = datetime.datetime.now()98    should_show_recaptcha, failed_attempts_count = auth.determine_if_recaptcha_should_be_turned_on_or_off()99    self.assertFalse(should_show_recaptcha)100    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,101                      failed_attempts_count)102    self.assertEquals(ufo.MAX_FAILED_LOGINS_BEFORE_RECAPTCHA,103                      len(models.FailedLoginAttempt.get_all()))104    config = ufo.get_user_config()105    self.assertFalse(config.should_show_recaptcha)106if __name__ == '__main__':...test_get_user_config.py
Source:test_get_user_config.py  
...63    """64    Get config from a valid ~/.cookiecutterrc file65    """66    shutil.copy('tests/test-config/valid-config.yaml', user_config_path)67    conf = config.get_user_config()68    assert conf == custom_config69@pytest.mark.usefixtures('back_up_rc')70def test_get_user_config_invalid(user_config_path):71    """72    Get config from an invalid ~/.cookiecutterrc file73    """74    shutil.copy('tests/test-config/invalid-config.yaml', user_config_path)75    with pytest.raises(InvalidConfiguration):76        config.get_user_config()77@pytest.mark.usefixtures('back_up_rc')78def test_get_user_config_nonexistent():79    """80    Get config from a nonexistent ~/.cookiecutterrc file81    """82    assert config.get_user_config() == config.DEFAULT_CONFIG83@pytest.fixture84def custom_config_path(custom_config):85    return 'tests/test-config/valid-config.yaml'86def test_specify_config_path(mocker, custom_config_path, custom_config):87    spy_get_config = mocker.spy(config, 'get_config')88    user_config = config.get_user_config(custom_config_path)89    spy_get_config.assert_called_once_with(custom_config_path)90    assert user_config == custom_config91def test_default_config_path(user_config_path):92    assert config.USER_CONFIG_PATH == user_config_path93def test_default_config_from_env_variable(94        monkeypatch, custom_config_path, custom_config):95    monkeypatch.setenv('COOKIECUTTER_CONFIG', custom_config_path)96    user_config = config.get_user_config()97    assert user_config == custom_config98def test_force_default_config(mocker):99    spy_get_config = mocker.spy(config, 'get_config')100    user_config = config.get_user_config(None, default_config=True)101    assert user_config == config.DEFAULT_CONFIG102    assert not spy_get_config.called103def test_expand_user_for_directories_in_config(monkeypatch):104    def _expanduser(path):105        return path.replace('~', 'Users/bob')106    monkeypatch.setattr('os.path.expanduser', _expanduser)107    config_file = 'tests/test-config/config-expand-user.yaml'108    user_config = config.get_user_config(config_file)109    assert user_config['replay_dir'] == 'Users/bob/replay-files'110    assert user_config['cookiecutters_dir'] == 'Users/bob/templates'111def test_expand_vars_for_directories_in_config(monkeypatch):112    monkeypatch.setenv('COOKIES', 'Users/bob/cookies')113    config_file = 'tests/test-config/config-expand-vars.yaml'114    user_config = config.get_user_config(config_file)115    assert user_config['replay_dir'] == 'Users/bob/cookies/replay-files'...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!!
