Skip to content

Commit

Permalink
SDK-1834 third party sandbox
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalMilewiczYoti committed Oct 4, 2021
1 parent 4ac3a61 commit 5330541
Show file tree
Hide file tree
Showing 6 changed files with 123 additions and 13 deletions.
18 changes: 9 additions & 9 deletions .github/workflows/sonar.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ jobs:
github.event_name == 'push' ||
github.event_name == 'pull_request_target' && github.event.pull_request.head.repo.full_name != github.repository
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0

- uses: sonarsource/sonarcloud-github-action@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
# steps:
# - uses: actions/checkout@v2
# with:
# fetch-depth: 0
#
# - uses: sonarsource/sonarcloud-github-action@master
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

3 changes: 3 additions & 0 deletions yoti_python_sandbox/doc_scan/check/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@
from .sandbox_id_document_comparison_check import ( # noqa: F401
SandboxIdDocumentComparisonCheckBuilder,
)
from .sandbox_third_party_check import ( # noqa: F401
SandboxThirdPartyCheckBuilder,
)
42 changes: 42 additions & 0 deletions yoti_python_sandbox/doc_scan/check/sandbox_third_party_check.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
from yoti_python_sandbox.doc_scan.check.sandbox_check import SandboxCheckBuilder
from yoti_python_sandbox.doc_scan.check.sandbox_check_report import SandboxCheckReport
from yoti_python_sandbox.doc_scan.check.sandbox_check_result import SandboxCheckResult
from .sandbox_check import SandboxCheck


class SandboxThirdPartyCheck(SandboxCheck):
def __init__(self, result, manual_check):
SandboxCheck.__init__(self, result)
self.__manual_check = manual_check

@property
def type(self):
return "THIRD_PARTY_IDENTITY"

@property
def manual_check(self):
return self.__manual_check

def to_json(self):
parent = SandboxCheck.to_json(self)
parent["type"] = self.type
parent["manual_check"] = self.manual_check

return parent


class SandboxThirdPartyCheckBuilder(SandboxCheckBuilder):
def __init__(self):
SandboxCheckBuilder.__init__(self)
self.__manual_check = None

def with_manual_check(self, manual_check):
self.__manual_check = manual_check

return self

def build(self):
report = SandboxCheckReport(self.recommendation, self.breakdown)
result = SandboxCheckResult(report)

