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

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/ndgCommon/trunk/ndg/common/unittests/testutils.py@4991
Revision 4991, 1.5 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"""
2Utilities to use in the various test cases
3
4NERC Data Grid Project
5"""
6__author__ = "C Byrom - Tessella"
7__date__ = "16/12/08"
8__copyright__ = "(C) 2008 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
15from ndg.common.src.models.vocabtermdata import VocabTermData as VTD
16from ndg.common.src.clients.xmldb.eXist.atomclient import AtomClient as ac
17import ndg.common.src.clients.xmldb.eXist.dbconstants as dc
18from ndg.common.src.models.Atom import Atom
19import ndg.common.unittests.testconstants as tc
20import os
21
22class testUtils(object):
23    def __init__(self, confFile):
24        self.host = tc.EXIST_DB
25        self.ac = ac(dbHostName = self.host, configFileName = confFile, setUpDB = True)
26   
27    def createAtom(self, content):
28        atom = Atom(VTD.GRANULE_TERM)
29        atom.fromString(content)
30        return atom
31   
32    def createAtomInEXist(self, content):
33        atom = self.createAtom(content)
34        return self.ac.createAtom(atom)
35   
36    def deleteDoc(self, path):
37        self.ac.deleteDoc(path)
38       
39    def createOldMolesDoc(self):
40        '''
41        Create an old moles1.0 doc
42        '''
43        # firstly, load a moles do to eXist
44        f = open(tc.MOLES_FILE_NAME, 'r')
45        xml = f.read()
46        f.close()
47        fileName = f.name.split(os.sep)[-1]
48        path = dc.MOLES_COLLECTION_PATH + tc.GRANULITE_PROVIDER_ID
49        self.ac.createDoc(xml, path, fileName)
50        return path + '/' + fileName
Note: See TracBrowser for help on using the repository browser.