Skip to content

Commit

Permalink
Tests (#23)
Browse files Browse the repository at this point in the history
* add in defaults of None to some of our service offerings

start some tests

* more tests

add in some better exceptions to the delivery object builder

* Bump version: 0.0.4 → 0.0.5
  • Loading branch information
Bobspadger committed Apr 6, 2018
1 parent ebb003a commit ea3325b
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
2 changes: 1 addition & 1 deletion royal_mail_rest_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

__author__ = """Alex Hellier"""
__email__ = 'alex.hellier@gmail.com'
__version__ = '0.0.4'
__version__ = '0.0.5'


# from .api import RoyalMailBaseClass
Expand Down
14 changes: 9 additions & 5 deletions royal_mail_rest_api/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ def remove_none_values(iterable):
def _check_ship_type(self, shipment_type):
if shipment_type.lower() != 'delivery':
# TODO: Find out the other options here!
raise Exception('Sorry, only delivery supported at the moment')
raise ValueError('Sorry, only delivery supported at the moment')
else:
self.shipment_type = shipment_type.lower()

Expand All @@ -230,9 +230,13 @@ def add_ship_date(self, date_obj=None):
:param date_obj:
:return:
"""

if date_obj is None:
date_obj = datetime.datetime.today()
self.shipping_date = datetime.datetime.strftime(date_obj, '%Y-%m-%d')
if isinstance(date_obj, datetime.datetime):
self.shipping_date = datetime.datetime.strftime(date_obj, '%Y-%m-%d')
else:
raise(TypeError('Sorry, need a datetime object'))

def _add_service(self):

Expand All @@ -255,15 +259,15 @@ def add_service_format(self, format=None):
self.service_format = self.service_formats[format]


def add_service_type(self, service_type):
def add_service_type(self, service_type=None):
if service_type is None:
raise(Valueerror('no service type selected'))
raise(ValueError('no service type selected'))
if service_type not in self.service_types:
raise(KeyError('Invalid service type'))
self.service_type = self.service_types[service_type]


def add_service_offering(self, service_offering):
def add_service_offering(self, service_offering=None):
if service_offering is None:
raise(ValueError('No service type selected'))
if service_offering not in self.service_offerings:
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.4
current_version = 0.0.5
commit = True
tag = True

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,6 @@
'Documentation': 'http://royal-mail-rest-api.readthedocs.io/en/latest/index.html'},
download_url='https://github.com/Bobspadger/royal_mail_rest_api',
url='https://github.com/bobspadger/royal_mail_rest_api',
version='0.0.4',
version='0.0.5',
zip_safe=False,
)
37 changes: 35 additions & 2 deletions tests/test_royal_mail_rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@

"""Tests for `royal_mail_rest_api` package."""
import pytest
import datetime
from royal_mail_rest_api.tools import RoyalMailBody

def test_add_services():
body = RoyalMailBody('delivery')
with pytest.raises(ValueError):
assert body.add_service_format()
assert body.add_service_type()
assert body.add_service_offering()
with pytest.raises(KeyError):
assert body.add_service_format('does not exist')
assert body.add_service_type('does not exist')
assert body.add_service_offering('does not exist')

def test_pass():
assert 1==1
body.add_service_format('inland_parcel')
body.add_service_type('royal_mail_24')
body.add_service_offering('royal_mail_tracked_24')

assert body.service_format == 'P'
assert body.service_type == '1'
assert body.service_offering =='TPN'


def test_create_object():
with pytest.raises(ValueError):
body = RoyalMailBody('not_supported_value')

body = RoyalMailBody('delivery')
assert body.shipment_type == 'delivery'



def test_add_ship_date():
body = RoyalMailBody('delivery')
with pytest.raises(TypeError):
body.add_ship_date('2018-01-28')
# Test we get date out in format YYYY-mm-dd
body.add_ship_date(datetime.datetime.today())
assert body.shipping_date == datetime.datetime.strftime(datetime.datetime.today(), '%Y-%m-%d')

0 comments on commit ea3325b

Please sign in to comment.