return SandboxThirdPartyCheck(result, self.__manual_check)
23 changes: 23 additions & 0 deletions yoti_python_sandbox/doc_scan/check_reports.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def __init__(
async_report_delay=None,
id_document_comparison_checks=None,
supplementary_document_text_data_checks=None,
third_party_check=None,
):
if document_authenticity_check is None:
document_authenticity_check = []
Expand All @@ -41,6 +42,7 @@ def __init__(
if supplementary_document_text_data_checks is None:
supplementary_document_text_data_checks = []

self.__third_party_check = third_party_check
self.__document_authenticity_check = document_authenticity_check
self.__document_face_match_check = document_face_match_check
self.__document_text_data_check = document_text_data_check
Expand Down Expand Up @@ -79,8 +81,13 @@ def id_document_comparison_checks(self):
def supplementary_document_text_data_checks(self):
return self.__supplementary_document_text_data_checks

@property
def third_party_check(self):
return self.__third_party_check

def to_json(self):
return {
"THIRD_PARTY_IDENTITY": self.__third_party_check,
"ID_DOCUMENT_AUTHENTICITY": self.__document_authenticity_check,
"ID_DOCUMENT_TEXT_DATA_CHECK": self.__document_text_data_check,
"ID_DOCUMENT_FACE_MATCH": self.__document_face_match_check,
Expand All @@ -97,6 +104,7 @@ def __init__(self):
self.__document_face_match_checks = []
self.__document_text_data_checks = []
self.__liveness_checks = []
self.__third_party_check = None
self.__async_report_delay = None
self.__id_document_comparison_check = []
self.__supplementary_document_text_data_checks = []
Expand Down Expand Up @@ -195,6 +203,20 @@ def with_supplementary_document_text_data_check(
)
return self

def with_third_party_check(self, third_party_check):
"""
Add a third party check
:param third_party_check: the third party check
:type third_party_check: SandboxThirdPartyCheck
:return: the builder
:rtype: SandboxCheckReportsBuilder
"""

self.__third_party_check = third_party_check

return self

def build(self):
return SandboxCheckReports(
self.__document_authenticity_checks,
Expand All @@ -204,4 +226,5 @@ def build(self):
self.__async_report_delay,
self.__id_document_comparison_check,
self.__supplementary_document_text_data_checks,
self.__third_party_check,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from mock import Mock

from yoti_python_sandbox.doc_scan.check import SandboxThirdPartyCheckBuilder
from yoti_python_sandbox.doc_scan.check.report.recommendation import (
SandboxRecommendation,
)
from yoti_python_sandbox.doc_scan.check.report.breakdown import SandboxBreakdown


def test_third_party_check_should_set_correct_manual_check_and_type():
check = SandboxThirdPartyCheckBuilder().with_manual_check("NEVER").build()

assert check.manual_check == "NEVER"
assert check.type == "THIRD_PARTY_IDENTITY"


def test_third_party_check_build_result_object():
recommendation_mock = Mock(spec=SandboxRecommendation)
breakdown_mock = Mock(spec=SandboxBreakdown)

check = (
SandboxThirdPartyCheckBuilder()
.with_recommendation(recommendation_mock)
.with_breakdown(breakdown_mock)
.build()
)

assert check.result.report.recommendation is not None
assert check.result.report.recommendation == recommendation_mock
assert len(check.result.report.breakdown) == 1
assert check.result.report.breakdown[0] == breakdown_mock
19 changes: 15 additions & 4 deletions yoti_python_sandbox/tests/doc_scan/test_check_reports.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from mock import Mock

from yoti_python_sandbox.doc_scan import SandboxCheckReportsBuilder
from yoti_python_sandbox.doc_scan.check_reports import SandboxCheckReports
from yoti_python_sandbox.doc_scan.check.sandbox_document_authenticity_check import (
SandboxDocumentAuthenticityCheck,
)
Expand All @@ -11,15 +10,19 @@
from yoti_python_sandbox.doc_scan.check.sandbox_document_text_data_check import (
SandboxDocumentTextDataCheck,
)
from yoti_python_sandbox.doc_scan.check.sandbox_liveness_check import (
SandboxLivenessCheck,
)
from yoti_python_sandbox.doc_scan.check.sandbox_id_document_comparison_check import (
SandboxIdDocumentComparisonCheck,
)
from yoti_python_sandbox.doc_scan.check.sandbox_liveness_check import (
SandboxLivenessCheck,
)
from yoti_python_sandbox.doc_scan.check.sandbox_supplementary_document_text_data_check import (
SandboxSupplementaryDocumentTextDataCheck,
)
from yoti_python_sandbox.doc_scan.check.sandbox_third_party_check import (
SandboxThirdPartyCheck,
)
from yoti_python_sandbox.doc_scan.check_reports import SandboxCheckReports


def test_should_build_with_correct_properties():
Expand All @@ -31,6 +34,7 @@ def test_should_build_with_correct_properties():
supplementary_text_data_check_mock = Mock(
spec=SandboxSupplementaryDocumentTextDataCheck
)
third_party_check_mock = Mock(spec=SandboxThirdPartyCheck)
async_report_delay = 12

check_reports = (
Expand All @@ -41,6 +45,7 @@ def test_should_build_with_correct_properties():
.with_liveness_check(liveness_check_mock)
.with_id_document_comparison_check(comparison_check_mock)
.with_supplementary_document_text_data_check(supplementary_text_data_check_mock)
.with_third_party_check(third_party_check_mock)
.with_async_report_delay(async_report_delay)
.build()
)
Expand All @@ -66,6 +71,8 @@ def test_should_build_with_correct_properties():
== supplementary_text_data_check_mock
)

assert check_reports.third_party_check is not None

assert check_reports.async_report_delay == 12


Expand All @@ -78,6 +85,7 @@ def test_json_should_have_correct_properties():
supplementary_text_data_check_mock = Mock(
spec=SandboxSupplementaryDocumentTextDataCheck
)
third_party_check_mock = Mock(spec=SandboxThirdPartyCheck)
async_report_delay = 12

check_reports = (
Expand All @@ -88,6 +96,7 @@ def test_json_should_have_correct_properties():
.with_liveness_check(liveness_check_mock)
.with_id_document_comparison_check(comparison_check_mock)
.with_supplementary_document_text_data_check(supplementary_text_data_check_mock)
.with_third_party_check(third_party_check_mock)
.with_async_report_delay(async_report_delay)
.build()
)
Expand All @@ -103,6 +112,7 @@ def test_json_should_have_correct_properties():
== supplementary_text_data_check_mock
)
assert json.get("LIVENESS")[0] == liveness_check_mock
assert json.get("THIRD_PARTY_IDENTITY") == third_party_check_mock
assert json.get("async_report_delay") == async_report_delay


Expand All @@ -118,6 +128,7 @@ def test_json_defaults_to_empty_array_for_checks():
assert json.get("ID_DOCUMENT_COMPARISON") == []
assert json.get("SUPPLEMENTARY_DOCUMENT_TEXT_DATA_CHECK") == []
assert json.get("LIVENESS") == []
assert json.get("THIRD_PARTY_IDENTITY") is None


def test_async_report_delay_not_included_when_not_specified():
Expand Down

0 comments on commit 5330541

Please sign in to comment.