def test_civ_value_to_file(): civ = ComponentInterfaceValueFactory(value={"foo": 1, "bar": None}) civ_value_to_file(civ_pk=civ.pk) civ.refresh_from_db() with civ.file.open("r") as f: v = json.loads(f.read()) assert v == {"foo": 1, "bar": None} assert civ.value is None # Check idempotency with pytest.raises(RuntimeError): civ_value_to_file(civ_pk=civ.pk)
def test_add_images_to_component_interface_value(): # Override the celery settings us = RawImageUploadSessionFactory() ImageFactory(origin=us), ImageFactory(origin=us) ci = ComponentInterface.objects.get(slug=DEFAULT_INPUT_INTERFACE_SLUG) civ = ComponentInterfaceValueFactory(interface=ci) with pytest.raises(ValueError) as err: add_images_to_component_interface_value( component_interface_value_pk=civ.pk, upload_pk=us.pk) assert "Image imports should result in a single image" in str(err) assert civ.image is None us2 = RawImageUploadSessionFactory() image = ImageFactory(origin=us2) civ2 = ComponentInterfaceValueFactory(interface=ci) add_images_to_component_interface_value( component_interface_value_pk=civ2.pk, upload_pk=us2.pk) civ2.refresh_from_db() assert civ2.image == image