Skip to content

Commit e90ad71

Browse files
committed
fix: [test] fix crawler test rel path + kwargs
1 parent 888a7ff commit e90ad71

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

tests/test_api_crawler.py

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from unittest.mock import patch, MagicMock
1919

2020
sys.path.append(os.environ['AIL_BIN'])
21+
sys.path.append(os.environ['AIL_FLASK'])
2122
##################################
2223
# Import Project packages
2324
##################################
@@ -99,10 +100,10 @@ def _make_authenticated_request(self, method, endpoint, data=None, token=None):
99100

100101
# ==================== POST /api/v1/add/crawler/task ====================
101102

102-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
103-
@patch('var/www/blueprints/api_rest.ail_api.is_user_in_role')
104-
@patch('var/www/blueprints/api_rest.ail_api.get_basic_user_meta')
105-
@patch('var/www/blueprints/api_rest.crawlers.api_add_crawler_task')
103+
@patch('blueprints.api_rest.ail_api.authenticate_user')
104+
@patch('blueprints.api_rest.ail_api.is_user_in_role')
105+
@patch('blueprints.api_rest.ail_api.get_basic_user_meta')
106+
@patch('blueprints.api_rest.crawlers.api_add_crawler_task')
106107
def test_add_crawler_task_success(self, mock_add_task, mock_get_meta, mock_is_role, mock_auth):
107108
"""
108109
Test successful crawler task addition.
@@ -131,12 +132,12 @@ def test_add_crawler_task_success(self, mock_add_task, mock_get_meta, mock_is_ro
131132
call_args = mock_add_task.call_args
132133
self.assertEqual(call_args[0][0], self.test_data, "Should pass request data to crawler")
133134
self.assertEqual(call_args[0][1], 'test_org', "Should pass user org to crawler")
134-
self.assertEqual(call_args[0][2], 'test_user_id', "Should pass user_id to crawler")
135+
self.assertEqual(call_args.kwargs["user_id"], 'test_user_id', "Should pass user_id to crawler")
135136

136-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
137-
@patch('var/www/blueprints/api_rest.ail_api.is_user_in_role')
138-
@patch('var/www/blueprints/api_rest.ail_api.get_basic_user_meta')
139-
@patch('var/www/blueprints/api_rest.crawlers.api_add_crawler_task')
137+
@patch('blueprints.api_rest.ail_api.authenticate_user')
138+
@patch('blueprints.api_rest.ail_api.is_user_in_role')
139+
@patch('blueprints.api_rest.ail_api.get_basic_user_meta')
140+
@patch('blueprints.api_rest.crawlers.api_add_crawler_task')
140141
def test_add_crawler_task_error_from_crawler(self, mock_add_task, mock_get_meta, mock_is_role, mock_auth):
141142
"""
142143
Test crawler task addition when crawler returns an error.
@@ -187,9 +188,9 @@ def test_add_crawler_task_missing_url(self):
187188
188189
Verifies that requests without required 'url' field are handled appropriately.
189190
"""
190-
with patch('var/www/blueprints/api_rest.ail_api.authenticate_user') as mock_auth, \
191-
patch('var/www/blueprints/api_rest.ail_api.is_user_in_role') as mock_is_role, \
192-
patch('var/www/blueprints/api_rest.ail_api.get_basic_user_meta') as mock_get_meta:
191+
with patch('blueprints.api_rest.ail_api.authenticate_user') as mock_auth, \
192+
patch('blueprints.api_rest.ail_api.is_user_in_role') as mock_is_role, \
193+
patch('blueprints.api_rest.ail_api.get_basic_user_meta') as mock_get_meta:
193194

194195
# Mock authentication
195196
mock_auth.return_value = ({'status': 'success'}, 200)
@@ -224,7 +225,7 @@ def test_add_crawler_task_invalid_json(self):
224225
# Should return 400 Bad Request for invalid JSON
225226
self.assertIn(response.status_code, [400, 415], "Should return error for invalid JSON")
226227

227-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
228+
@patch('blueprints.api_rest.ail_api.authenticate_user')
228229
def test_add_crawler_task_invalid_token(self, mock_auth):
229230
"""
230231
Test crawler task addition with invalid token.
@@ -243,8 +244,8 @@ def test_add_crawler_task_invalid_token(self, mock_auth):
243244
self.assertEqual(response_data.get('status'), 'error', "Response should indicate error status")
244245
self.assertIn('token', response_data.get('reason', '').lower(), "Error message should mention token")
245246

246-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
247-
@patch('var/www/blueprints/api_rest.ail_api.is_user_in_role')
247+
@patch('blueprints.api_rest.ail_api.authenticate_user')
248+
@patch('blueprints.api_rest.ail_api.is_user_in_role')
248249
def test_add_crawler_task_wrong_role(self, mock_is_role, mock_auth):
249250
"""
250251
Test crawler task addition with insufficient user role.
@@ -266,10 +267,10 @@ def test_add_crawler_task_wrong_role(self, mock_is_role, mock_auth):
266267

267268
# ==================== POST /api/v1/add/crawler/capture ====================
268269

269-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
270-
@patch('var/www/blueprints/api_rest.ail_api.is_user_in_role')
271-
@patch('var/www/blueprints/api_rest.ail_api.get_user_from_token')
272-
@patch('var/www/blueprints/api_rest.crawlers.api_add_crawler_capture')
270+
@patch('blueprints.api_rest.ail_api.authenticate_user')
271+
@patch('blueprints.api_rest.ail_api.is_user_in_role')
272+
@patch('blueprints.api_rest.ail_api.get_user_from_token')
273+
@patch('blueprints.api_rest.crawlers.api_add_crawler_capture')
273274
def test_add_crawler_capture_success(self, mock_add_capture, mock_get_user, mock_is_role, mock_auth):
274275
"""
275276
Test successful crawler capture addition.
@@ -299,10 +300,10 @@ def test_add_crawler_capture_success(self, mock_add_capture, mock_get_user, mock
299300
self.assertEqual(call_args[0][0], self.test_data, "Should pass request data to crawler")
300301
self.assertEqual(call_args[0][1], 'test_user_id', "Should pass user_id to crawler")
301302

302-
@patch('var/www/blueprints/api_rest.ail_api.authenticate_user')
303-
@patch('var/www/blueprints/api_rest.ail_api.is_user_in_role')
304-
@patch('var/www/blueprints/api_rest.ail_api.get_user_from_token')
305-
@patch('var/www/blueprints/api_rest.crawlers.api_add_crawler_capture')
303+
@patch('blueprints.api_rest.ail_api.authenticate_user')
304+
@patch('blueprints.api_rest.ail_api.is_user_in_role')
305+
@patch('blueprints.api_rest.ail_api.get_user_from_token')
306+
@patch('blueprints.api_rest.crawlers.api_add_crawler_capture')
306307
def test_add_crawler_capture_error_from_crawler(self, mock_add_capture, mock_get_user, mock_is_role, mock_auth):
307308
"""
308309
Test crawler capture addition when crawler returns an error.

0 commit comments

Comments
 (0)