Skip to content

Commit

Permalink
adding integration tests for payroll ingestion
Browse files Browse the repository at this point in the history
  • Loading branch information
DenisDDBT committed Jan 29, 2025
1 parent 8b05ed2 commit 3d85012
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 0 deletions.
104 changes: 104 additions & 0 deletions payroll/tests/services/test_ingest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
import os
import pytest
from django.core.files import File

from chartofaccountDIT.test.factories import ProgrammeCodeFactory
from costcentre.test.factories import CostCentreFactory
from gifthospitality.test.factories import GradeFactory
from ...services.ingest import import_payroll

@pytest.fixture(autouse=True)
def setup(db):
cost_centre_codes=[888812,888813,888814]
programme_codes=["338887","338888","338889"]
grade_codes=["SEO",
"SCS",
"HEO",
"Grade 7",
"Grade 6",
"Faststream",
"EO",
"Contractor",
"AO",
"AA"]
cost_centres = [CostCentreFactory(cost_centre_code=id) for id in cost_centre_codes]
programmes=[ProgrammeCodeFactory(programme_code=id) for id in programme_codes]
grades=[GradeFactory(grade=id) for id in grade_codes]
yield


def test_ingest_payroll_success(db):
"""Testing valid records"""
test_data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'test_assets')
csv_file = os.path.join(test_data_dir, 'valid_records.csv')
with open(csv_file, 'rb') as f:
try:
result = import_payroll(File(f))
print(result)
except Exception as e:
result = {

'created': [],
'updated': [],
'failed': [],
'error': str(e)
}
assert len(result.get('failed'))== 0
assert result.get('error') is None
assert result.get('created')==15

def test_ingest_payroll_failed_record(db):
"""Testing failed records"""
test_data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'test_assets')
csv_file = os.path.join(test_data_dir, 'mixed_records.csv')
with open(csv_file, 'rb') as f:
try:
result = import_payroll(File(f))
except Exception as e:
result = {

'created': [],
'updated': [],
'failed': [],
'error': str(e)
}
assert result.get('failed') is not None

def test_ingest_payroll_error(db):
"""Testing mall structured csv file"""
test_data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'test_assets')
csv_file = os.path.join(test_data_dir, 'error.csv')
with open(csv_file, 'rb') as f:
try:
result = import_payroll(File(f))
except Exception as e:
result = {

'created': [],
'updated': [],
'failed': [],
'error': str(e)
}
print(result)
assert result.get('error') is not None

def test_ingest_payroll_update(db):
"""Testing update record functionality"""
test_data_dir = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'test_assets')
csv_file = os.path.join(test_data_dir, 'valid_records.csv')
with open(csv_file, 'rb') as f:
try:
result = import_payroll(File(f))
result = import_payroll(File(f))
except Exception as e:
result = {

'created': [],
'updated': [],
'failed': [],
'error': str(e)
}
assert len(result.get('failed'))== 0
assert result.get('error') is None
assert result.get('updated')==15
assert result.get('created')==0
24 changes: 24 additions & 0 deletions payroll/tests/test_assets/error.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
employee_no,first_name,last_name,cost_centre_code,programme_code,grade,assignment_status,fte,basic_pay,ernic,pension
150891,Charlotte,Wilson,1888812,338887,SEO,Secondment In - Unpaid,0,268154,674128,646780
150892,Jack,Wright,888813,338888,SCS,Loan Out - Non Payroll,0,0,0,0
150893,Oliver,Thomas,888814,338889,HEO,Secondment In - Unpaid,0,91692,109058,467950



150894,Lucy,Wilson,888812,338887,Grade 7,Secondment In - Unpaid,0,541545,821337,353586
150895,Lucy,Brown,888813,338888,Grade 6,Active Assignment,1,225309,951986,988960
150896,Emily,Taylor,888814,338889,Faststream,Active Assignment,1,768384,552567,321801
150897,Elizabeth,Brown,888812,338887,EO,Loan In - Payroll,1,823719,706068,254764
150898,Elizabeth,Williams,888813,338888,Contractor,Loan Out - Non Payroll,0,0,0,0
150899,George,Williams,888814,338889,AO,Loan In - Payroll,1,827779,759096,925580
150900,Lucy,Roberts,888812,338887,AA,Loan In - Payroll,1,294191,170873,757744
150901,Charlie,Brown,888813,338888,SEO,Loan In - Payroll,1,149978,671475,802482
150902,George,Jones,888814,338889,SCS,Loan In - Payroll,1,641702,475572,480622
150903,Emma,Taylor,888812,338887,HEO-1,Loan In - Payroll,1,875298,451712,586056
150904,Lucy,Smith,1888813,338888,Grade 7,Loan In - Payroll,1,130034,946561,673974
150905,Alice,Davies,888814,338889,Grade 6,Secondment In - Unpaid,0,762957,720411,922423
150906,Emma,Wilson,1888812,338887,Faststream,Loan In - Payroll,1,445218,840452,580614
150907,Lucy,Jones,888813,338888,EO,Loan Out - Non Payroll,0,0,0,0
150908,Oliver,Evans,888814,338889,Contractor,Secondment Out - Paid,1,314034,274579,327408
150909,Jack,Smithhhh,888814,338887,AO,Loan Out - Non Payroll,0,0,0,0
150910,George,Davies,888812,338888,Some GRADE,Secondment Out - Paid,1,360808,296336,883975
24 changes: 24 additions & 0 deletions payroll/tests/test_assets/mixed_records.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
employee_no,first_name,last_name,cost_centre_code,programme_code,grade,assignment_status,fte,basic_pay,ernic,pension
150891,Charlotte,Wilson,1888812,338887,SEO,Secondment In - Unpaid,0,268154,674128,646780
150892,Jack,Wright,888813,338888,SCS,Loan Out - Non Payroll,0,0,0,0
150893,Oliver,Thomas,888814,338889,HEO,Secondment In - Unpaid,0,91692,109058,467950



