-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b0228d6
commit 76f0193
Showing
5 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<xsd:schema targetNamespace="http://www.ivoa.net/xml/VOSIAvailability/v1.0" | ||
xmlns:tns="http://www.ivoa.net/xml/VOSIAvailability/v1.0" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
elementFormDefault="qualified" | ||
attributeFormDefault="unqualified" | ||
version="1.0"> | ||
|
||
<xsd:annotation> | ||
<xsd:documentation> | ||
A schema for formatting availability metadata as returned by an | ||
availability resource defined in the IVOA Support Interfaces | ||
specification (VOSI). | ||
See http://www.ivoa.net/Documents/latest/VOSI.html. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
|
||
<!-- | ||
- the root element for a VOSI availability (section 2.3) | ||
--> | ||
<xsd:element name="availability" type="tns:Availability"/> | ||
|
||
<xsd:complexType name="Availability"> | ||
<xsd:sequence> | ||
|
||
<xsd:element name="available" type="xsd:boolean"> | ||
<xsd:annotation> | ||
<xsd:documentation> | ||
Indicates whether the service is currently available. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
|
||
<xsd:element name="upSince" type="xsd:dateTime" minOccurs="0"> | ||
<xsd:annotation> | ||
<xsd:documentation> | ||
The instant at which the service last became available. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
|
||
<xsd:element name="downAt" type="xsd:dateTime" minOccurs="0"> | ||
<xsd:annotation> | ||
<xsd:documentation> | ||
The instant at which the service is next scheduled to become | ||
unavailable. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
|
||
<xsd:element name="backAt" type="xsd:dateTime" minOccurs="0"> | ||
<xsd:annotation> | ||
<xsd:documentation> | ||
The instant at which the service is scheduled to become available | ||
again after a period of unavailability. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
|
||
<xsd:element name="note" type="xsd:string" | ||
minOccurs="0" maxOccurs="unbounded"> | ||
<xsd:annotation> | ||
<xsd:documentation> | ||
A textual note concerning availability. | ||
</xsd:documentation> | ||
</xsd:annotation> | ||
</xsd:element> | ||
|
||
</xsd:sequence> | ||
</xsd:complexType> | ||
|
||
</xsd:schema> |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
"""Tests for VOSI Availability models.""" | ||
|
||
from datetime import timezone as tz | ||
from unittest import TestCase | ||
from xml.etree.ElementTree import canonicalize | ||
|
||
from lxml import etree | ||
|
||
with open("tests/vosi/VOSIAvailability-v1.0.xsd") as f: | ||
availability_schema = etree.parse(f) | ||
|
||
from vo_models.xml.vosi.availability import Availability | ||
from vo_models.xml.generics import VODateTime | ||
|
||
VOSI_AVAILABILITY_HEADER = """xmlns="http://www.ivoa.net/xml/VOSIAvailability/v1.0" | ||
xmlns:xsd="http://www.w3.org/2001/XMLSchema" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
""" | ||
|
||
class TestVOSIAvailabilityType(TestCase): | ||
"""Tests the VOSI Availability complex type.""" | ||
|
||
test_avaiability_xml = f"""<availability {VOSI_AVAILABILITY_HEADER}> | ||
<available>true</available> | ||
<upSince>2021-01-01T00:00:00.000Z</upSince> | ||
<downAt>2021-01-01T00:00:00.000Z</downAt> | ||
<backAt>2021-01-01T00:00:00.000Z</backAt> | ||
<note>Test note</note> | ||
</availability>""" | ||
|
||
def test_read_from_xml(self): | ||
"""Test reading Availability from XML.""" | ||
availability = Availability.from_xml(self.test_avaiability_xml) | ||
self.assertTrue(availability.available) | ||
self.assertEqual(availability.up_since, VODateTime(2021, 1, 1, tzinfo=tz.utc)) | ||
self.assertEqual(availability.down_at, VODateTime(2021, 1, 1, tzinfo=tz.utc)) | ||
self.assertEqual(availability.back_at, VODateTime(2021, 1, 1, tzinfo=tz.utc)) | ||
self.assertEqual(availability.note, ["Test note"]) | ||
|
||
def test_write_to_xml(self): | ||
"""Test writing Availability to XML.""" | ||
availability = Availability( | ||
available=True, | ||
up_since="2021-01-01T00:00:00.000Z", | ||
down_at="2021-01-01T00:00:00.000Z", | ||
back_at="2021-01-01T00:00:00.000Z", | ||
note=["Test note"], | ||
) | ||
|
||
with open("debug.xml", "w") as f: | ||
f.write(canonicalize(availability.to_xml())) | ||
f.write("\n") | ||
f.write(canonicalize(self.test_avaiability_xml)) | ||
|
||
availability_xml = availability.to_xml() | ||
self.assertEqual( | ||
canonicalize(availability_xml, strip_text=True), | ||
canonicalize(self.test_avaiability_xml, strip_text=True), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
"""Module containing VOSI (VO Service Interface) classes.""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
"""VOSIAvailability pydantic-xml models.""" | ||
|
||
from typing import Optional | ||
|
||
from pydantic_xml import BaseXmlModel, element | ||
|
||
from vo_models.xml.generics import VODateTime | ||
|
||
NSMAP = { | ||
"": "http://www.ivoa.net/xml/VOSIAvailability/v1.0", | ||
"xsd": "http://www.w3.org/2001/XMLSchema", | ||
"xsi": "http://www.w3.org/2001/XMLSchema-instance", | ||
} | ||
|
||
|
||
class Availability(BaseXmlModel, tag="availability", nsmap=NSMAP): | ||
"""VOSI Availability complex type. | ||
Elements: | ||
available (bool): Whether the service is currently available. | ||
upSince (datetime): The instant at which the service last became available. | ||
downAt (datetime): The instant at which the service is next scheduled to become unavailable. | ||
backAt (datetime): The instant at which the service is scheduled to become available again after a period | ||
of unavailability. | ||
note (str): A textual note concerning availability. | ||
""" | ||
|
||
available: bool = element(tag="available") | ||
up_since: Optional[VODateTime] = element(tag="upSince") | ||
down_at: Optional[VODateTime] = element(tag="downAt") | ||
back_at: Optional[VODateTime] = element(tag="backAt") | ||
note: Optional[list[str]] = element(tag="note") |