test_odata.py 1.91 KB
Newer Older
1
# encoding: utf-8
Morten Knutsen's avatar
Morten Knutsen committed
2
from scvmm_client import odata
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
import uuid


class TestOData(object):
    def setup(self):
        pass

    def teardown(self):
        pass

    def test_ns_split(self):
        """ Test splitting tag and namespace, normal flow """
        tag = "{http://www.w3.org/2007/app}mytag"
        namespace, tag = odata.namespace_split(tag)
        assert namespace == "http://www.w3.org/2007/app"
        assert tag == "mytag"

    def test_ns_split_no_namespace(self):
        """ Test splitting tag and namespace when no namespace is provided """
        tag = "mytag"
        namespace, res_tag = odata.namespace_split(tag)
        assert namespace == ""
        assert res_tag == tag

    def test_ns(self):
        """ test constructing namespaced tag names """
        assert odata.ns("b", "mytag") == "{http://www.w3.org/2007/app}mytag"
        assert odata.ns("atom", "mytag2") == "{http://www.w3.org/2005/Atom}mytag2"
        assert odata.ns("ds", "sometag") == "{http://schemas.microsoft.com/ado/2007/08/dataservices}sometag"
        assert odata.ns("m", "mytag") == "{http://schemas.microsoft.com/ado/2007/08/dataservices/metadata}mytag"

    def test_type_encode_argvalue(self):
        uuid_string = '00010203-0405-0607-0809-0a0b0c0d0e0f'
        guid = uuid.UUID(uuid_string)
        assert odata.type_encode_argvalue(guid) == "guid'" + uuid_string + "'"
        assert odata.type_encode_argvalue("mystring") == "'mystring'"
#        assert odata.type_encode_argvalue(u"blåbærsyltetøy") = u"'blåbærsyltetøy'"
        assert odata.type_encode_argvalue(123) == 123


class TestODataClient(object):
    def setup(self):
        self.client = odata.Client("http://someurl", "myusername", "mytopsecretpassword")

    def teardown(self):
        pass

    def test_format_url(self):
        """ Test the format url call """
52
        assert self.client._format_url("foo") == "http://someurl/Microsoft.Management.Odata.svc/foo"