Beispiel #1
0
 def tesx_feed_entries(self):
     c = client.Client(ODATA_SAMPLE_SERVICEROOT)
     # now open a collection and iterate through it
     names = set()
     with c.feeds['Products'].open() as collection:
         n = len(collection)
         self.assertTrue(n > 10,
                         "Sample has more than 10 products (found %i)" % n)
         for product in collection.itervalues():
             names.add(product['ProductName'].value)
         self.assertTrue(n == len(names))
         scottish_long_breads = collection[68]
         self.assertTrue(
             isinstance(scottish_long_breads['ProductID'], edm.Int32Value))
         self.assertTrue(scottish_long_breads['ProductID'].value == 68)
         self.assertTrue(
             isinstance(scottish_long_breads['ProductName'],
                        edm.StringValue))
         self.assertTrue(scottish_long_breads['ProductName'].value ==
                         "Scottish Longbreads")
         self.assertTrue(
             isinstance(scottish_long_breads['SupplierID'], edm.Int32Value))
         self.assertTrue(scottish_long_breads['SupplierID'].value == 8)
         self.assertTrue(
             isinstance(scottish_long_breads['CategoryID'], edm.Int32Value))
         self.assertTrue(scottish_long_breads['CategoryID'].value == 3)
         self.assertTrue(
             isinstance(scottish_long_breads['QuantityPerUnit'],
                        edm.StringValue))
         self.assertTrue(scottish_long_breads['QuantityPerUnit'].value ==
                         "10 boxes x 8 pieces")
         self.assertTrue(
             isinstance(scottish_long_breads['UnitPrice'],
                        edm.DecimalValue))
         self.assertTrue(scottish_long_breads['UnitPrice'].value.as_tuple()
                         == decimal.Decimal("12.5000").as_tuple())
         self.assertTrue(
             isinstance(scottish_long_breads['UnitsInStock'],
                        edm.Int16Value))
         self.assertTrue(scottish_long_breads['UnitsInStock'].value == 6)
         self.assertTrue(
             isinstance(scottish_long_breads['UnitsOnOrder'],
                        edm.Int16Value))
         self.assertTrue(scottish_long_breads['UnitsOnOrder'].value == 10)
         self.assertTrue(
             isinstance(scottish_long_breads['ReorderLevel'],
                        edm.Int16Value))
         self.assertTrue(scottish_long_breads['ReorderLevel'].value == 15)
         self.assertTrue(
             isinstance(scottish_long_breads['Discontinued'],
                        edm.BooleanValue))
         self.assertFalse(scottish_long_breads['Discontinued'].value)
Beispiel #2
0
 def tesx_orderby(self):
     c = client.Client(ODATA_SAMPLE_SERVICEROOT)
     with c.feeds['Products'].open() as collection:
         collection.set_orderby(
             core.CommonExpression.orderby_from_str("ProductName asc"))
         first_value = None
         last_value = None
         for product in collection.itervalues():
             last_value = product['ProductName'].value
             if first_value is None:
                 first_value = last_value
     self.assertTrue(first_value == "Alice Mutton",
                     "Bad first value: %s" % first_value)
     self.assertTrue(last_value == "Zaanse koeken",
                     "Bad last value: %s" % last_value)
Beispiel #3
0
 def tesx_filter(self):
     c = client.Client(ODATA_SAMPLE_SERVICEROOT)
     with c.feeds['Products'].open() as collection:
         collection.set_filter(
             core.CommonExpression.from_str(
                 "substringof('bread',ProductName)"))
         self.assertTrue(len(collection) == 1)
         product = collection.values()[0]
         self.assertTrue(product['ProductName'] == "Scottish Longbreads")
         scottish_long_breads = collection[68]
         self.assertTrue(scottish_long_breads['ProductID'].value == 68)
         try:
             collection[17]
             self.fail("Alice Mutton wasn't filtered")
         except KeyError:
             pass
Beispiel #4
0
 def setUp(self):  # noqa
     global regressionServerApp
     DataServiceRegressionTests.setUp(self)
     self.container = InMemoryEntityContainer(
         self.ds['RegressionModel.RegressionContainer'])
     regressionServerApp = Server("http://localhost:%i/" % HTTP_PORT)
     regressionServerApp.SetModel(self.ds.get_document())
     t = threading.Thread(target=run_regression_server)
     t.setDaemon(True)
     t.start()
     logging.info("OData Client/Server combined tests starting HTTP "
                  "server on localhost, port %i" % HTTP_PORT)
     # yield time to allow the server to start up
     time.sleep(2)
     self.svcDS = self.ds
     self.client = client.Client("http://localhost:%i/" % HTTP_PORT)
     self.ds = self.client.model.DataServices
Beispiel #5
0
 def tesx_navigation(self):
     c = client.Client(ODATA_SAMPLE_SERVICEROOT)
     with c.feeds['Customers'].open() as collection:
         customer = collection['ALFKI']
         self.assertFalse(customer['Orders'].isExpanded)
         with customer['Orders'].open() as orders:
             self.assertTrue(len(orders) == 6, "Number of orders")
             self.assertFalse(
                 isinstance(orders, edm.ExpandedEntityCollection))
         # now test expansion
         collection.set_expand({"Orders": None})
         customer = collection['ALFKI']
         self.assertTrue(customer['Orders'].isExpanded)
         with customer['Orders'].open() as orders:
             self.assertTrue(len(orders) == 6, "Number of orders")
             self.assertTrue(
                 isinstance(orders, core.ExpandedEntityCollection))
Beispiel #6
0
 def tesx_constructor(self):
     c = client.Client(ODATA_SAMPLE_SERVICEROOT)
     self.assertTrue(isinstance(c, app.Client),
                     "OData client not an APP client")
     self.assertTrue(isinstance(c.service, app.Service),
                     "Service document is present")
     self.assertTrue(len(c.service.Workspace) == 1,
                     "Service not returning a single Workspace child")
     self.assertTrue(len(c.service.Workspace[0].Collection) > 0,
                     "Workspace empty")
     self.assertTrue(isinstance(c.serviceRoot, uri.URI),
                     "Service root should be a URI instance")
     self.assertTrue(len(c.feeds) > 0,
                     "At least one feed loaded from service")
     self.assertTrue("Products" in c.feeds,
                     "One feed called Products required")
     self.assertTrue(isinstance(c.feeds["Products"], edm.EntitySet),
                     "Feeds map to entity sets")
Beispiel #7
0
import pyslet.odata2.client as odata

c = odata.Client('http://odata.pyslet.org/weather/')
with c.feeds['DataPoints'].OpenCollection() as collection:
    collection.SetPage(10)
    for d in collection.ietPage():
        print d['TimePoint'].value, d['Temperature'].value