File tree 2 files changed +40
-3
lines changed 2 files changed +40
-3
lines changed Original file line number Diff line number Diff line change @@ -56,9 +56,6 @@ class Link:
56
56
"""Optional description of the media type. Registered Media Types are preferred.
57
57
See :class:`~pystac.MediaType` for common media types."""
58
58
59
- title : Optional [str ]
60
- """Optional title for this link."""
61
-
62
59
extra_fields : Dict [str , Any ]
63
60
"""Optional, additional fields for this link. This is used by extensions as a
64
61
way to serialize and deserialize properties on link object JSON."""
@@ -70,6 +67,7 @@ class Link:
70
67
71
68
_target_href : Optional [str ]
72
69
_target_object : Optional ["STACObject_Type" ]
70
+ _title : Optional [str ]
73
71
74
72
def __init__ (
75
73
self ,
@@ -103,6 +101,22 @@ def set_owner(self, owner: Optional["STACObject_Type"]) -> "Link":
103
101
self .owner = owner
104
102
return self
105
103
104
+ @property
105
+ def title (self ) -> Optional [str ]:
106
+ """Optional title for this link. If not provided during instantiation, this will
107
+ attempt to get the title from the STAC object that the link references."""
108
+ if self ._title is not None :
109
+ return self ._title
110
+ if self ._target_object is not None and isinstance (
111
+ self ._target_object , pystac .Catalog
112
+ ):
113
+ return self ._target_object .title
114
+ return None
115
+
116
+ @title .setter
117
+ def title (self , v : Optional [str ]) -> None :
118
+ self ._title = v
119
+
106
120
@property
107
121
def href (self ) -> str :
108
122
"""Returns the HREF for this link.
Original file line number Diff line number Diff line change @@ -130,6 +130,29 @@ def test_relative_self_href(self) -> None:
130
130
finally :
131
131
os .chdir (previous )
132
132
133
+ def test_auto_title_when_resolved (self ) -> None :
134
+ extent = pystac .Extent .from_items ([self .item ])
135
+ collection = pystac .Collection (
136
+ id = "my_collection" ,
137
+ description = "Test Collection" ,
138
+ extent = extent ,
139
+ title = "Collection Title" ,
140
+ )
141
+ link = pystac .Link ("my rel" , target = collection )
142
+
143
+ self .assertEqual (collection .title , link .title )
144
+
145
+ def test_auto_title_not_found (self ) -> None :
146
+ extent = pystac .Extent .from_items ([self .item ])
147
+ collection = pystac .Collection (
148
+ id = "my_collection" ,
149
+ description = "Test Collection" ,
150
+ extent = extent ,
151
+ )
152
+ link = pystac .Link ("my rel" , target = collection )
153
+
154
+ self .assertEqual (None , link .title )
155
+
133
156
134
157
class StaticLinkTest (unittest .TestCase ):
135
158
def setUp (self ) -> None :
You can’t perform that action at this time.
0 commit comments