Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions 18 README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
13 changes: 12 additions & 1 deletion 13 odata/tests/test_nw_manual_model.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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'))
Expand Down
24 changes: 18 additions & 6 deletions 24 odata/tests/test_nw_reflect_model.py
Original file line number Diff line number Diff line change
@@ -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'))
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.