From 69ec1e8e6ab36d245ecc9cd6bd3de1e1d2057797 Mon Sep 17 00:00:00 2001 From: Matt Martz Date: Tue, 22 Dec 2015 10:52:03 -0600 Subject: [PATCH] Check for requests imports. Fixes #12 --- ansible_testing/modules.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ansible_testing/modules.py b/ansible_testing/modules.py index d67beb7fd8d..1196d699e9b 100644 --- a/ansible_testing/modules.py +++ b/ansible_testing/modules.py @@ -196,6 +196,16 @@ class ModuleValidator(Validator): 'already provided by ' 'ansible.module_utils.basic') + def _find_requests_import(self): + for child in self.ast.body: + if isinstance(child, ast.Import): + for name in child.names: + if name.name == 'requests': + self.errors.append('requests import found, ' + 'should use ' + 'ansible.module_utils.urls ' + 'instead') + def _find_module_utils(self, main): linenos = [] for child in self.ast.body: @@ -401,6 +411,7 @@ class ModuleValidator(Validator): if self._python_module() and not self._just_docs(): self._check_for_sys_exit() self._find_json_import() + self._find_requests_import() main = self._find_main_call() self._find_module_utils(main) self._find_has_import()