Skip to content

Commit

Permalink
add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Harshg999 committed Nov 27, 2024
1 parent 7140c73 commit 3b14790
Showing 1 changed file with 297 additions and 14 deletions.
311 changes: 297 additions & 14 deletions desktop/core/src/desktop/lib/fs/ozone/ofsstat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,208 @@
from desktop.lib.fs.ozone.ofsstat import OzoneFSStat


class TestOzoneFSStat(object):
def setup_method(self):
class TestOzoneFSStat:
def test_stat_normal_file_path(self):
test_file_status = {
'pathSuffix': 'testfile.csv', 'type': 'FILE', 'length': 32, 'owner': 'hueadmin', 'group': 'huegroup',
'permission': '666', 'accessTime': 1677914460588, 'modificationTime': 1677914460588, 'blockSize': 268435456, 'replication': 3}
'pathSuffix': 'testfile.csv',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}

test_parent_path = '/ozone1/gethue/'
test_parent_path = '/gethue/buck'

self.stat = OzoneFSStat(test_file_status, test_parent_path)
self.stat = OzoneFSStat(test_file_status, test_parent_path, 'ozone1')

assert self.stat.name == 'testfile.csv'
assert self.stat.path == 'ofs://ozone1/gethue/buck/testfile.csv'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1/gethue/buck/testfile.csv',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_root_path(self):
test_path_status = {
'pathSuffix': 'ozone1',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = 'ofs://'
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

assert self.stat.name == 'ozone1'
assert self.stat.path == 'ofs://ozone1'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_normal_volume_path(self):
test_path_status = {
'pathSuffix': 'gethue',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = ''
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

assert self.stat.name == 'gethue'
assert self.stat.path == 'ofs://ozone1/gethue'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1/gethue',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_volume_path_startswith_serviceid(self):
test_path_status = {
'pathSuffix': 'ozone1-gethue',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = ''
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

assert self.stat.name == 'ozone1-gethue'
assert self.stat.path == 'ofs://ozone1/ozone1-gethue'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1/ozone1-gethue',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_file_path_when_volume_name_startswith_serviceid(self):
test_path_status = {
'pathSuffix': 'testfile.csv',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = '/ozone1-gethue/buck'
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

def test_stat_attributes(self):
assert self.stat.name == 'testfile.csv'
assert self.stat.path == 'ofs://ozone1/gethue/testfile.csv'
assert self.stat.isDir == False
assert self.stat.path == 'ofs://ozone1/ozone1-gethue/buck/testfile.csv'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
Expand All @@ -42,14 +229,110 @@ def test_stat_attributes(self):
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit == None
assert self.stat.fileId == None
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1/ozone1-gethue/buck/testfile.csv',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_volume_path_equals_serviceid(self):
test_path_status = {
'pathSuffix': 'ozone1',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = ''
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

assert self.stat.name == 'ozone1'
assert self.stat.path == 'ofs://ozone1/ozone1'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

expected_json_dict = {
'path': 'ofs://ozone1/ozone1',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

def test_stat_file_path_when_volume_name_equals_serviceid(self):
test_path_status = {
'pathSuffix': 'testfile.csv',
'type': 'FILE',
'length': 32,
'owner': 'hueadmin',
'group': 'huegroup',
'permission': '666',
'accessTime': 1677914460588,
'modificationTime': 1677914460588,
'blockSize': 268435456,
'replication': 3,
}
test_parent_path = '/ozone1/buck'
self.stat = OzoneFSStat(test_path_status, test_parent_path, 'ozone1')

assert self.stat.name == 'testfile.csv'
assert self.stat.path == 'ofs://ozone1/ozone1/buck/testfile.csv'
assert self.stat.isDir is False
assert self.stat.type == 'FILE'
assert self.stat.atime == 1677914460
assert self.stat.mtime == 1677914460
assert self.stat.user == 'hueadmin'
assert self.stat.group == 'huegroup'
assert self.stat.size == 32
assert self.stat.blockSize == 268435456
assert self.stat.replication == 3
assert self.stat.aclBit is None
assert self.stat.fileId is None
assert self.stat.mode == 33206

def test_to_json_dict(self):
expected_json_dict = {
'path': 'ofs://ozone1/gethue/testfile.csv', 'size': 32, 'atime': 1677914460, 'mtime': 1677914460, 'mode': 33206, 'user': 'hueadmin',
'group': 'huegroup', 'blockSize': 268435456, 'replication': 3}
'path': 'ofs://ozone1/ozone1/buck/testfile.csv',
'size': 32,
'atime': 1677914460,
'mtime': 1677914460,
'mode': 33206,
'user': 'hueadmin',
'group': 'huegroup',
'blockSize': 268435456,
'replication': 3,
}

assert self.stat.to_json_dict() == expected_json_dict

0 comments on commit 3b14790

Please sign in to comment.