source: ndgCommon/trunk/ndg/common/unittests/models/test_ndgObject.py @ 4991

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/models/test_ndgObject.py@4991
Revision 4991, 3.9 KB checked in by cbyrom, 11 years ago (diff)

Move generic 'httpify' method to utilities + adjust utilities method
to retrive default proxy to cope with standard formatting + set this
up on each call to urlopen - since different urls may use different
proxies + tidyup and extend test suite.

Line 
1"""
2Test cases for the ndgObject module
3
4NERC Data Grid Project
5"""
6__author__ = "B Lawrence"
7__date__ = "06/12/07"
8__copyright__ = "(C) 2007 STFC & NERC"
9__license__ = \
10"""This software may be distributed under the terms of the Q Public
11License, version 1.0 or later."""
12__contact__ = "b.n.lawrence@rl.ac.uk"
13__revision__ = '$Id: $'
14
15import unittest, os, logging
16from ndg.common.src.models.ndgObject import ndgObject as no
17from ndg.common.src.models.myconfig import myConfig
18import ndg.common.unittests.testconstants as tc
19from ndg.common.unittests.testutils import testUtils as tu
20
21class TestCase(unittest.TestCase):
22    """ Tests as required """
23   
24    def setUp(self):
25        self.config = myConfig(tc.NDG_CONFIG_FILE)
26        self.createdAtoms = []    # array to store paths to atoms created - in order to then delete them
27        self.utils = tu(tc.EXIST_DBCONFIG_FILE)
28       
29    def __assertions(self,uri):
30        self.assertEqual(tc.VALID_PROVIDER_ID,uri.repository)
31        self.assertEqual(no.NDGB0_DOC_TYPE,uri.schema)
32        self.assertEqual(tc.VALID_MOLES_DOC_ID,uri.localID)
33   
34    def testURI1(self):
35        ''' Testing the underscore ID type '''
36        uri= tc.VALID_PROVIDER_ID + '__' + no.NDGB0_DOC_TYPE + '__' + \
37            tc.VALID_MOLES_DOC_ID
38        n=no(uri)
39        self.__assertions(n)
40       
41    def testURI2(self):
42        ''' Testing the colon form of ID '''
43        uri=tc.VALID_PROVIDER_ID + ':' + no.NDGB0_DOC_TYPE + ':' + \
44            tc.VALID_MOLES_DOC_ID
45        n=no(uri)
46        self.__assertions(n)
47   
48    def notestURI3(self):
49        ''' Testing the default MOLES form of id '''
50        uri=tc.VALID_PROVIDER_ID + '/' + tc.VALID_MOLES_DOC_ID
51        n=no(uri)
52        self.__assertions(n)
53   
54    def testMakeURL(self):
55        ''' Tests making a url via a configuration file '''
56        uri=tc.VALID_PROVIDER_ID + '__' + no.NDGB0_DOC_TYPE + '__' + \
57            tc.VALID_MOLES_DOC_ID
58        n=no(uri)
59        n.schema='DIF'
60        n.setConfig(self.config)
61        self.assertTrue(n.gettable)
62        self.assertEqual(n.discoveryURL,'http://ndgbeta.badc.rl.ac.uk/view/badc.nerc.ac.uk__DIF__dataent_hadisst')
63         
64    def testStubB(self):
65        ''' Test the url components of a stub-b '''
66        uri=tc.VALID_PROVIDER_ID + '__' + no.NDGB1_DOC_TYPE + '__' + \
67            tc.VALID_MOLES_ID
68        n=no(tc.VALID_NDG_URL,self.config)
69        self.assertEqual(tc.VALID_DISCOVERY_URL + '?outputSchema=DIF', 
70                         n.discoveryURL)
71        self.assertEqual(tc.VALID_DISCOVERY_URL, n.URL)
72        self.assertEqual(tc.VALID_RETRIEVE_URL + '?format=raw', n.xmlURL)
73        self.assertEqual(tc.VALID_DISCOVERY_URL + '?format=xml', n.printableURL)
74         
75    def testAtom(self):
76        ''' Test the url components of an atom '''
77        uri= tc.VALID_NDG_URL
78        n=no(uri,self.config)
79       
80        self.assertEqual(tc.VALID_DISCOVERY_URL + '?outputSchema=DIF', n.discoveryURL)
81        self.assertEqual(tc.VALID_DISCOVERY_URL, n.URL)
82        self.assertEqual(tc.VALID_RETRIEVE_URL + '?format=raw', n.xmlURL)
83        self.assertEqual(tc.VALID_DISCOVERY_URL + '?format=xml', n.printableURL)
84         
85    def testPMLuri(self):
86        '''Make sure the pml uris work in ndg object '''
87        uri='www.npm.ac.uk__NDG-B1__dataent.692'
88        n=no(uri,self.config)
89        self.assertEqual('http://wwwdev.neodaas.ac.uk/projects/ndg/view/www.npm.ac.uk__NDG-B1__dataent.692', n.URL)
90
91    def testHorribleURI(self):
92        ''' tests use of '__' in localID '''
93        uri='repository__schema__something__else'
94        n=no(uri)
95        self.assertEqual(('repository','schema','something__else'),
96            (n.repository,n.schema,n.localID))
97       
98       
99    def tearDown(self):
100        for path  in self.createdAtoms:
101            # delete the test file, in case it has been used in a test
102            self.utils.deleteDoc(path)
103
104if __name__=="__main__":
105    unittest.main()
Note: See TracBrowser for help on using the repository browser.