33from datetime import datetime
44import unittest
55
6+ from models .extract import Extract , ExtractProcess
67from models .process import ErrorType , ErrorTracking , Process , ProcessTracking
78
8- from process_tracker import data_store_type
9- from process_tracker import session
9+ from process_tracker import data_store_type , session
10+ from process_tracker . extract_tracking import ExtractTracker
1011from process_tracker .process_tracking import ProcessTracker
1112
1213
@@ -36,7 +37,9 @@ def tearDown(self):
3637 Need to clean up tables to return them to pristine state for other tests.
3738 :return:
3839 """
40+ session .query (ExtractProcess ).delete ()
3941 session .query (ProcessTracking ).delete ()
42+ session .query (Extract ).delete ()
4043 session .query (ErrorTracking ).delete ()
4144 session .query (ErrorType ).delete ()
4245 session .commit ()
@@ -52,6 +55,90 @@ def test_verify_session_variables_postgresql(self):
5255
5356 self .assertEqual (expected_result , given_result )
5457
58+ def test_find_ready_extracts_by_filename_full (self ):
59+ """
60+ Testing that for the given full filename, find the extract, provided it's in 'ready' state.
61+ :return:
62+ """
63+ extract = ExtractTracker (process_run = self .process_tracker
64+ , filename = 'test_extract_filename2.csv'
65+ , location_name = 'Test Location'
66+ , location_path = '/home/test/extract_dir' )
67+
68+ # Need to manually change the status, because this would normally be done while the process was processing data
69+ extract .extract .extract_status_id = extract .extract_status_ready
70+
71+ session .commit ()
72+
73+ expected_result = ['/home/test/extract_dir/test_extract_filename2.csv' ]
74+
75+ given_result = self .process_tracker .find_ready_extracts_by_filename ('test_extract_filename2.csv' )
76+
77+ self .assertEqual (expected_result , given_result )
78+
79+ def test_find_ready_extracts_by_filename_partial (self ):
80+ """
81+ Testing that for the given partial filename, find the extracts, provided they are in 'ready' state.
82+ :return:
83+ """
84+ extract = ExtractTracker (process_run = self .process_tracker
85+ , filename = 'test_extract_filename3.csv'
86+ , location_name = 'Test Location'
87+ , location_path = '/home/test/extract_dir' )
88+
89+ # Need to manually change the status, because this would normally be done while the process was processing data
90+ extract .extract .extract_status_id = extract .extract_status_ready
91+
92+ session .commit ()
93+
94+ expected_result = ['/home/test/extract_dir/test_extract_filename3.csv' ]
95+
96+ given_result = self .process_tracker .find_ready_extracts_by_filename ('test_extract_filename' )
97+
98+ self .assertEqual (expected_result , given_result )
99+
100+ def test_find_ready_extracts_by_location (self ):
101+ """
102+ Testing that for the given location name, find the extracts, provided they are in 'ready' state.
103+ :return:
104+ """
105+ extract = ExtractTracker (process_run = self .process_tracker
106+ , filename = 'test_extract_filename4.csv'
107+ , location_name = 'Test Location'
108+ , location_path = '/home/test/extract_dir' )
109+
110+ # Need to manually change the status, because this would normally be done while the process was processing data
111+ extract .extract .extract_status_id = extract .extract_status_ready
112+
113+ session .commit ()
114+
115+ expected_result = ['/home/test/extract_dir/test_extract_filename4.csv' ]
116+
117+ given_result = self .process_tracker .find_ready_extracts_by_location ('Test Location' )
118+
119+ self .assertEqual (expected_result , given_result )
120+
121+ def test_find_ready_extracts_by_process (self ):
122+ """
123+ Testing that for the given process name, find the extracts, provided they are in 'ready' state.
124+ :return:
125+ """
126+ extract = ExtractTracker (process_run = self .process_tracker
127+ , filename = 'test_extract_filename5.csv'
128+ , location_name = 'Test Location'
129+ , location_path = '/home/test/extract_dir' )
130+
131+ # Need to manually change the status, because this would normally be done while the process was processing data
132+ extract .extract .extract_status_id = extract .extract_status_ready
133+
134+ session .commit ()
135+
136+ expected_result = ['/home/test/extract_dir/test_extract_filename5.csv' ]
137+
138+ given_result = self .process_tracker .find_ready_extracts_by_process ('Testing Process Tracking Initialization' )
139+
140+ self .assertEqual (expected_result , given_result )
141+
55142 def test_initializing_process_tracking (self ):
56143 """
57144 Testing that when ProcessTracking is initialized, the necessary objects are created.
0 commit comments