Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Sage Validation
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
geant-swd
Sage Validation
Commits
adb279d1
Commit
adb279d1
authored
3 weeks ago
by
Neda Moeini
Browse files
Options
Downloads
Patches
Plain Diff
Make ruff happy
parent
36a671c6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!2
Feature/unit test for validations
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
test/conftest.py
+19
-10
19 additions, 10 deletions
test/conftest.py
test/settings.py
+4
-2
4 additions, 2 deletions
test/settings.py
test/test_file_validator/test_forms.py
+6
-5
6 additions, 5 deletions
test/test_file_validator/test_forms.py
with
29 additions
and
17 deletions
test/conftest.py
+
19
−
10
View file @
adb279d1
import
pytest
"""
Fixtures for the sage_validation tests.
"""
from
unittest.mock
import
MagicMock
import
pytest
from
django.core.files.uploadedfile
import
SimpleUploadedFile
from
sage_validation.file_validator.models
import
MeoValidSuppliers
,
MeoCostCentres
,
XxData
from
faker
import
Faker
from
sage_validation.file_validator.models
import
MeoCostCentres
,
MeoValidSuppliers
,
XxData
@pytest.fixture
def
sample_input_file
():
"""
Create
s
a sample valid CSV file for testing.
"""
csv_headers
=
"
,
"
.
join
(
[
"""
Create a sample valid CSV file for testing.
"""
csv_headers
_list
=
[
"
AccountNumber
"
,
"
CBAccountNumber
"
,
"
DaysDiscountValid
"
,
...
...
@@ -46,9 +49,10 @@ def sample_input_file():
"
TaxAnalysisDiscountValue/1
"
,
"
TaxAnalysisDiscountPercentage/1
"
,
"
TaxAnalysisTaxOnGoodsValue/1
"
,
])
]
csv_headers
=
"
,
"
.
join
(
csv_headers_list
)
csv_content
=
"
,
"
.
join
(
[
csv_content
_list
=
[
"
12345
"
,
# AccountNumber
"
54321
"
,
# CBAccountNumber
"
30
"
,
# DaysDiscountValid
...
...
@@ -86,9 +90,10 @@ def sample_input_file():
"
30
"
,
# TaxAnalysisDiscountValue/1
"
3.5
"
,
# TaxAnalysisDiscountPercentage/1
"
180
"
,
# TaxAnalysisTaxOnGoodsValue/1
])
]
csv_content
=
"
,
"
.
join
(
csv_content_list
)
return
SimpleUploadedFile
(
"
test.csv
"
,
f
"
{
csv_headers
}
\n
{
csv_content
}
"
.
encode
(
"
utf-8
"
),
content_type
=
"
text/csv
"
)
return
SimpleUploadedFile
(
"
test.csv
"
,
f
"
{
csv_headers
}
\n
{
csv_content
}
"
.
encode
(),
content_type
=
"
text/csv
"
)
@pytest.fixture
def
mock_meo_database
(
mocker
):
...
...
@@ -98,7 +103,9 @@ def mock_meo_database(mocker):
# Mock MeoValidSuppliers
supplier_mock
=
MagicMock
()
supplier_mock
.
all
.
return_value
=
[
MeoValidSuppliers
(
supplier_account_number
=
str
(
fake
.
random_int
(
min
=
10000
,
max
=
99999
)),
supplier_account_name
=
fake
.
company
()),
MeoValidSuppliers
(
supplier_account_number
=
str
(
fake
.
random_int
(
min
=
10000
,
max
=
99999
)),
supplier_account_name
=
fake
.
company
()
),
MeoValidSuppliers
(
supplier_account_number
=
"
12345
"
,
supplier_account_name
=
"
Sample Narrative
"
)
]
mocker
.
patch
(
"
sage_validation.file_validator.models.MeoValidSuppliers.objects.using
"
,
return_value
=
supplier_mock
)
...
...
@@ -123,7 +130,9 @@ def mock_meo_database(mocker):
# Mock MeoValidSageAccounts
sage_account_mock
=
MagicMock
()
sage_account_mock
.
filter
.
return_value
.
exists
.
return_value
=
True
mocker
.
patch
(
"
sage_validation.file_validator.models.MeoValidSageAccounts.objects.using
"
,
return_value
=
sage_account_mock
)
mocker
.
patch
(
"
sage_validation.file_validator.models.MeoValidSageAccounts.objects.using
"
,
return_value
=
sage_account_mock
)
# Mock MeoNominal
nominal_mock
=
MagicMock
()
...
...
This diff is collapsed.
Click to expand it.
test/settings.py
+
4
−
2
View file @
adb279d1
from
sage_validation.settings
import
*
# noqa: F403, F401
"""
Settings for running tests.
"""
from
sage_validation.settings
import
*
# noqa: F403
DATABASES
=
{
"
default
"
:
DATABASES
[
"
default
"
],
"
default
"
:
DATABASES
[
"
default
"
],
# noqa: F405
}
This diff is collapsed.
Click to expand it.
test/test_file_validator/test_forms.py
+
6
−
5
View file @
adb279d1
"""
Tests for the file_validator forms.
"""
import
csv
import
io
...
...
@@ -30,7 +31,6 @@ def test_missing_required_columns():
def
test_source_and_trader_type_validation
(
sample_input_file
,
mock_meo_database
):
"""
Test validation for Source and SYSTraderTranType columns.
"""
csv_content
=
sample_input_file
.
read
().
decode
(
"
utf-8
"
).
splitlines
()
reader
=
csv
.
DictReader
(
csv_content
)
rows
=
list
(
reader
)
...
...
@@ -54,7 +54,6 @@ def test_source_and_trader_type_validation(sample_input_file, mock_meo_database)
def
test_validate_nominal_analysis_account
(
sample_input_file
,
mock_meo_database
):
"""
Test validation for nominal analysis account.
"""
csv_content
=
sample_input_file
.
read
().
decode
(
"
utf-8
"
).
splitlines
()
reader
=
csv
.
DictReader
(
csv_content
)
rows
=
list
(
reader
)
...
...
@@ -69,8 +68,9 @@ def test_validate_nominal_analysis_account(sample_input_file, mock_meo_database)
form
=
CSVUploadForm
(
files
=
{
"
file
"
:
modified_file
})
assert
not
form
.
is_valid
()
assert
(
f
"
Row 1:
'
AccountNumber
'
must match
'
Sample Narrative
'
in
'
NominalAnalysisNominalAnalysisNarrative/1
'
,
"
f
"
but found
'
Invalid Name
'
.
"
)
==
form
.
errors
[
"
file
"
][
0
]
assert
form
.
errors
[
"
file
"
][
0
]
==
(
"
Row 1:
'
AccountNumber
'
must match
'
Sample Narrative
'
in
'
NominalAnalysisNominalAnalysisNarrative/1
'"
"
, but found
'
Invalid Name
'
.
"
)
def
test_validate_nc_cc_dep_combination_against_meo_sage_account
(
sample_input_file
,
mock_meo_database
):
...
...
@@ -90,5 +90,6 @@ def test_validate_nc_cc_dep_combination_against_meo_sage_account(sample_input_fi
form
=
CSVUploadForm
(
files
=
{
"
file
"
:
modified_file
})
assert
not
form
.
is_valid
()
assert
"
Row 1:
'
NominalAnalysisNominalCostCentre/1
'
(Invalid_CC) is not a valid cost centre.
"
in
str
(
form
.
errors
[
"
file
"
][
0
])
assert
(
"
Row 1:
'
NominalAnalysisNominalCostCentre/1
'
(Invalid_CC) is not a valid cost centre.
"
in
str
(
form
.
errors
[
"
file
"
][
0
]))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment