Skip to content

Commit

Permalink
Add integration tests latest vault metadata
Browse files Browse the repository at this point in the history
Add basic integration tests for meta.get_latest_vault_metadata_path
  • Loading branch information
stsnel committed Aug 6, 2024
1 parent 9e0083c commit 7bff302
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions integration_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import data_access_token
import folder
import meta
import schema
from util import avu, collection, config, constants, data_object, group, log, msi, resource, rule, user

Expand Down Expand Up @@ -170,6 +171,30 @@ def _test_schema_active_schema_vault_without_research(ctx):
return result


def _test_get_latest_vault_metadata_path_empty(ctx):
tmp_collection = _create_tmp_collection(ctx)
latest_file = meta.get_latest_vault_metadata_path(ctx, tmp_collection)
collection.remove(ctx, tmp_collection)
return latest_file is None


def _test_get_latest_vault_metadata_path_normal(ctx):
tmp_collection = _create_tmp_collection(ctx)
data_object.write(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869873].json"), "test")
data_object.write(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869875].json"), "test")
data_object.write(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869877].json"), "test")
data_object.write(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869876].json"), "test")
data_object.write(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869874].json"), "test")
latest_file = meta.get_latest_vault_metadata_path(ctx, tmp_collection)
data_object.remove(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869873].json"))
data_object.remove(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869875].json"))
data_object.remove(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869877].json"))
data_object.remove(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869876].json"))
data_object.remove(ctx, os.path.join(tmp_collection, "yoda-metadata[1722869874].json"))
collection.remove(ctx, tmp_collection)
return latest_file == os.path.join(tmp_collection, "yoda-metadata[1722869877].json")


def _test_folder_secure_func(ctx, func):
"""Create tmp collection, apply func to it and get result, and clean up.
Used for testing functions that modify avu/acls related to folder secure.
Expand Down Expand Up @@ -405,6 +430,12 @@ def _test_folder_secure_func(ctx, func):
{"name": "groups.rule_group_expiration_date_validate.6",
"test": lambda ctx: ctx.rule_group_expiration_date_validate("2044-02-26", ""),
"check": lambda x: x['arguments'][1] == 'true'},
{"name": "meta.get_latest_vault_metadata_path.empty",
"test": lambda ctx: _test_get_latest_vault_metadata_path_empty(ctx),
"check": lambda x: x},
{"name": "meta.get_latest_vault_metadata_path.normal",
"test": lambda ctx: _test_get_latest_vault_metadata_path_normal(ctx),
"check": lambda x: x},
{"name": "policies.check_anonymous_access_allowed.local",
"test": lambda ctx: ctx.rule_check_anonymous_access_allowed("127.0.0.1", ""),
"check": lambda x: x['arguments'][1] == 'true'},
Expand Down

0 comments on commit 7bff302

Please sign in to comment.