Skip to content

Commit c085fb3

Browse files
committed
Revert "Merge pull request #5 from rliebz/test"
This reverts commit d4205b2, reversing changes made to 8e60018.
1 parent d4205b2 commit c085fb3

19 files changed

Lines changed: 177 additions & 313 deletions

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
11
.vagrant
22
.DS_Store
33
*pyc
4-
.idea/
5-
.cache/
6-
*~

__init__.py

Whitespace-only changes.

dvn_client/__init__.py

Lines changed: 0 additions & 1 deletion
This file was deleted.

dvn_client/resources/atom-example.xml

Lines changed: 0 additions & 49 deletions
This file was deleted.

dvn_client/src/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
__author__ = 'RLiebowitz'
1+
# To change this template, choose Tools | Templates
2+
# and open the template in the editor.

dvn_client/src/config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
DEFAULT_USERNAME = "FIXME"
2+
DEFAULT_PASSWORD = "FIXME"
3+
DEFAULT_HOST = "dvn-4.hmdc.harvard.edu"
4+
DEFAULT_CERT = "../resources/dvn-4.hmdc.harvard.edu"

dvn_client/src/connection.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,14 @@
1616
#local modules
1717
from dataverse import Dataverse
1818

19-
2019
class DvnConnection(object):
2120
# todo add port number
2221
def __init__(self, username, password, host, cert=None, sdUriOverride=None):
2322
# Connection Properties
2423
self.username = username
2524
self.password = password
2625
self.host = host
27-
self.sdUri = "https://{host}/dvn/api/data-deposit/v1/swordv2/service-document".format(host=self.host) \
28-
if not sdUriOverride else sdUriOverride.format(host=self.host)
26+
self.sdUri = "https://{host}/dvn/api/data-deposit/v1/swordv2/service-document".format(host=self.host) if not sdUriOverride else sdUriOverride.format(host=self.host)
2927
self.cert = cert
3028

3129
# Connection Status and SWORD Properties
@@ -41,12 +39,10 @@ def __init__(self, username, password, host, cert=None, sdUriOverride=None):
4139

4240
# todo raise exception if connection fails?
4341
def _connect(self):
44-
self.swordConnection = sword2.Connection(
45-
service_document_iri=self.sdUri,
46-
user_name=self.username,
47-
user_pass=self.password,
48-
ca_certs=self.cert,
49-
)
42+
self.swordConnection = sword2.Connection(self.sdUri,
43+
user_name = self.username,
44+
user_pass = self.password,
45+
ca_certs = self.cert)
5046

5147
self.serviceDocument = self.swordConnection.get_service_document()
5248
self.connected = True

dvn_client/src/dataverse.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
# python base lib modules
55
import pprint
66

7-
# downloaded modules
7+
#downloaded modules
88
from lxml import etree
99

10-
# local modules
10+
#local modules
1111
from study import Study
1212
import utils
1313

@@ -29,15 +29,14 @@ def is_released(self):
2929
collectionInfo,
3030
namespace="http://purl.org/net/sword/terms/state",
3131
tag="dataverseHasBeenReleased",
32-
numberOfElements=1,
32+
numberOfElements=1
3333
).text
3434
return bool(status)
3535

36-
def add_study(self, study):
37-
# this creates the study AND generates a deposit receipt
36+
def add_study(self, study):
3837
depositReceipt = self.connection.swordConnection.create(
39-
col_iri=self.collection.href,
4038
metadata_entry=study.entry,
39+
col_iri=self.collection.href
4140
)
4241

4342
study.hostDataverse = self
@@ -46,9 +45,6 @@ def add_study(self, study):
4645

4746
def delete_study(self, study):
4847
depositReceipt = self.connection.swordConnection.delete(study.editUri)
49-
study.lastDepositReceipt = depositReceipt
50-
51-
# todo: Is this used? Should it be? Other ways to handle this?
5248
study.isDeleted = True
5349

5450
# Note: Functionality removed
@@ -70,13 +66,13 @@ def get_studies(self):
7066
studiesResponse = self.connection.swordConnection.get_resource(self.collection.href)
7167

7268
return [
73-
Study.from_entry_element(element, hostDataverse=self)
69+
Study.CreateStudyFromEntryElement(element, hostDataverse=self)
7470
for element in utils.get_elements(studiesResponse.content, tag='entry')
7571
]
7672
# # get all the entry nodes and parse them into study objects
7773
# studies = []
7874
# for element in utils.get_elements(studiesResponse.content, tag="entry"):
79-
# s = Study.from_entry_element(element, hostDataverse=self)
75+
# s = Study.CreateStudyFromEntryElement(element, hostDataverse=self)
8076
# studies.append(s)
8177
#
8278
# return studies
Lines changed: 26 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,11 @@
1616
from time import sleep
1717
import traceback
1818

19-
# downloaded modules
19+
#downloaded modules
2020

21-
# local modules
22-
from dvn_client.src.study import Study
23-
from dvn_client.src.connection import DvnConnection
24-
from config import DEFAULT_PASSWORD, DEFAULT_HOST, DEFAULT_CERT, DEFAULT_USERNAME, EXAMPLE_FILE, \
25-
EXAMPLE_DICT
21+
#local modules
22+
from study import Study
23+
from connection import DvnConnection
2624

