-
Notifications
You must be signed in to change notification settings - Fork 0
/
tests.py
199 lines (185 loc) · 9.27 KB
/
tests.py
1
2
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
import unittest
import os
from subprocess import call
import datetime
from time import sleep
import ConfigParser
import requests
from github import Github
from mongoengine import connect
from models import Repo
# abs_tests_dir = '/home/ahmad/tests'
clone_url = 'git@github.com:ahmad88me/jarsomatic-vocab-test.git'
test_folder = clone_url.split('/')[-1][:-4]
repo = clone_url.split(':')[1][:-4]
print 'test folder: %s' % test_folder
print 'repo %s ' % repo
connect("jarsomatic")
start_setup = False
class IntegrationTest(unittest.TestCase):
# vocabularies_abs_dir = os.path.join(abs_tests_dir, test_folder, 'Vocabularies.csv')
repo = None
def setUp(self):
"""
clone the test repo
clean Vocabularies.csv in master
push the changes
get the run
wait until it is completed
:return:
"""
if not start_setup:
return
start_time = datetime.datetime.now()
print 'start time: '+str(start_time)
config_file = 'jarsomatic.cfg'
config = ConfigParser.ConfigParser()
app_home = os.path.dirname(os.path.abspath(__file__))
if not os.path.isfile(os.path.join(app_home, config_file)):
print "\n*** The file: "+config_file+" is not here or is not accessible ***\n"
config.read(os.path.join(app_home, config_file))
self.abs_tests_dir = config.get('DEFAULT', 'tmp')
self.vocabularies_abs_dir = os.path.join(self.abs_tests_dir, test_folder, 'Vocabularies.csv')
print 'vocabularies dir: '+self.vocabularies_abs_dir
github_token = config.get('GITHUB', 'token')
self.g = Github(github_token)
comm = "git config --global user.email 'jarsomatic@delicias.dia.fi.upm.es' ; "
comm += "git config --global user.name 'Test' ; "
call(comm, shell=True)
comm = 'cd %s; rm -Rf %s ; git clone %s ' % (self.abs_tests_dir, test_folder, clone_url)
print "cloning command: "+comm
call(comm, shell=True)
f = open(self.vocabularies_abs_dir, 'w')
f.write('')
f.close()
comm = 'cd %s; git add .; git commit -m "tests cleaning step"; git push origin master ' % \
os.path.join(self.abs_tests_dir, test_folder)
print "cleaning command: "+comm
call(comm, shell=True)
sleep(30)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
while latest_repo['progress'] != 100:
print 'clear - keep waiting...'
print latest_repo['started_at']
sleep(15)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print 'preparation is done'
def tearDown(self):
pass
def test_1(self):
pass
def test_vocab_3_repos(self):
pass
comm = "git config --global user.email 'jarsomatic@delicias.dia.fi.upm.es' ; "
comm += "git config --global user.name 'Test3' ; "
call(comm, shell=True)
start_time = datetime.datetime.now()
print '%s start time: %s' % ('test_vocab_3_repos', str(start_time))
s = 'VocabURI;domain'
s += '\nhttp://purl.org/net/p-plan;e-Science,plan,provenance,scientific workflow'
s += '\nhttp://purl.org/net/wf-motifs;e-Science,workflow abstraction'
s += '\nhttp://purl.org/net/wf-invocation;e-Science,infrastructure,scientific workflow'
f = open(self.vocabularies_abs_dir, 'w')
f.write(s)
f.close()
comm = "cd %s ; git add . ; git commit -m 'automated test 3'; git push;" % \
os.path.join(self.abs_tests_dir, test_folder)
call(comm, shell=True)
sleep(30)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print latest_repo['started_at']
print latest_repo['name']
while latest_repo['progress'] != 100:
sleep(15)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print 'test3: '+str(latest_repo['progress'])
original_repo = 'jarsomatic/'+repo.split('/')[1]
print 'original repo: '+original_repo
r = self.g.get_repo(original_repo)
print 'get repo'
c = r.get_file_contents('site/index.html', 'gh-pages').decoded_content
print 'gotten the content'
response = c
assert len(response.split('<tr id')) == 4, 'Number of vocabularies does not match'
assert 'p-plan' in response, 'p-plan is not in the index.html'
assert 'wf-motifs' in response, 'wf-motifs is not in index.html'
assert 'wf-invocation' in response, 'wf-invocation is not in index.html'
def test_vocab_4_repos(self):
comm = "git config --global user.email 'jarsomatic@delicias.dia.fi.upm.es' ; "
comm += "git config --global user.name 'Test4' ; "
call(comm, shell=True)
start_time = datetime.datetime.now()
print '%s start time: %s' % ('test_vocab_4_repos', str(start_time))
s = 'VocabURI;domain'
s += '\nhttp://purl.org/net/p-plan;e-Science,plan,provenance,scientific workflow'
s += '\nhttp://purl.org/net/wf-motifs;e-Science,workflow abstraction'
s += '\nhttp://purl.org/net/wf-invocation;e-Science,infrastructure,scientific workflow'
s += '\nhttp://purl.org/net/ro-optimization;e-Science,Research Object'
f = open(self.vocabularies_abs_dir, 'w')
f.write(s)
f.close()
comm = "cd %s ; git add . ; git commit -m 'automated test 4'; git push;" % \
os.path.join(self.abs_tests_dir, test_folder)
call(comm, shell=True)
sleep(30)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print latest_repo['started_at']
print latest_repo['name']
while latest_repo['progress'] != 100:
sleep(15)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print 'test4: '+str(latest_repo['progress'])
original_repo = 'jarsomatic/'+repo.split('/')[1]
print 'original repo: '+original_repo
r = self.g.get_repo(original_repo)
print 'get repo'
c = r.get_file_contents('site/index.html', 'gh-pages').decoded_content
print 'gotten the content'
response = c
assert len(response.split('<tr id')) == 5, 'Number of vocabularies does not match'
assert 'p-plan' in response, 'p-plan is not in the index.html'
assert 'wf-motifs' in response, 'wf-motifs is not in index.html'
assert 'wf-invocation' in response, 'wf-invocation is not in index.html'
assert 'ro-optimization' in response, 'ro-optimization is not in index.html'
def test_vocab_5_repos(self):
comm = "git config --global user.email 'jarsomatic@delicias.dia.fi.upm.es' ; "
comm += "git config --global user.name 'Test5' ; "
call(comm, shell=True)
start_time = datetime.datetime.now()
print '%s start time: %s' % ('test_vocab_5_repos', str(start_time))
s = 'VocabURI;domain'
s += '\nhttp://purl.org/net/p-plan;e-Science,plan,provenance,scientific workflow'
s += '\nhttp://purl.org/net/wf-motifs;e-Science,workflow abstraction'
s += '\nhttp://purl.org/net/wf-invocation;e-Science,infrastructure,scientific workflow'
s += '\nhttp://purl.org/net/ro-optimization;e-Science,Research Object'
s += '\nhttp://purl.org/net/wf-fd;e-Science,workflow abstraction'
f = open(self.vocabularies_abs_dir, 'w')
f.write(s)
f.close()
comm = "cd %s ; git add . ; git commit -m 'automated test 5'; git push;" % \
os.path.join(self.abs_tests_dir, test_folder)
call(comm, shell=True)
sleep(30)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print latest_repo['started_at']
print latest_repo['name']
while latest_repo['progress'] != 100:
sleep(15)
latest_repo = requests.get('http://jarsomatic.linkeddata.es/get_latest_repo').json()
print 'test5: '+str(latest_repo['progress'])
original_repo = 'jarsomatic/'+repo.split('/')[1]
print 'original repo: '+original_repo
r = self.g.get_repo(original_repo)
print 'get repo'
c = r.get_file_contents('site/index.html', 'gh-pages').decoded_content
print 'gotten the content'
response = c
assert len(response.split('<tr id')) == 6, 'Number of vocabularies does not match'
assert 'p-plan' in response, 'p-plan is not in the index.html'
assert 'wf-motifs' in response, 'wf-motifs is not in index.html'
assert 'wf-invocation' in response, 'wf-invocation is not in index.html'
assert 'ro-optimization' in response, 'ro-optimization is not in index.html'
assert 'wf-fd' in response, 'wf-fd is not in index.html'
if __name__ == '__main__':
start_setup = True # so the test only run in the case of being called
unittest.main()