Skip to content

Commit

Permalink
Merge pull request #109 from getyoti/release-2.9.2
Browse files Browse the repository at this point in the history
Release 2.9.2
  • Loading branch information
MrBurtyyy authored Oct 2, 2019
2 parents 8d97a0f + 9031a8c commit 8a3147e
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 8 deletions.
2 changes: 1 addition & 1 deletion sonar-project.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sonar.projectKey = yoti-web-sdk:python
sonar.projectName = python-sdk
sonar.projectVersion = 2.9.1
sonar.projectVersion = 2.9.2
sonar.exclusions=yoti_python_sdk/tests/**,examples/**

sonar.python.pylint.reportPath=coverage.out
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,41 @@ def __init__(self):
self.__extension["content"] = {}
self.__device_location = {
"latitude": None,
"longtitude": None,
"longitude": None,
"radius": None,
"max_uncertainty_radius": None,
}
self.__extension["content"]["expected_device_location"] = self.__device_location

def with_latitude(self, latitude):
if not isinstance(latitude, float) and not isinstance(latitude, int):
raise ValueError("Latitude must be float or int")
if not -90 <= latitude <= 90:
raise ValueError("Latitude must be between -90 and 90 degrees")
self.__device_location["latitude"] = latitude
return self

def with_longtitude(self, longtitude):
self.__device_location["longtitude"] = longtitude
def with_longitude(self, longitude):
if not isinstance(longitude, float) and not isinstance(longitude, int):
raise ValueError("Lontitude must be float or int")
if not -180 <= longitude <= 180:
raise ValueError("Longitude must be between -180 and 180 degrees")
self.__device_location["longitude"] = longitude
return self

def with_radius(self, radius):
if not isinstance(radius, float) and not isinstance(radius, int):
raise ValueError("Radius must be float or int")
if not 0 <= radius:
raise ValueError("Radius must be >= 0")
self.__device_location["radius"] = radius
return self

def with_uncertainty(self, uncertainty):
if not isinstance(uncertainty, float) and not isinstance(uncertainty, int):
raise ValueError("Uncertainty must be float or int")
if not 0 <= uncertainty:
raise ValueError("Uncertainty must be >= 0")
self.__device_location["max_uncertainty_radius"] = uncertainty
return self

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,71 @@
from yoti_python_sdk.dynamic_sharing_service.extension.location_constraint_extension_builder import (
LocationConstraintExtensionBuilder,
)
import pytest


@pytest.mark.parametrize("longitude", [270.00, -181, "27.00"])
def test_longitude_validation_should_reject_invalid(longitude):
extension = LocationConstraintExtensionBuilder()
with pytest.raises(ValueError):
extension.with_longitude(longitude)


@pytest.mark.parametrize("longitude", [180.0, -90])
def test_longitude_vaidation_should_accept_valid(longitude):
extension = LocationConstraintExtensionBuilder()
extension.with_longitude(longitude)


@pytest.mark.parametrize("latitude", [270.00, -181, "27.00", 91, -180])
def test_latitude_validation_should_reject_invalid(latitude):
extension = LocationConstraintExtensionBuilder()
with pytest.raises(ValueError):
extension.with_latitude(latitude)


@pytest.mark.parametrize("latitude", [18.0, -90])
def test_latitude_validation_should_accept_valid(latitude):
extension = LocationConstraintExtensionBuilder()
extension.with_latitude(latitude)


@pytest.mark.parametrize("uncertainty", [-1, -0.01, "3"])
def test_uncertainty_validation_should_reject_invalid(uncertainty):
extension = LocationConstraintExtensionBuilder()
with pytest.raises(ValueError):
extension.with_uncertainty(uncertainty)


@pytest.mark.parametrize("uncertainty", [0, 1, 1e3])
def test_uncertainty_validation_should_accept_valid(uncertainty):
extension = LocationConstraintExtensionBuilder()
extension.with_uncertainty(uncertainty)


@pytest.mark.parametrize("radius", [-1, -0.01, "3"])
def test_radius_validation_should_reject_invalid(radius):
extension = LocationConstraintExtensionBuilder()
with pytest.raises(ValueError):
extension.with_radius(radius)


@pytest.mark.parametrize("radius", [0, 1, 1e3])
def test_radius_validation_should_accept_valid(radius):
extension = LocationConstraintExtensionBuilder()
extension.with_radius(radius)


def test_builds_with_given_values():
LATITUDE = 50
LONGTITUDE = 99
LONGITUDE = 99
RADIUS = 60
UNCERTAINTY = 30

extension = (
LocationConstraintExtensionBuilder()
.with_latitude(LATITUDE)
.with_longtitude(LONGTITUDE)
.with_longitude(LONGITUDE)
.with_radius(RADIUS)
.with_uncertainty(UNCERTAINTY)
.build()
Expand All @@ -24,6 +77,6 @@ def test_builds_with_given_values():
device_location = extension["content"]["expected_device_location"]

assert device_location["latitude"] == LATITUDE
assert device_location["longtitude"] == LONGTITUDE
assert device_location["longitude"] == LONGITUDE
assert device_location["radius"] == RADIUS
assert device_location["max_uncertainty_radius"] == UNCERTAINTY
2 changes: 1 addition & 1 deletion yoti_python_sdk/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# -*- coding: utf-8 -*-
__version__ = "2.9.1"
__version__ = "2.9.2"

0 comments on commit 8a3147e

Please sign in to comment.