|  | 
| 4 | 4 | 
 | 
| 5 | 5 | import pytest | 
| 6 | 6 | from pyld import jsonld | 
|  | 7 | +from pydantic import ValidationError | 
| 7 | 8 | 
 | 
| 8 | 9 | from ...jsonldutils import load_file | 
| 9 | 10 | from ...utils import start_server, stop_server | 
| @@ -176,3 +177,88 @@ def test_item(tmp_path, server_http_kwargs): | 
| 176 | 177 |     ) | 
| 177 | 178 |     del data_comp["@context"] | 
| 178 | 179 |     assert item_dict == data_comp | 
|  | 180 | + | 
|  | 181 | + | 
|  | 182 | +def test_canvas_activity_allows_extra_fields(): | 
|  | 183 | +    """Test that canvas activities allow backgroundImage (now an explicit field).""" | 
|  | 184 | +    activity_dict = { | 
|  | 185 | +        "category": "Activity", | 
|  | 186 | +        "id": "canvas_activity.jsonld", | 
|  | 187 | +        "prefLabel": {"en": "Canvas Drawing Activity"}, | 
|  | 188 | +        "description": {"en": "A canvas drawing activity"}, | 
|  | 189 | +        "schemaVersion": "1.0.0-rc4", | 
|  | 190 | +        "version": "0.0.1", | 
|  | 191 | +        "ui": { | 
|  | 192 | +            "inputType": "canvas", | 
|  | 193 | +            "addProperties": [ | 
|  | 194 | +                { | 
|  | 195 | +                    "isAbout": "item1", | 
|  | 196 | +                    "variableName": "canvas_item", | 
|  | 197 | +                    "backgroundImage": "./images/drawaclock.png", | 
|  | 198 | +                } | 
|  | 199 | +            ], | 
|  | 200 | +        }, | 
|  | 201 | +    } | 
|  | 202 | + | 
|  | 203 | +    # This should work fine | 
|  | 204 | +    activity_obj = Activity(**activity_dict) | 
|  | 205 | +    assert ( | 
|  | 206 | +        activity_obj.ui.addProperties[0].backgroundImage | 
|  | 207 | +        == "./images/drawaclock.png" | 
|  | 208 | +    ) | 
|  | 209 | + | 
|  | 210 | + | 
|  | 211 | +def test_background_image_always_allowed(): | 
|  | 212 | +    """Test that backgroundImage is always allowed regardless of inputType.""" | 
|  | 213 | +    activity_dict = { | 
|  | 214 | +        "category": "Activity", | 
|  | 215 | +        "id": "radio_activity_with_background.jsonld", | 
|  | 216 | +        "prefLabel": {"en": "Radio Button Activity with Background"}, | 
|  | 217 | +        "description": {"en": "A radio button activity with background image"}, | 
|  | 218 | +        "schemaVersion": "1.0.0-rc4", | 
|  | 219 | +        "version": "0.0.1", | 
|  | 220 | +        "ui": { | 
|  | 221 | +            "inputType": "radio", | 
|  | 222 | +            "addProperties": [ | 
|  | 223 | +                { | 
|  | 224 | +                    "isAbout": "item1", | 
|  | 225 | +                    "variableName": "radio_item", | 
|  | 226 | +                    # backgroundImage should be allowed for all activities | 
|  | 227 | +                    "backgroundImage": "./images/some_image.png", | 
|  | 228 | +                } | 
|  | 229 | +            ], | 
|  | 230 | +        }, | 
|  | 231 | +    } | 
|  | 232 | + | 
|  | 233 | +    # This should work fine - backgroundImage is now an explicit field | 
|  | 234 | +    activity_obj = Activity(**activity_dict) | 
|  | 235 | +    assert ( | 
|  | 236 | +        activity_obj.ui.addProperties[0].backgroundImage | 
|  | 237 | +        == "./images/some_image.png" | 
|  | 238 | +    ) | 
|  | 239 | + | 
|  | 240 | + | 
|  | 241 | +def test_activity_without_extra_fields_works(): | 
|  | 242 | +    """Test that activities without extra fields work normally regardless of input type.""" | 
|  | 243 | +    activity_dict = { | 
|  | 244 | +        "category": "Activity", | 
|  | 245 | +        "id": "normal_activity.jsonld", | 
|  | 246 | +        "prefLabel": {"en": "Normal Activity"}, | 
|  | 247 | +        "description": {"en": "A normal activity without extra fields"}, | 
|  | 248 | +        "schemaVersion": "1.0.0-rc4", | 
|  | 249 | +        "version": "0.0.1", | 
|  | 250 | +        "ui": { | 
|  | 251 | +            "inputType": "radio", | 
|  | 252 | +            "addProperties": [ | 
|  | 253 | +                { | 
|  | 254 | +                    "isAbout": "item1", | 
|  | 255 | +                    "variableName": "normal_item", | 
|  | 256 | +                    # No extra fields | 
|  | 257 | +                } | 
|  | 258 | +            ], | 
|  | 259 | +        }, | 
|  | 260 | +    } | 
|  | 261 | + | 
|  | 262 | +    # This should work fine | 
|  | 263 | +    activity_obj = Activity(**activity_dict) | 
|  | 264 | +    assert activity_obj.ui.addProperties[0].variableName == "normal_item" | 
0 commit comments