Skip to content

Commit

Permalink
[test] convert remaining nose based test to pytest (cloudera#3705)
Browse files Browse the repository at this point in the history
  • Loading branch information
agl29 authored and a.terrien committed Dec 19, 2024
1 parent 4546928 commit 9928b8e
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
21 changes: 15 additions & 6 deletions apps/beeswax/src/beeswax/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ def _start_server(cluster):

env = cluster._mr2_env.copy()

hadoop_cp_proc = subprocess.Popen(args=[get_run_root('ext/hadoop/hadoop') + '/bin/hadoop', 'classpath'], env=env, cwd=cluster._tmpdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
hadoop_cp_proc = subprocess.Popen(
args=[get_run_root('ext/hadoop/hadoop') + '/bin/hadoop', 'classpath'],
env=env, cwd=cluster._tmpdir, stdout=subprocess.PIPE, stderr=subprocess.PIPE
)
hadoop_cp_proc.wait()
hadoop_cp = hadoop_cp_proc.stdout.read().strip()

Expand Down Expand Up @@ -343,10 +346,16 @@ def verify_history(client, fragment, design=None, reverse=False, server_name='be
Return the size of the history; -1 if we fail to determine it.
"""
resp = client.get('/%(server_name)s/query_history' % {'server_name': server_name})
my_assert = reverse and assert_false or assert_true
my_assert(fragment in resp.content, resp.content)
if design:
my_assert(design in resp.content, resp.content)
if reverse:
if fragment in resp.content:
raise AssertionError(f"Unexpected fragment '{fragment}' found in response:\n{resp.content}")
if design and design in resp.content:
raise AssertionError(f"Unexpected design '{design}' found in response:\n{resp.content}")
else:
if fragment not in resp.content:
raise AssertionError(f"Fragment '{fragment}' not found in response:\n{resp.content}")
if design and design not in resp.content:
raise AssertionError(f"Design '{design}' not found in response:\n{resp.content}")

if resp.context:
try:
Expand Down Expand Up @@ -377,7 +386,7 @@ def setup_class(cls, load_data=True):
grant_access('test', 'test', 'metastore')

# Weird redirection to avoid binding nonsense.
cls.shutdown = [ shutdown ]
cls.shutdown = [shutdown]
cls.init_beeswax_db()

@classmethod
Expand Down
23 changes: 13 additions & 10 deletions apps/metastore/src/metastore/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,23 +455,26 @@ def test_has_write_access_frontend(self):
grant_access("write_access_frontend", "write_access_frontend", "metastore")
user = User.objects.get(username='write_access_frontend')

def check(client, assertz):
response = client.get("/metastore/databases")
assertz("Drop</button>" in response.content, response.content)
assertz("Create a new database" in response.content, response.content)

response = client.get("/metastore/tables/")
assertz("Drop</button>" in response.content, response.content)
assertz("Create a new table" in response.content, response.content)
response = client.get("/metastore/databases")
assert not "Drop</button>" in response.content, response.content
assert not "Create a new database" in response.content, response.content

check(client, assert_false)
response = client.get("/metastore/tables/")
assert not "Drop</button>" in response.content, response.content
assert not "Create a new table" in response.content, response.content

# Add access
group, created = Group.objects.get_or_create(name='write_access_frontend')
perm, created = HuePermission.objects.get_or_create(app='metastore', action='write')
GroupPermission.objects.get_or_create(group=group, hue_permission=perm)

response = client.get("/metastore/databases")
assert "Drop</button>" in response.content, response.content
assert "Create a new database" in response.content, response.content

check(client, assert_true)
response = client.get("/metastore/tables/")
assert "Drop</button>" in response.content, response.content
assert "Create a new table" in response.content, response.content

def test_has_write_access_backend(self):
client = make_logged_in_client(username='write_access_backend', groupname='write_access_backend',
Expand Down
10 changes: 4 additions & 6 deletions apps/security/src/security/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,17 @@ def test_permissions(self):
grant_access("test_permissions", "test_permissions", "security")
user = User.objects.get(username='test_permissions')

def check(client, assertz):
response = client.get(reverse("security:hive"))
assertz("Impersonate the user" in response.content, response.content)

# Forbidden
check(client, assert_false)
response = client.get(reverse("security:hive"))
assert not "Impersonate the user" in response.content, response.content

# Allowed
group, created = Group.objects.get_or_create(name='test_permissions')
perm, created = HuePermission.objects.get_or_create(app='security', action='impersonate')
GroupPermission.objects.get_or_create(group=group, hue_permission=perm)

check(client, assert_true)
response = client.get(reverse("security:hive"))
assert "Impersonate the user" in response.content, response.content

def test_permissions(self):
privilege = {
Expand Down
6 changes: 4 additions & 2 deletions desktop/libs/hadoop/src/hadoop/fs/test_webhdfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,9 +306,11 @@ def test_i18n_namespace(self):
sys.setdefaultencoding('utf-8')

def check_existence(name, parent, present=True):
assertion = present and assert_true or assert_false
listing = self.cluster.fs.listdir(parent)
assertion(name in listing, "%s should be in %s" % (name, listing))
if present:
assert name in listing, f"{name} should be in {listing}"
else:
assert not name in listing, f"{name} should not be in {listing}"

name = u'''pt-Olá_ch-你好_ko-안녕_ru-Здравствуйте%20,.<>~`!@$%^&()_-+='"'''
prefix = self.prefix + '/tmp/i18n'
Expand Down

0 comments on commit 9928b8e

Please sign in to comment.