diff --git a/app/api/routes/resource_modification.py b/app/api/routes/resource_modification.py index 4e6205cf..7b82c418 100644 --- a/app/api/routes/resource_modification.py +++ b/app/api/routes/resource_modification.py @@ -45,7 +45,7 @@ def update_resource(id, json, db): try: logger.info( f"Updating resource. Old data: {json_module.dumps(resource.serialize)}") - if json.get('languages'): + if json.get('languages') is not None: resource.languages = langs index_object['languages'] = resource.serialize['languages'] if json.get('category'): diff --git a/tests/unit/test_routes/helpers.py b/tests/unit/test_routes/helpers.py index d3065ed7..ea6f5ea9 100644 --- a/tests/unit/test_routes/helpers.py +++ b/tests/unit/test_routes/helpers.py @@ -45,7 +45,7 @@ def update_resource(client, name="New name" if not name else name, url="https://new.url" if not url else url, category="New Category" if not category else category, - languages=["New language"] if not languages else languages, + languages=["New Lang"] if languages is None else languages, free=False if not free else free, notes="New notes" if not notes else notes), headers={'x-apikey': apikey} if not headers else headers) diff --git a/tests/unit/test_routes/test_resource_update.py b/tests/unit/test_routes/test_resource_update.py index be0708ae..96085a6e 100644 --- a/tests/unit/test_routes/test_resource_update.py +++ b/tests/unit/test_routes/test_resource_update.py @@ -240,6 +240,11 @@ def test_update_resource( notes) assert (response.status_code == 200) + # Empty languages list given removes all languages of resource + response = update_resource(client, apikey, languages=[]) + assert (response.status_code == 200) + assert (response.json['resource'].get('languages') == []) + # Resource not found response = client.put("/api/v1/resources/0", json=dict(name="New name"),