Skip to content

Commit 99de8be

Browse files
committed
Enforced extract record ascending order
🐛 Closes: #13 🏗️ Configured Travis-CI to publish on Github Releases Resolved #13 where there was a chance where extracts could be returned in an order other than registration date. While this was unlikely, the order is now enforced in the queries. Also tweaked travis-ci to now publish releases to both PyPi and GitHub. This is based on git tags. Will not test the publishing until more of the first release backlog is done.
1 parent 1ccd22c commit 99de8be

File tree

3 files changed

+152
-14
lines changed

3 files changed

+152
-14
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,16 @@ env:
1818
process_tracking_data_store_name=process_tracking process_tracking_data_store_type=postgresql
1919
process_tracking_data_store_password=Testing1! process_tracking_data_store_username=pt_admin
2020
deploy:
21+
- provider: releases
22+
api_key:
23+
secure: T02NqddtE6qN/2ugvx/anZFzqmfnpWy2uCWcW4jg+pgiNI8GhRr0zh5Fwfe3aGnzAZLEgEMSgNWsM5CpniSbquioijqOEL/9xo8gZn6wV9VEjToR1/FEvGZm08T/Grc4rEYzjNgZu8eLUtC6Mg5l1nm6tGNEBE1oAKvflL77pnSGPL9enhmQupzbSQxNJ7rOuR7OgxuaFygP0Tne56Ca1LU6rAHmzqKJh6hI6eZARSikjLvgEHThcvZPc3gPfYMAc7i+dTx17Q3zQQGaHvySuLp+5aR3a+3xaFQPCmecLeiuX2yCiVVs9BOcrTeJOHivRYv6Cj9i60NUblvBlwOfJdo6uiArYTbVP/Aj8d1+8ruM5RdSeEyzlZlKarRN24CvH99OxU+LZGF5JgKV9UrTlytWl6ENOJcZq91LjejzkxGtKFp67abh8WPqqSGdcwA5VeI+QcHWDvc/3T/CdvljH4ivZRKeTCArAe4ce94WRvnJ6W0o3PoxrYxprhDFUyGUmrRJaLy/22qkkaifBQ9ljFgWNqeJtSGej87QhUVlfVnSS/6intr/sgd/vT0sDOU8RMTDxji3vkKKO1hfzBPKousqq48ddWGUxzAGwRoGULVbpwf8IIYApxlqotp40GpNOPJR6WrMUhHu/7jWGmvy66HPi4rQXKlaIWJLaH1f1yo=
24+
file: ''
25+
on:
26+
repo: OpenDataAlex/process_tracker_python
2127
- provider: pypi
2228
user: opendataalex
2329
password:
2430
secure: jYe8ygGYuJox5f1vQvraIDNlR2Yk/+/afIXdsxaxRi/QN135rIHxRih24iYv8ZQewfW+w4CveEPz2pr0ew5NG8hm2MD5hQZI/A2QE4BC53Tr3xMAWSdPQgcI1rX4Ieu6BHTS3jet212yLuBk41GdASKztz+s/CVvVqT0A29U1b85OVzoVHz6OTgaM1m0pKeJE6Ho66r5O6J7ClZfEY4RJ8jROmrT7ufW3hEs/VQXwfAUWcjy6l5H5VYTLa/g94MgQ+0WmgcdUbB8s3c2q7n4RiaVEowZOLtBmRElDIPiLJC8JGAIFKcf5W8pzXK/ZhZhY3ppgmBvRVeyPdiAwjysionzl4vIlNxC28acI3HzvJbAdvwPsuMD+pnTo/LKRqqvGey2NSnMPmzGXxzqVUqQ5Wa1Yzdcqg8mbWHFRw9icMWKM84CnDBvqkmJcfnj5R4X6Rc77mr9jc5LMMBBblNtY7dQc2AooframujGA2mP1xABQ9vOSg89MdnlhHrgEK6m+Pz0S2hhlsGRw9yMF9L4Q1ie7xKeE49L3HKZSjKEgSMv9y9RbqnmW32F0UoKgWkCJE8DV9wbZe5Htn+lpwmXI0vu+cxnqsiZvG8wjm+klJGn5F84OFTN3zQOC/kIBXQXvutZYtgF0vofdCmKQzK9istl16Eur1r4NCbov3oM97o=
2531
on:
2632
tags: true
33+
-

process_tracker/process_tracker.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,11 @@ def find_ready_extracts_by_filename(self, filename):
9797
extract_files = []
9898

9999
process_files = self.session.query(Extract.extract_filename, Location.location_path)\
100-
.join(Location)\
101-
.join(ExtractStatus)\
102-
.filter(Extract.extract_filename.like("%" + filename + "%"))\
103-
.filter(ExtractStatus.extract_status_name == 'ready')
100+
.join(Location)\
101+
.join(ExtractStatus)\
102+
.filter(Extract.extract_filename.like("%" + filename + "%"))\
103+
.filter(ExtractStatus.extract_status_name == 'ready') \
104+
.order_by(Extract.extract_registration_date_time)
104105

