Skip to content

Commit 7ff5b3f

Browse files
added previous secret testing.
1 parent df1e43d commit 7ff5b3f

File tree

2 files changed

+54
-67
lines changed

2 files changed

+54
-67
lines changed

tests/integration/conftest.py

Lines changed: 34 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -384,25 +384,36 @@ def person_table(dynamodb_resource: ServiceResource) -> Generator[Any]:
384384

385385

386386
@pytest.fixture
387-
def persisted_person(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
387+
def persisted_person(person_table: Any, faker: Faker,
388+
hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
388389

389390
nhs_num = faker.nhs_number()
390391
nhs_number = eligibility_status.NHSNumber(nhs_num)
392+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
391393

392-
nhs_num_hash = hmac.new(
393-
"test_value".encode("utf-8"),
394-
nhs_num.encode("utf-8"),
395-
hashlib.sha512,
396-
).hexdigest()
394+
date_of_birth = eligibility_status.DateOfBirth(faker.date_of_birth(minimum_age=18, maximum_age=65))
395+
396+
for row in (
397+
rows := person_rows_builder(nhs_num_hash, date_of_birth=date_of_birth, postcode="hp1", cohorts=["cohort1"]).data
398+
):
399+
person_table.put_item(Item=row)
400+
401+
yield nhs_number
402+
403+
for row in rows:
404+
person_table.delete_item(Key={"NHS_NUMBER": row["NHS_NUMBER"], "ATTRIBUTE_TYPE": row["ATTRIBUTE_TYPE"]})
405+
406+
@pytest.fixture
407+
def persisted_person_previous(person_table: Any, faker: Faker,
408+
hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
397409

398-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
399-
#nhs_number = eligibility_status.NHSNumber(nhs_num)
400-
#nhs_number = nhs_num_hash
410+
nhs_num = faker.nhs_number()
411+
nhs_number = eligibility_status.NHSNumber(nhs_num)
412+
nhs_num_hash = hashing_service.hash_with_previous_secret(nhs_num) # AWSPREVIOUS
401413

402414
date_of_birth = eligibility_status.DateOfBirth(faker.date_of_birth(minimum_age=18, maximum_age=65))
403415

404416
for row in (
405-
#rows := person_rows_builder(nhs_number, date_of_birth=date_of_birth, postcode="hp1", cohorts=["cohort1"]).data
406417
rows := person_rows_builder(nhs_num_hash, date_of_birth=date_of_birth, postcode="hp1", cohorts=["cohort1"]).data
407418
):
408419
person_table.put_item(Item=row)
@@ -414,24 +425,17 @@ def persisted_person(person_table: Any, faker: Faker) -> Generator[eligibility_s
414425

415426

416427
@pytest.fixture
417-
def persisted_77yo_person(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
418-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
428+
def persisted_77yo_person(person_table: Any, faker: Faker, hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
419429

420430
nhs_num = faker.nhs_number()
421431
nhs_number = eligibility_status.NHSNumber(nhs_num)
422-
423-
nhs_num_hash = hmac.new(
424-
"test_value".encode("utf-8"),
425-
nhs_num.encode("utf-8"),
426-
hashlib.sha512,
427-
).hexdigest()
432+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
428433

429434
date_of_birth = eligibility_status.DateOfBirth(faker.date_of_birth(minimum_age=77, maximum_age=77))
430435

431436
for row in (
432437
rows := person_rows_builder(
433438
nhs_num_hash,
434-
#nhs_number,
435439
date_of_birth=date_of_birth,
436440
postcode="hp1",
437441
cohorts=["cohort1", "cohort2"],
@@ -446,24 +450,17 @@ def persisted_77yo_person(person_table: Any, faker: Faker) -> Generator[eligibil
446450

447451

448452
@pytest.fixture
449-
def persisted_person_all_cohorts(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
450-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
453+
def persisted_person_all_cohorts(person_table: Any, faker: Faker, hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
451454

452455
nhs_num = faker.nhs_number()
453456
nhs_number = eligibility_status.NHSNumber(nhs_num)
454-
455-
nhs_num_hash = hmac.new(
456-
"test_value".encode("utf-8"),
457-
nhs_num.encode("utf-8"),
458-
hashlib.sha512,
459-
).hexdigest()
457+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
460458

461459
date_of_birth = eligibility_status.DateOfBirth(faker.date_of_birth(minimum_age=74, maximum_age=74))
462460

463461
for row in (
464462
rows := person_rows_builder(
465463
nhs_num_hash,
466-
# nhs_number,
467464
date_of_birth=date_of_birth,
468465
postcode="SW19",
469466
cohorts=["cohort_label1", "cohort_label2", "cohort_label3", "cohort_label4", "cohort_label5"],
@@ -479,17 +476,11 @@ def persisted_person_all_cohorts(person_table: Any, faker: Faker) -> Generator[e
479476

480477

481478
@pytest.fixture
482-
def person_with_all_data(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
483-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
479+
def person_with_all_data(person_table: Any, faker: Faker, hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
484480

485481
nhs_num = faker.nhs_number()
486482
nhs_number = eligibility_status.NHSNumber(nhs_num)
487-
488-
nhs_num_hash = hmac.new(
489-
"test_value".encode("utf-8"),
490-
nhs_num.encode("utf-8"),
491-
hashlib.sha512,
492-
).hexdigest()
483+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
493484

494485
date_of_birth = eligibility_status.DateOfBirth(datetime.date(1990, 2, 28))
495486

@@ -521,19 +512,11 @@ def person_with_all_data(person_table: Any, faker: Faker) -> Generator[eligibili
521512

522513

523514
@pytest.fixture
524-
def persisted_person_no_cohorts(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
525-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
526-
515+
def persisted_person_no_cohorts(person_table: Any, faker: Faker, hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
527516
nhs_num = faker.nhs_number()
528517
nhs_number = eligibility_status.NHSNumber(nhs_num)
518+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
529519

530-
nhs_num_hash = hmac.new(
531-
"test_value".encode("utf-8"),
532-
nhs_num.encode("utf-8"),
533-
hashlib.sha512,
534-
).hexdigest()
535-
536-
#for row in (rows := person_rows_builder(nhs_number).data):
537520
for row in (rows := person_rows_builder(nhs_num_hash).data):
538521
person_table.put_item(Item=row)
539522

@@ -544,21 +527,11 @@ def persisted_person_no_cohorts(person_table: Any, faker: Faker) -> Generator[el
544527

545528

546529
@pytest.fixture
547-
def persisted_person_pc_sw19(person_table: Any, faker: Faker) -> Generator[eligibility_status.NHSNumber]:
548-
# nhs_number = eligibility_status.NHSNumber(
549-
# faker.nhs_number(),
550-
# )
551-
530+
def persisted_person_pc_sw19(person_table: Any, faker: Faker, hashing_service: HashingService) -> Generator[eligibility_status.NHSNumber]:
552531
nhs_num = faker.nhs_number()
553532
nhs_number = eligibility_status.NHSNumber(nhs_num)
533+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
554534

555-
nhs_num_hash = hmac.new(
556-
"test_value".encode("utf-8"),
557-
nhs_num.encode("utf-8"),
558-
hashlib.sha512,
559-
).hexdigest()
560-
561-
#for row in (rows := person_rows_builder(nhs_number, postcode="SW19", cohorts=["cohort1"]).data):
562535
for row in (rows := person_rows_builder(nhs_num_hash, postcode="SW19", cohorts=["cohort1"]).data):
563536
person_table.put_item(Item=row)
564537

@@ -570,22 +543,16 @@ def persisted_person_pc_sw19(person_table: Any, faker: Faker) -> Generator[eligi
570543

571544
@pytest.fixture
572545
def persisted_person_with_no_person_attribute_type(
573-
person_table: Any, faker: Faker
546+
person_table: Any, faker: Faker, hashing_service: HashingService
574547
) -> Generator[eligibility_status.NHSNumber]:
575-
#nhs_number = eligibility_status.NHSNumber(faker.nhs_number())
548+
576549
date_of_birth = eligibility_status.DateOfBirth(faker.date_of_birth(minimum_age=18, maximum_age=65))
577550

578551
nhs_num = faker.nhs_number()
579552
nhs_number = eligibility_status.NHSNumber(nhs_num)
580-
581-
nhs_num_hash = hmac.new(
582-
"test_value".encode("utf-8"),
583-
nhs_num.encode("utf-8"),
584-
hashlib.sha512,
585-
).hexdigest()
553+
nhs_num_hash = hashing_service.hash_with_current_secret(nhs_num)
586554

587555
for row in (
588-
#rows := person_rows_builder(nhs_number, date_of_birth=date_of_birth, postcode="hp1", cohorts=["cohort1"]).data
589556
rows := person_rows_builder(nhs_num_hash, date_of_birth=date_of_birth, postcode="hp1", cohorts=["cohort1"]).data
590557
):
591558
if row["ATTRIBUTE_TYPE"] != "PERSON":

tests/integration/repo/test_person_repo.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ def test_person_found_with_current_secret(person_table: Any,
7171
nhs_num_hash_pre = hashing_service.hash_with_previous_secret(persisted_person)
7272

7373

74+
assert_that(
75+
actual.data,
76+
contains_inanyorder(
77+
has_entries({"NHS_NUMBER": nhs_num_hash, "ATTRIBUTE_TYPE": "PERSON"}),
78+
has_entries({"NHS_NUMBER": nhs_num_hash, "ATTRIBUTE_TYPE": "COHORTS"}),
79+
),
80+
)
81+
82+
def test_person_found_with_previous_secret(person_table: Any,
83+
persisted_person_previous: NHSNumber,
84+
hashing_service: HashingService):
85+
# Given
86+
repo = PersonRepo(person_table, hashing_service)
87+
88+
# When
89+
actual = repo.get_eligibility_data(persisted_person_previous)
90+
91+
# Then
92+
nhs_num_hash = hashing_service.hash_with_previous_secret(persisted_person_previous)
93+
7494
assert_that(
7595
actual.data,
7696
contains_inanyorder(

0 commit comments

Comments
 (0)