diff --git a/README.md b/README.md index e6365b2..fec1221 100644 --- a/README.md +++ b/README.md @@ -55,3 +55,21 @@ for order in query: order.Employee = empl Service.save(order) ``` + +## Running tests + +To run the tests, you can use pytest or unittest: + +- python -m pytest +- python -m unittest discover + +To include tests that call the Northwind service, set the envionment variable: + +``` +export ODATA_DO_REMOTE_TESTS=1 +``` + +The Northwind tests are automatically skipped if it cannot connect to the service. + +Test dependency: +- responses diff --git a/odata/tests/test_nw_manual_model.py b/odata/tests/test_nw_manual_model.py index 0aa982b..f615f96 100644 --- a/odata/tests/test_nw_manual_model.py +++ b/odata/tests/test_nw_manual_model.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- import unittest +import os from odata.service import ODataService +from odata.exceptions import ODataConnectionError from odata.entity import declarative_base from odata.property import StringProperty, IntegerProperty @@ -41,9 +43,18 @@ class Product(Base): quantity_per_unit = StringProperty('QuantityPerUnit') -@unittest.skip('unavailable') +@unittest.skipUnless(os.environ.get('ODATA_DO_REMOTE_TESTS', False), + 'Avoid Northwind service unless requested') class NorthwindManualModelReadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + try: + # Test query to make sure we have an OData connection + q = service.query(Customer).first() + except ODataConnectionError: + raise unittest.SkipTest('Unable to connect to Northwind service') + def test_query_one(self): q = service.query(Customer) q = q.filter(Customer.contact_title.startswith('Sales')) diff --git a/odata/tests/test_nw_reflect_model.py b/odata/tests/test_nw_reflect_model.py index b17b942..5c6164e 100644 --- a/odata/tests/test_nw_reflect_model.py +++ b/odata/tests/test_nw_reflect_model.py @@ -1,19 +1,31 @@ # -*- coding: utf-8 -*- import unittest +import os from odata.service import ODataService +from odata.exceptions import ODataConnectionError -url = 'http://services.odata.org/V4/Northwind/Northwind.svc/' -Service = ODataService(url, reflect_entities=True) -Customer = Service.entities.get('Customers') -Product = Service.entities.get('Products') +Service = None +Customer = None +Product = None - -@unittest.skip('unavailable') +@unittest.skipUnless(os.environ.get('ODATA_DO_REMOTE_TESTS', False), + 'Avoid Northwind service unless requested') class NorthwindReflectModelReadTest(unittest.TestCase): + @classmethod + def setUpClass(cls): + global Service, Customer, Product + url = 'http://services.odata.org/V4/Northwind/Northwind.svc/' + try: + Service = ODataService(url, reflect_entities=True) + except ODataConnectionError: + raise unittest.SkipTest('Unable to connect to Northwind service') + Customer = Service.entities.get('Customers') + Product = Service.entities.get('Products') + def test_query_one(self): q = Service.query(Customer) q = q.filter(Customer.ContactTitle.startswith('Sales'))