Skip to content

Commit

Permalink
Update unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bsmartradio committed Aug 21, 2024
1 parent 0ea4f4e commit 6e15a4f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
14 changes: 7 additions & 7 deletions python/lsst/alert/packet/bin/syncAllSchemasToRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def parse_args():
return parser.parse_args()


def upload_schema(registry_url, subject, schema_registry):
def upload_schemas(registry_url, subject, schema_registry):
"""Parse schema registry and upload all schemas.
"""
for schema_id in schema_registry.known_ids:
Expand All @@ -65,8 +65,8 @@ def upload_schema(registry_url, subject, schema_registry):
print(f"response text={response.text}")


def delete_schema(registry_url, subject):
"""Delete schema and then remake it in import mode"""
def clear_schema_registry_for_import(registry_url, subject):
"""Delete schemas in the registry and then remake it in import mode"""
# Define the URLs
url_mode = f"{registry_url}/mode/{subject}"
url_schemas = f"{registry_url}/subjects/{subject}"
Expand Down Expand Up @@ -101,7 +101,7 @@ def delete_schema(registry_url, subject):
print('Response Text:', response.text)


def close_schema(registry_url, subject):
def close_schema_registry(registry_url, subject):
"""Return the schema registry from import mode to readwrite.
"""
data = {
Expand All @@ -122,14 +122,14 @@ def close_schema(registry_url, subject):

def main():
args = parse_args()
delete_schema(args.schema_registry_url, args.subject)
clear_schema_registry_for_import(args.schema_registry_url, args.subject)
schema_registry = lsst.alert.packet.schemaRegistry.SchemaRegistry().all_schemas_from_filesystem()
upload_schema(
upload_schemas(
args.schema_registry_url,
subject=args.subject,
schema_registry=schema_registry
)
close_schema(args.schema_registry_url, args.subject)
close_schema_registry(args.schema_registry_url, args.subject)


if __name__ == "__main__":
Expand Down
6 changes: 5 additions & 1 deletion test/test_schemaRegistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def write_schema(root_dir, filename, version_major, version_minor):
# Generate a new schema for each version to avoid ID collisions.
schema = {
"name": "example",
"namespace": "lsst",
"namespace": f"lsst.v{version_major}_{version_minor}",
"type": "record",
"fields": [
{"name": "field%s%s" % (version_major, version_minor),
Expand Down Expand Up @@ -75,3 +75,7 @@ def test_from_filesystem(self):
for version in versions:
registry.get_by_version(version)
self.assertRaises(KeyError, registry.get_by_version, "2.2")

for id in registry.known_ids:
registry.get_by_id(id)
self.assertRaises(KeyError, registry.get_by_id, "202")

0 comments on commit 6e15a4f

Please sign in to comment.