def meter(s): if s is None or len(s) < 1: return _PasswordStrength().INVALID met_counts = 0 if len(s) >= 8: met_counts += 1 if PasswordStrengthMeter.meets_containing_number_criteria(s): met_counts += 1 if PasswordStrengthMeter.meets_containing_uppercase_criteria(s): met_counts += 1 if met_counts == 1: return _PasswordStrength().WEAK if met_counts == 2: return _PasswordStrength().NORMAL return _PasswordStrength().STRONG
def test_constant(self): self.assertEqual(_PasswordStrength().STRONG, "STRONG")
def test_meets_only_num_criteria_then_weak(self): self.assertStrength("12345", _PasswordStrength().WEAK)
def test_meets_only_uppercase_criteria_then_weak(self): self.assertStrength("AFSBFD", _PasswordStrength().WEAK)
def test_meets_other_criteria_for_uppercase_then_normal(self): self.assertStrength("ab12!@df", _PasswordStrength().NORMAL)
def test_meets_only_length_criteria_then_weak(self): self.assertStrength("abdfsgid", _PasswordStrength().WEAK)
def test_empty_input_then_invalid(self): self.assertStrength("", _PasswordStrength().INVALID)
def test_null_input_then_invalid(self): self.assertStrength(None, _PasswordStrength().INVALID)
def test_meets_other_criteria_expect_for_number_then_normal(self): self.assertStrength("ab!@ABqw", _PasswordStrength().NORMAL)
def test_meets_other_criteria_expect_for_length_then_normal(self): self.assertStrength("ab12!@A", _PasswordStrength().NORMAL) self.assertStrength("Ab12!c", _PasswordStrength().NORMAL)
def test_meets_all_criteria_then_strong(self): self.assertStrength("ab!@#AB2", _PasswordStrength().STRONG) self.assertStrength("abc12@3D", _PasswordStrength().STRONG)