105106
for record in process_files:
106107
extract_files.append(join(record.location_path, record.extract_filename))
@@ -119,7 +120,8 @@ def find_ready_extracts_by_location(self, location):
119120
.join(Location)\
120121
.join(ExtractStatus)\
121122
.filter(ExtractStatus.extract_status_name == 'ready')\
122-
.filter(Location.location_name == location)
123+
.filter(Location.location_name == location) \
124+
.order_by(Extract.extract_registration_date_time)
123125

124126
for record in process_files:
125127
extract_files.append(join(record.location_path, record.extract_filename))
@@ -140,7 +142,8 @@ def find_ready_extracts_by_process(self, extract_process_name):
140142
.join(ProcessTracking) \
141143
.join(Process) \
142144
.filter(Process.process_name == extract_process_name
143-
, ExtractStatus.extract_status_name == 'ready')
145+
, ExtractStatus.extract_status_name == 'ready') \
146+
.order_by(Extract.extract_registration_date_time)
144147

145148
for record in process_files:
146149
extract_files.append(join(record.location_path, record.extract_filename))

tests/test_process_tracker.py

Lines changed: 136 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ def test_find_ready_extracts_by_filename_full(self):
8686

8787
def test_find_ready_extracts_by_filename_partial(self):
8888
"""
89-
Testing that for the given partial filename, find the extracts, provided they are in 'ready' state.
89+
Testing that for the given partial filename, find the extracts, provided they are in 'ready' state. Should return
90+
them in ascending order by registration datetime.
9091
:return:
9192
"""
9293
extract = ExtractTracker(process_run=self.process_tracker
93-
, filename='test_extract_filename3.csv'
94+
, filename='test_extract_filename3-1.csv'
95+
, location_name='Test Location'
96+
, location_path='/home/test/extract_dir')
97+
98+
extract2 = ExtractTracker(process_run=self.process_tracker
99+
, filename='test_extract_filename3-2.csv'
94100
, location_name='Test Location'
95101
, location_path='/home/test/extract_dir')
96102

@@ -99,19 +105,62 @@ def test_find_ready_extracts_by_filename_partial(self):
99105
session = Session.object_session(extract.extract)
100106
session.commit()
101107

102-
expected_result = ['/home/test/extract_dir/test_extract_filename3.csv']
108+
extract2.extract.extract_status_id = extract2.extract_status_ready
109+
session = Session.object_session(extract2.extract)
110+
session.commit()
111+
112+
expected_result = ['/home/test/extract_dir/test_extract_filename3-1.csv'
113+
, '/home/test/extract_dir/test_extract_filename3-2.csv']
103114

104115
given_result = self.process_tracker.find_ready_extracts_by_filename('test_extract_filename')
105116

106117
self.assertEqual(expected_result, given_result)
107118

119+
def test_find_ready_extracts_by_filename_partial_not_descending(self):
120+
"""
121+
Testing that for the given partial filename, find the extracts, provided they are in 'ready' state. Verifying
122+
that records are NOT returned in descending order.
123+
:return:
124+
"""
125+
extract = ExtractTracker(process_run=self.process_tracker
126+
, filename='test_extract_filename3-1.csv'
127+
, location_name='Test Location'
128+
, location_path='/home/test/extract_dir')
129+
130+
extract2 = ExtractTracker(process_run=self.process_tracker
131+
, filename='test_extract_filename3-2.csv'
132+
, location_name='Test Location'
133+
, location_path='/home/test/extract_dir')
134+
135+
# Need to manually change the status, because this would normally be done while the process was processing data
136+
extract.extract.extract_status_id = extract.extract_status_ready
137+
session = Session.object_session(extract.extract)
138+
session.commit()
139+
140+
extract2.extract.extract_status_id = extract2.extract_status_ready
141+
session = Session.object_session(extract2.extract)
142+
session.commit()
143+
144+
expected_result = ['/home/test/extract_dir/test_extract_filename3-2.csv'
145+
, '/home/test/extract_dir/test_extract_filename3-1.csv']
146+
147+
given_result = self.process_tracker.find_ready_extracts_by_filename('test_extract_filename')
148+
149+
self.assertNotEqual(expected_result, given_result)
150+
108151
def test_find_ready_extracts_by_location(self):
109152
"""
110-
Testing that for the given location name, find the extracts, provided they are in 'ready' state.
153+
Testing that for the given location name, find the extracts, provided they are in 'ready' state. Should return
154+
them in ascending order by registration datettime.
111155
:return:
112156
"""
113157
extract = ExtractTracker(process_run=self.process_tracker
114-
, filename='test_extract_filename4.csv'
158+
, filename='test_extract_filename4-1.csv'
159+
, location_name='Test Location'
160+
, location_path='/home/test/extract_dir')
161+
162+
extract2 = ExtractTracker(process_run=self.process_tracker
163+
, filename='test_extract_filename4-2.csv'
115164
, location_name='Test Location'
116165
, location_path='/home/test/extract_dir')
117166