2725
def parse_arguments():
2826
parser = argparse.ArgumentParser(description='dvn_client exercises the APIs available for a DataVerse Network')
@@ -45,7 +43,7 @@ def main():
4543
execfile(args.config, globals())
4644
execfile(args.runTests, globals())
4745

48-
dv = None # declare outside so except clause has access
46+
dv = None #declare outside so except clause has access
4947
try:
5048
dvc = DvnConnection(username=DEFAULT_USERNAME,
5149
password=DEFAULT_PASSWORD,
@@ -61,36 +59,29 @@ def main():
6159
dv = dvs[0]
6260

6361
# clean up the test dataverse
64-
# dv.delete_all_studies()
65-
# print "RELEASED:", dv.is_released()
66-
67-
# s = dv.get_studies()[0]
68-
# s = Study(EXAMPLE_DICT)
69-
# s = Study(EXAMPLE_FILE)
70-
# dv.add_study(s)
71-
# print s
72-
73-
# print s.get_entry()
74-
75-
# s.add_files([INGEST_FILES])
76-
# print s.get_citation()
77-
# print s.get_state()
78-
79-
# sleep(3) #wait for ingest`
62+
#dv.delete_all_studies()
63+
print "RELEASED: ", dv.is_released()
8064

81-
# fs = s.get_files()
82-
# print "FILES: ", len(fs)
83-
# s.delete_file(fs[-1])
84-
# fs = s.get_files()
85-
# print "FILES: ", len(fs)
86-
# s.delete_all_files()
87-
# fs = s.get_files()
88-
# print "FILES: ", len(fs)
65+
#s = Study.CreateStudyFromDict(PICS_OF_CATS_STUDY)
66+
s = Study.CreateStudyFromAtomEntryXmlFile("/home/vagrant/dvn_client/resources/atom-entry-study.xml")
67+
dv.add_study(s)
68+
#s.add_files([INGEST_FILES])
69+
print s.get_citation()
70+
print s.get_state()
71+
72+
#sleep(3) #wait for ingest`
73+
74+
#fs = s.get_files()
75+
#print "FILES: ", len(fs)
76+
#s.delete_file(fs[-1])
77+
#fs = s.get_files()
78+
#print "FILES: ", len(fs)
79+
#s.delete_all_files()
80+
#fs = s.get_files()
81+
#print "FILES: ", len(fs)
82+
83+
#s.release()
8984

90-
# s.release()
91-
92-
# s.hostDataverse.delete_study(s)
93-
9485
print "\n\ndvn_client succeeded"
9586

9687
except Exception as e:
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@
1414
logging.basicConfig(level=logging.ERROR)
1515

1616
#local modules
17-
from dvn_client.src.study import Study
18-
from dvn_client.src.connection import DvnConnection
19-
from dvn_client.src.example.config import DEFAULT_USERNAME, DEFAULT_CERT, DEFAULT_HOST, DEFAULT_PASSWORD
20-
from dvn_client.src.test.tests import PIC_OF_CAT, PICS_OF_CATS_STUDY, INGEST_FILES, ATOM_STUDY
17+
from study import Study
18+
from connection import DvnConnection
2119

2220
class TestStudyOperations(unittest.TestCase):
2321
@classmethod
@@ -26,7 +24,7 @@ def setUpClass(self):
2624

2725
print "Loading test data."
2826
testModulePath = os.path.dirname(__file__)
29-
execfile(os.path.join(testModulePath, "../example/config.py"), globals()) #CREDS - This file is not committed.
27+
execfile(os.path.join(testModulePath, "config.py"), globals()) #CREDS - This file is not committed.
3028
execfile(os.path.join(testModulePath, "tests.py"), globals()) #TEST DATA
3129

3230
print "Connecting to DVN."
@@ -45,7 +43,7 @@ def setUp(self):
4543
#runs before each test method
4644

4745
#create a study for each test
48-
s = Study.from_dict(PICS_OF_CATS_STUDY)
46+
s = Study.CreateStudyFromDict(PICS_OF_CATS_STUDY)
4947
self.dv.add_study(s)
5048
id = s.get_id()
5149
self.s = self.dv.get_study_by_hdl(id)
@@ -59,7 +57,7 @@ def tearDown(self):
5957
return
6058

6159
def test_create_study_from_xml(self):
62-
xmlStudy = Study.from_atom_xml_file(ATOM_STUDY)
60+
xmlStudy = Study.CreateStudyFromAtomEntryXmlFile(ATOM_STUDY)
6361
self.dv.add_study(xmlStudy)
6462
atomStudy = self.dv.get_study_by_string_in_entry("The first study for the New England Journal of Coffee dataverse")
6563
self.assertTrue(atomStudy)
@@ -106,7 +104,7 @@ def test_delete_a_file(self):
106104
self.assertTrue(len(catFile) == 0)
107105

108106
def test_delete_a_study(self):
109-
xmlStudy = Study.from_atom_xml_file(ATOM_STUDY)
107+
xmlStudy = Study.CreateStudyFromAtomEntryXmlFile(ATOM_STUDY)
110108
self.dv.add_study(xmlStudy)
111109
atomStudy = self.dv.get_study_by_string_in_entry("The first study for the New England Journal of Coffee dataverse")
112110
self.assertTrue(atomStudy)

0 commit comments

Comments
 (0)