|
| 1 | +from __future__ import print_function |
| 2 | +import importlib |
| 3 | +import os |
| 4 | +import sys |
| 5 | + |
| 6 | +from tests.support import MIG_BASE, MigTestCase, testmain, _temppath |
| 7 | + |
| 8 | +from mig.shared.base import client_id_dir |
| 9 | +from mig.shared.functionality.cat import _main as main |
| 10 | + |
| 11 | + |
| 12 | +def create_wsgi_environ(configuration, wsgi_variables={}): |
| 13 | + environ = {} |
| 14 | + environ['wsgi.input'] = () |
| 15 | + environ['MIG_CONF'] = configuration.config_file |
| 16 | + environ['HTTP_HOST'] = wsgi_variables.get('http_host', 'localhost') |
| 17 | + environ['PATH_INFO'] = wsgi_variables.get('path_info', '/') |
| 18 | + environ['REMOTE_ADDR'] = wsgi_variables.get('remote_addr', '127.0.0.1') |
| 19 | + environ['SCRIPT_URI'] = ''.join(('http://', environ['HTTP_HOST'], environ['PATH_INFO'])) |
| 20 | + return environ |
| 21 | + |
| 22 | + |
| 23 | +class MigCgibinCat(MigTestCase): |
| 24 | + TEST_CLIENT_ID = '/C=DK/ST=NA/L=NA/O=Test Org/OU=NA/CN=Test User/emailAddress=test@example.com' |
| 25 | + |
| 26 | + def _provide_configuration(self): |
| 27 | + return 'testconfig' |
| 28 | + |
| 29 | + def before_each(self): |
| 30 | + user_home = self.configuration.user_home[:-1] |
| 31 | + client_dir = client_id_dir(self.TEST_CLIENT_ID) |
| 32 | + # create the test user home directory |
| 33 | + self.test_user_dir = _temppath(os.path.join(user_home, client_dir), self, ensure_dir=True) |
| 34 | + self.test_environ = create_wsgi_environ(self.configuration) |
| 35 | + |
| 36 | + def test_returns_file_output_with_single_file_match(self): |
| 37 | + with open(os.path.join(self.test_user_dir, 'foobar.txt'), 'w'): |
| 38 | + pass |
| 39 | + payload = { |
| 40 | + 'path': ['foobar.txt'], |
| 41 | + } |
| 42 | + |
| 43 | + (output_objects, status) = main(self.configuration, self.logger, self.TEST_CLIENT_ID, user_arguments_dict=payload, environ=self.test_environ) |
| 44 | + self.assertEqual(len(output_objects), 1) |
| 45 | + output_obj = output_objects[0] |
| 46 | + self.assertEqual(output_obj['object_type'], 'file_output') |
| 47 | + |
| 48 | + |
| 49 | +if __name__ == '__main__': |
| 50 | + testmain() |
0 commit comments