diff --git a/.coveragerc b/.coveragerc
index bbd92e24..51873f2a 100644
--- a/.coveragerc
+++ b/.coveragerc
@@ -1,4 +1,5 @@
[run]
omit =
yoti_python_sdk/tests/**
+ yoti_python_sdk/protobuf/**/*
examples/**
\ No newline at end of file
diff --git a/.travis.yml b/.travis.yml
index be2362de..412f3df2 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -2,11 +2,12 @@ language: python
dist: xenial
-# Only clone the most recent commit.
git:
- depth: 1
+ depth: false
jobs:
+ allow_failures:
+ - python: "3.8-dev"
include:
- &test
stage: Test
@@ -49,7 +50,18 @@ jobs:
if: type = pull_request OR branch = master
after_success:
- coveralls
-
-matrix:
- allow_failures:
- - python: "3.8-dev"
+ - stage: Analyze
+ name: Sonarcloud
+ dist: trusty
+ python: "3.6.1"
+ addons:
+ sonarcloud:
+ organization: "getyoti"
+ install:
+ - pip install -r requirements.txt
+ - pip install -e .[dev]
+ script:
+ - pytest --cov=yoti_python_sdk yoti_python_sdk/tests --cov-report=xml:coverage-reports/coverage-new.xml
+ - sed -i 's+++g' coverage-reports/coverage-new.xml
+ - sonar-scanner
+ if: type = pull_request OR branch = master
diff --git a/requirements.in b/requirements.in
index b4152e92..479122b4 100644
--- a/requirements.in
+++ b/requirements.in
@@ -7,6 +7,7 @@ itsdangerous==0.24
pbr==1.10.0
protobuf==3.7.0
pyopenssl==18.0.0
+PyYAML==5.2 # PyYAML 5.3 does not support Python 3.4
pytz==2018.9
requests>=2.20.0
urllib3>=1.24.2
diff --git a/requirements.txt b/requirements.txt
index 53658733..32904d2c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -20,6 +20,7 @@ protobuf==3.7.0
pycparser==2.18 # via cffi
pyopenssl==18.0.0
pytz==2018.9
+pyyaml==5.2
requests==2.21.0
six==1.10.0 # via cryptography, protobuf, pyopenssl
urllib3==1.24.2
@@ -27,4 +28,4 @@ wheel==0.24.0
wrapt==1.11.2 # via deprecated
# The following packages are considered to be unsafe in a requirements file:
-# setuptools==41.4.0 # via protobuf
+# setuptools==43.0.0 # via protobuf
diff --git a/setup.py b/setup.py
index 5b209ab8..8d5fe232 100644
--- a/setup.py
+++ b/setup.py
@@ -44,6 +44,7 @@
"pylint==1.9.4",
"pylint-exit>=1.1.0",
"python-coveralls==2.9.3",
+ "coverage==4.5.4",
"mock==2.0.0",
"virtualenv==15.2",
],
diff --git a/sonar-project.properties b/sonar-project.properties
index c02c71b4..12c5d404 100644
--- a/sonar-project.properties
+++ b/sonar-project.properties
@@ -1,7 +1,9 @@
-sonar.projectKey = yoti-web-sdk:python
-sonar.projectName = python-sdk
-sonar.projectVersion = 2.10.0
-sonar.exclusions=yoti_python_sdk/tests/**,examples/**
+sonar.host.url = https://sonarcloud.io
+sonar.organization = getyoti
+sonar.projectKey = getyoti:python
+sonar.projectName = Python SDK
+sonar.projectVersion = 2.10.1
+sonar.exclusions = yoti_python_sdk/tests/**,examples/**,yoti_python_sdk/protobuf/**/*
-sonar.python.pylint.reportPath=coverage.out
+sonar.python.pylint.reportPath = coverage.out
sonar.verbose = true
diff --git a/yoti_python_sdk/document_details.py b/yoti_python_sdk/document_details.py
index aa637b64..06de6d22 100644
--- a/yoti_python_sdk/document_details.py
+++ b/yoti_python_sdk/document_details.py
@@ -1,14 +1,9 @@
# -*- coding: utf-8 -*-
-import re
-
from . import date_parser
class DocumentDetails(object):
- VALIDATION_REGEX = re.compile("^[A-Za-z_]* [A-Za-z]{3} [A-Za-z0-9]{1}.*$")
-
def __init__(self, data):
- self.__validate_data(data)
self.__parse_data(data)
@property
@@ -31,14 +26,10 @@ def expiration_date(self):
def issuing_authority(self):
return self.__dict__.get("_DocumentDetails__issuing_authority", None)
- def __validate_data(self, data):
- if self.VALIDATION_REGEX.search(data):
- return
- else:
- raise ValueError("Invalid value for DocumentDetails")
-
def __parse_data(self, data):
- data = data.split()
+ data = data.split(" ")
+ if len(data) < 3 or "" in data:
+ raise ValueError("Invalid value for DocumentDetails")
self.__document_type = data[0]
self.__issuing_country = data[1]
diff --git a/yoti_python_sdk/tests/test_document_details.py b/yoti_python_sdk/tests/test_document_details.py
index 20701dd5..7cbc8a5f 100644
--- a/yoti_python_sdk/tests/test_document_details.py
+++ b/yoti_python_sdk/tests/test_document_details.py
@@ -34,6 +34,40 @@ def test_parse_3_words():
assert document.issuing_authority is None
+def test_parse_redacted_aadhaar():
+ DATA = "AADHAAR IND ****1234"
+
+ document = DocumentDetails(DATA)
+
+ assert document.document_type == "AADHAAR"
+ assert document.issuing_country == "IND"
+ assert document.document_number == "****1234"
+ assert document.expiration_date is None
+ assert document.issuing_authority is None
+
+
+@pytest.mark.parametrize(
+ "details, expected_number",
+ [
+ ("type country **** - authority", "****"),
+ (
+ "type country ~!@#$%^&*()-_=+[]{}|;':,./<>? - authority",
+ "~!@#$%^&*()-_=+[]{}|;':,./<>?",
+ ),
+ ('type country "" - authority', '""'),
+ ("type country \\ - authority", "\\"),
+ ('type country " - authority', '"'),
+ ("type country '' - authority", "''"),
+ ("type country ' - authority", "'"),
+ ],
+)
+def test_parse_special_characters(details, expected_number):
+ document = DocumentDetails(details)
+
+ assert document.document_type == "type"
+ assert document.document_number == expected_number
+
+
def test_parse_4_words():
DATA = "DRIVING_LICENCE GBR 1234abc 2016-05-01"
@@ -88,3 +122,11 @@ def test_invalid_date():
with pytest.raises(ValueError) as exc:
DocumentDetails(DATA)
assert str(exc.value) == "Invalid value for DocumentDetails"
+
+
+def test_should_fail_with_double_space():
+ DATA = "AADHAAR IND ****1234"
+
+ with pytest.raises(ValueError) as exc:
+ DocumentDetails(DATA)
+ assert str(exc.value) == "Invalid value for DocumentDetails"
diff --git a/yoti_python_sdk/version.py b/yoti_python_sdk/version.py
index f86f175b..6f7b7c7d 100644
--- a/yoti_python_sdk/version.py
+++ b/yoti_python_sdk/version.py
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
-__version__ = "2.10.0"
+__version__ = "2.10.1"