Skip to content

Commit

Permalink
[AIRFLOW-5852] Make tests.www pylint compatible (apache#6504)
Browse files Browse the repository at this point in the history
  • Loading branch information
turbaszek authored and potiuk committed Nov 5, 2019
1 parent 5096fa3 commit 0b42d9d
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 85 deletions.
2 changes: 1 addition & 1 deletion pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ ignore-on-opaque-inference=yes
# List of class names for which member attributes should not be checked (useful
# for classes with dynamically set attributes). This supports the use of
# qualified names.
ignored-classes=optparse.Values,thread._local,_thread._local
ignored-classes=optparse.Values,thread._local,_thread._local,sqlalchemy.orm.scoping.scoped_session

# List of module names for which member attributes should not be checked
# (useful for modules/projects where namespaces are manipulated during runtime
Expand Down
5 changes: 0 additions & 5 deletions scripts/ci/pylint_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,8 +379,3 @@
./tests/utils/test_log_handlers.py
./tests/utils/test_tests.py
./tests/utils/test_timezone.py
./tests/www/api/experimental/test_endpoints.py
./tests/www/api/experimental/test_kerberos_endpoints.py
./tests/www/test_security.py
./tests/www/test_utils.py
./tests/www/test_views.py
6 changes: 0 additions & 6 deletions tests/www/api/experimental/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,6 @@ def setUpClass(cls):
for dag in dagbag.dags.values():
dag.sync_to_db()

def setUp(self):
super().setUp()

def tearDown(self):
session = Session()
session.query(DagRun).delete()
Expand Down Expand Up @@ -309,9 +306,6 @@ def setUp(self):
self.session.commit()
self.pool = self.pools[-1]

def tearDown(self):
super().tearDown()

def _get_pool_count(self):
response = self.client.get('/api/experimental/pools')
self.assertEqual(response.status_code, 200)
Expand Down
14 changes: 7 additions & 7 deletions tests/www/api/experimental/test_kerberos_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,14 @@ class TestApiKerberos(unittest.TestCase):
def setUp(self):
try:
conf.add_section("api")
except Exception:
except Exception: # pylint:disable=broad-except
pass
conf.set("api",
"auth_backend",
"airflow.api.auth.backend.kerberos_auth")
try:
conf.add_section("kerberos")
except Exception:
except Exception: # pylint:disable=broad-except
pass
conf.set("kerberos",
"keytab",
Expand All @@ -51,9 +51,9 @@ def setUp(self):
self.app, _ = application.create_app(testing=True)

def test_trigger_dag(self):
with self.app.test_client() as c:
with self.app.test_client() as client:
url_template = '/api/experimental/dags/{}/dag_runs'
response = c.post(
response = client.post(
url_template.format('example_bash_operator'),
data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
content_type="application/json"
Expand All @@ -80,7 +80,7 @@ class Request:
CLIENT_AUTH.handle_response(response)
self.assertIn('Authorization', response.request.headers)

response2 = c.post(
response2 = client.post(
url_template.format('example_bash_operator'),
data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
content_type="application/json",
Expand All @@ -89,9 +89,9 @@ class Request:
self.assertEqual(200, response2.status_code)

def test_unauthorized(self):
with self.app.test_client() as c:
with self.app.test_client() as client:
url_template = '/api/experimental/dags/{}/dag_runs'
response = c.post(
response = client.post(
url_template.format('example_bash_operator'),
data=json.dumps(dict(run_id='my_run' + datetime.now().isoformat())),
content_type="application/json"
Expand Down
6 changes: 3 additions & 3 deletions tests/www/test_security.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@
from airflow.exceptions import AirflowException
from airflow.www.security import AirflowSecurityManager

READ_WRITE = {'can_dag_read', 'can_dag_edit'}
READ_ONLY = {'can_dag_read'}

logging.basicConfig(format='%(asctime)s:%(levelname)s:%(name)s:%(message)s')
logging.getLogger().setLevel(logging.DEBUG)
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -267,9 +270,6 @@ def test_access_control_is_set_on_init(self):
)

def test_access_control_stale_perms_are_revoked(self):
READ_WRITE = {'can_dag_read', 'can_dag_edit'}
READ_ONLY = {'can_dag_read'}

self.expect_user_is_in_role(self.user, rolename='team-a')
self.security_manager.sync_perm_for_dag(
'access_control_test',
Expand Down
12 changes: 6 additions & 6 deletions tests/www/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def test_params_search(self):
(None, True, ''),
(None, False, ''),
])
def test_params_showPaused(self, show_paused, hide_by_default, expected_result):
def test_params_show_paused(self, show_paused, hide_by_default, expected_result):
with conf_vars({('webserver', 'hide_paused_dags_by_default'): str(hide_by_default)}):
self.assertEqual(expected_result,
utils.get_params(showPaused=show_paused))
Expand All @@ -139,9 +139,9 @@ def test_should_remove_show_paused_from_url_params(self, show_paused,
)

def test_params_none_and_zero(self):
qs = utils.get_params(a=0, b=None)
query_str = utils.get_params(a=0, b=None)
# The order won't be consistent, but that doesn't affect behaviour of a browser
pairs = list(sorted(qs.split('&')))
pairs = list(sorted(query_str.split('&')))
self.assertListEqual(['a=0', 'b='], pairs)

def test_params_all(self):
Expand Down Expand Up @@ -172,15 +172,15 @@ def test_open_maybe_zipped_normal_file_with_zip_in_name(self):

@mock.patch("zipfile.is_zipfile")
@mock.patch("zipfile.ZipFile")
def test_open_maybe_zipped_archive(self, mocked_ZipFile, mocked_is_zipfile):
def test_open_maybe_zipped_archive(self, mocked_zip_file, mocked_is_zipfile):
mocked_is_zipfile.return_value = True
instance = mocked_ZipFile.return_value
instance = mocked_zip_file.return_value
instance.open.return_value = mock.mock_open(read_data="data")

utils.open_maybe_zipped('/path/to/archive.zip/deep/path/to/file.txt')

mocked_is_zipfile.assert_called_once_with('/path/to/archive.zip')
mocked_ZipFile.assert_called_once_with('/path/to/archive.zip', mode='r')
mocked_zip_file.assert_called_once_with('/path/to/archive.zip', mode='r')
instance.open.assert_called_once_with('deep/path/to/file.txt')

def test_state_token(self):
Expand Down
Loading

0 comments on commit 0b42d9d

Please sign in to comment.