Exemple #1
0
def validate_data(data):
    valid_args = ["byr", "iyr", "eyr", "hgt", "hcl", "ecl", "pid"]
    valid_count = 0
    valid_and_complete_count = 0
    for line in data:
        line_valid_count = 0
        for arg in valid_args:
            if arg not in line:
                print(f"{arg} not in {line}")
            else:
                line_valid_count += 1
        if line_valid_count == len(valid_args):
            valid_count += 1
            params = make_dict_from_line(line)
            validation_results = [
                validate_date(params["byr"], 1920, 2002),
                validate_date(params["iyr"], 2010, 2020),
                validate_date(params["eyr"], 2020, 2030),
                validate_hgt(params["hgt"]),
                validate_hcl(params["hcl"]),
                validate_ecl(params["ecl"]),
                validate_pid(params["pid"]),
            ]
            if sum(validation_results) == len(valid_args):
                valid_and_complete_count += 1
    print(f"Valid passports: {valid_count}")
    print(f"Valid and complete passports: {valid_and_complete_count}")
Exemple #2
0
def lambda_handler(event, context):
    eligible_persons = []

    with open(FILE_NAME, "r") as f:
        csv_dictreader = csv.DictReader(f)
        for r in csv_dictreader:
            print(r.get("beginning_date"))
            valid = validate_date(r.get("beginning_date"), r.get("Frequency"))
            if valid:
                eligible_persons.append(r.get("Person"))
    print(eligible_persons)

    eligible_persons = ",".join(eligible_persons)
    ret_val = send_mail(eligible_persons)
    status_body = "Successfully sent the mail" if ret_val else "Some shit!"
    return {"statusCode": 200, "body": json.dumps(status_body)}
Exemple #3
0
 def test_closure(self):
     validator = validate_date()
     validator(date.today())
     with self.assertRaises(TypeError):
         validator(datetime.now())
Exemple #4
0
    def test_required(self):
        validate_date(None, required=False)

        with self.assertRaises(TypeError):
            validate_date(None)
Exemple #5
0
 def test_invalid_type(self):
     with self.assertRaises(TypeError):
         validate_date("1970-01-01T12:00:00+00:00")
Exemple #6
0
 def test_repr(self):
     validator = validate_date(required=False)
     self.assertEqual(
         repr(validator),
         'validate_date(required=False)',
     )
Exemple #7
0
 def test_datetime(self):
     with self.assertRaises(TypeError):
         validate_date(datetime.now())
Exemple #8
0
 def test_valid(self):
     validate_date(date.today())
 def test_valid(self):  # type: () -> None
     validate_date(date.today())
 def test_closure_valid(self):  # type() -> None
     validator = validate_date()
     validator(date.today())
 def test_not_required(self):  # type: () -> None
     validate_date(None, required=False)