1 | """ |
---|
2 | Utilities to use in the various test cases |
---|
3 | |
---|
4 | NERC 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 |
---|
11 | License, version 1.0 or later.""" |
---|
12 | __contact__ = "b.n.lawrence@rl.ac.uk" |
---|
13 | __revision__ = '$Id: $' |
---|
14 | |
---|
15 | from ndg.common.src.models.vocabtermdata import VocabTermData as VTD |
---|
16 | from ndg.common.src.clients.xmldb.eXist.atomclient import AtomClient as ac |
---|
17 | import ndg.common.src.clients.xmldb.eXist.dbconstants as dc |
---|
18 | from ndg.common.src.models.Atom import Atom |
---|
19 | import ndg.common.unittests.testconstants as tc |
---|
20 | import os |
---|
21 | |
---|
22 | class 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 |
---|