150894,Lucy,Wilson,888812,338887,Grade 7,Secondment In - Unpaid,0,541545,821337,353586
150895,Lucy,Brown,888813,338888,Grade 6,Active Assignment,1,225309,951986,988960
150896,Emily,Taylor,888814,338889,Faststream,Active Assignment,1,768384,552567,321801
150897,Elizabeth,Brown,888812,338887,EO,Loan In - Payroll,1,823719,706068,254764
150898,Elizabeth,Williams,888813,338888,Contractor,Loan Out - Non Payroll,0,0,0,0
150899,George,Williams,888814,338889,AO,Loan In - Payroll,1,827779,759096,925580
150900,Lucy,Roberts,888812,338887,AA,Loan In - Payroll,1,294191,170873,757744
150901,Charlie,Brown,888813,338888,SEO,Loan In - Payroll,1,149978,671475,802482
150902,George,Jones,888814,338889,SCS,Loan In - Payroll,1,641702,475572,480622
150903,Emma,Taylor,888812,338887,HEO-1,Loan In - Payroll,1,875298,451712,586056
150904,Lucy,Smith,1888813,338888,Grade 7,Loan In - Payroll,1,130034,946561,673974
150905,Alice,Davies,888814,338889,Grade 6,Secondment In - Unpaid,0,762957,720411,922423
150906,Emma,Wilson,1888812,338887,Faststream,Loan In - Payroll,1,445218,840452,580614
150907,Lucy,Jones,888813,338888,EO,Loan Out - Non Payroll,0,0,0,0
150908,Oliver,Evans,888814,338889,Contractor,Secondment Out - Paid,1,314034,274579,327408
150909,Jack,Smithhhh,888814,338887,AO,Loan Out - Non Payroll,0,0,0,0
150910,George,Davies,888812,338888,Some GRADE,Secondment Out - Paid,1,360808,296336,883975
16 changes: 16 additions & 0 deletions payroll/tests/test_assets/valid_records.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
employee_no,first_name,last_name,cost_centre_code,programme_code,grade,assignment_status,fte,basic_pay,ernic,pension
150892,Jack,Wright,888813,338888,SCS,Loan Out - Non Payroll,0,0,0,0
150893,Oliver,Thomas,888814,338889,HEO,Secondment In - Unpaid,0,91692,109058,467950
150894,Lucy,Wilson,888812,338887,Grade 7,Secondment In - Unpaid,0,541545,821337,353586
150895,Lucy,Brown,888813,338888,Grade 6,Active Assignment,1,225309,951986,988960
150896,Emily,Taylor,888814,338889,Faststream,Active Assignment,1,768384,552567,321801
150897,Elizabeth,Brown,888812,338887,EO,Loan In - Payroll,1,823719,706068,254764
150898,Elizabeth,Williams,888813,338888,Contractor,Loan Out - Non Payroll,0,0,0,0
150899,George,Williams,888814,338889,AO,Loan In - Payroll,1,827779,759096,925580
150900,Lucy,Roberts,888812,338887,AA,Loan In - Payroll,1,294191,170873,757744
150901,Charlie,Brown,888813,338888,SEO,Loan In - Payroll,1,149978,671475,802482
150902,George,Jones,888814,338889,SCS,Loan In - Payroll,1,641702,475572,480622
150905,Alice,Davies,888814,338889,Grade 6,Secondment In - Unpaid,0,762957,720411,922423
150907,Lucy,Jones,888813,338888,EO,Loan Out - Non Payroll,0,0,0,0
150908,Oliver,Evans,888814,338889,Contractor,Secondment Out - Paid,1,314034,274579,327408
150909,Jack,Smithhhh,888814,338887,AO,Loan Out - Non Payroll,0,0,0,0

0 comments on commit 3d85012

Please sign in to comment.