@@ -120,19 +169,61 @@ def test_find_ready_extracts_by_location(self):
120169
session = Session.object_session(extract.extract)
121170
session.commit()
122171

123-
expected_result = ['/home/test/extract_dir/test_extract_filename4.csv']
172+
extract2.extract.extract_status_id = extract2.extract_status_ready
173+
session = Session.object_session(extract2.extract)
174+
session.commit()
175+
176+
expected_result = ['/home/test/extract_dir/test_extract_filename4-1.csv'
177+
, '/home/test/extract_dir/test_extract_filename4-2.csv']
124178

125179
given_result = self.process_tracker.find_ready_extracts_by_location('Test Location')
126180

127181
self.assertEqual(expected_result, given_result)
128182

183+
def test_find_ready_extracts_by_location_not_descending(self):
184+
"""
185+
Testing that for the given location name, find the extracts, provided they are in 'ready' state. Verifying that
186+
records NOT returned in descending order.
187+
:return:
188+
"""
189+
extract = ExtractTracker(process_run=self.process_tracker
190+
, filename='test_extract_filename4-1.csv'
191+
, location_name='Test Location'
192+
, location_path='/home/test/extract_dir')
193+
194+
extract2 = ExtractTracker(process_run=self.process_tracker
195+
, filename='test_extract_filename4-2.csv'
196+
, location_name='Test Location'
197+
, location_path='/home/test/extract_dir')
198+
199+
# Need to manually change the status, because this would normally be done while the process was processing data
200+
extract.extract.extract_status_id = extract.extract_status_ready
201+
session = Session.object_session(extract.extract)
202+
session.commit()
203+
204+
extract2.extract.extract_status_id = extract2.extract_status_ready
205+
session = Session.object_session(extract2.extract)
206+
session.commit()
207+
208+
expected_result = ['/home/test/extract_dir/test_extract_filename4-2.csv'
209+
, '/home/test/extract_dir/test_extract_filename4-1.csv']
210+
211+
given_result = self.process_tracker.find_ready_extracts_by_location('Test Location')
212+
213+
self.assertNotEqual(expected_result, given_result)
214+
129215
def test_find_ready_extracts_by_process(self):
130216
"""
131217
Testing that for the given process name, find the extracts, provided they are in 'ready' state.
132218
:return:
133219
"""
134220
extract = ExtractTracker(process_run=self.process_tracker
135-
, filename='test_extract_filename5.csv'
221+
, filename='test_extract_filename5-1.csv'
222+
, location_name='Test Location'
223+
, location_path='/home/test/extract_dir')
224+
225+
extract2 = ExtractTracker(process_run=self.process_tracker
226+
, filename='test_extract_filename5-2.csv'
136227
, location_name='Test Location'
137228
, location_path='/home/test/extract_dir')
138229

@@ -141,12 +232,49 @@ def test_find_ready_extracts_by_process(self):
141232
session = Session.object_session(extract.extract)
142233
session.commit()
143234

144-
expected_result = ['/home/test/extract_dir/test_extract_filename5.csv']
235+
extract2.extract.extract_status_id = extract2.extract_status_ready
236+
session = Session.object_session(extract2.extract)
237+
session.commit()
238+
239+
expected_result = ['/home/test/extract_dir/test_extract_filename5-1.csv'
240+
, '/home/test/extract_dir/test_extract_filename5-2.csv']
145241

146242
given_result = self.process_tracker.find_ready_extracts_by_process('Testing Process Tracking Initialization')
147243

148244
self.assertEqual(expected_result, given_result)
149245

246+
def test_find_ready_extracts_by_process_not_descending(self):
247+
"""
248+
Testing that for the given process name, find the extracts, provided they are in 'ready' state. Verifying that
249+
records are NOT returned in Descending order.
250+
:return:
251+
"""
252+
extract = ExtractTracker(process_run=self.process_tracker
253+
, filename='test_extract_filename5-1.csv'
254+
, location_name='Test Location'
255+
, location_path='/home/test/extract_dir')
256+
257+
extract2 = ExtractTracker(process_run=self.process_tracker
258+
, filename='test_extract_filename5-2.csv'
259+
, location_name='Test Location'
260+
, location_path='/home/test/extract_dir')
261+
262+
# Need to manually change the status, because this would normally be done while the process was processing data
263+
extract.extract.extract_status_id = extract.extract_status_ready
264+
session = Session.object_session(extract.extract)
265+
session.commit()
266+
267+
extract2.extract.extract_status_id = extract2.extract_status_ready
268+
session = Session.object_session(extract2.extract)
269+
session.commit()
270+
271+
expected_result = ['/home/test/extract_dir/test_extract_filename5-2.csv'
272+
, '/home/test/extract_dir/test_extract_filename5-1.csv']
273+
274+
given_result = self.process_tracker.find_ready_extracts_by_process('Testing Process Tracking Initialization')
275+
276+
self.assertNotEqual(expected_result, given_result)
277+
150278
def test_initializing_process_tracking(self):
151279
"""
152280
Testing that when ProcessTracking is initialized, the necessary objects are created.

0 commit comments

Comments
 (0)