Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[test] convert remaining nose based test to pytest #3705

Merged
merged 1 commit into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading