def test_load_licenses_update(factories): license = models.License.objects.create( code="dummy", url="http://oldurl", redistribute=True, derivative=True, commercial=True, attribution=True, copyleft=True, ) license_data = { "code": "dummy", "url": "http://newurl", "redistribute": False, "derivative": False, "commercial": True, "attribution": True, "copyleft": True, } licenses.load([license_data]) license.refresh_from_db() assert license.url == license_data["url"] assert license.derivative == license_data["derivative"] assert license.copyleft == license_data["copyleft"] assert license.commercial == license_data["commercial"] assert license.attribution == license_data["attribution"]
def test_load_skip_update_if_no_change(factories, mocker): license = models.License.objects.create( code="dummy", url="http://oldurl", redistribute=True, derivative=True, commercial=True, attribution=True, copyleft=True, ) update_or_create = mocker.patch.object(models.License.objects, "update_or_create") save = mocker.patch.object(models.License, "save") # we load licenses but with same data licenses.load([{ "code": "dummy", "url": license.url, "derivative": license.derivative, "redistribute": license.redistribute, "commercial": license.commercial, "attribution": license.attribution, "copyleft": license.copyleft, }]) save.assert_not_called() update_or_create.assert_not_called()
def test_track_null_license_mutation(factories, now): track = factories["music.Track"](license="cc-by-sa-4.0") mutation = factories["common.Mutation"](type="update", target=track, payload={ "license": None }) licenses.load(licenses.LICENSES) mutation.apply() track.refresh_from_db() assert track.license is None
def test_upload_import_metadata_serializer_full(): licenses.load(licenses.LICENSES) data = { "title": "hello", "mbid": "3220fd02-5237-4952-8394-b7e64b0204a6", "tags": ["politics", "gender"], "license": "cc-by-sa-4.0", "copyright": "My work", "position": 42, } expected = data.copy() expected["license"] = models.License.objects.get(code=data["license"]) expected["mbid"] = uuid.UUID(data["mbid"]) serializer = serializers.ImportMetadataSerializer(data=data) assert serializer.is_valid(raise_exception=True) is True assert serializer.validated_data == expected
def test_load_licenses_create(db): license_data = { "code": "dummy", "url": "http://dummy", "redistribute": True, "derivative": True, "commercial": True, "attribution": True, "copyleft": True, } licenses.load([license_data]) license = models.License.objects.get(pk=license_data["code"]) assert license.url == license_data["url"] assert license.redistribute == license_data["redistribute"] assert license.derivative == license_data["derivative"] assert license.copyleft == license_data["copyleft"] assert license.commercial == license_data["commercial"] assert license.attribution == license_data["attribution"]
def test_mutations_route_create_success(factories, api_request, is_approved, mocker): licenses.load(licenses.LICENSES) on_commit = mocker.patch("funkwhale_api.common.utils.on_commit") user = factories["users.User"](permission_library=True) actor = user.create_actor() track = factories["music.Track"](title="foo", local=True) view = V.as_view({"post": "mutations"}) request = api_request.post( "/", { "type": "update", "payload": {"title": "bar", "unknown": "test", "license": "cc-by-nc-4.0"}, "summary": "hello", "is_approved": is_approved, }, format="json", ) setattr(request, "user", user) setattr(request, "session", {}) response = view(request, pk=track.pk) assert response.status_code == 201 mutation = models.Mutation.objects.get_for_target(track).latest("id") assert mutation.type == "update" assert mutation.payload == {"title": "bar", "license": "cc-by-nc-4.0"} assert mutation.created_by == actor assert mutation.is_approved is is_approved assert mutation.is_applied is None assert mutation.target == track assert mutation.summary == "hello" if is_approved: on_commit.assert_any_call(tasks.apply_mutation.delay, mutation_id=mutation.pk) expected = serializers.APIMutationSerializer(mutation).data assert response.data == expected on_commit.assert_any_call( signals.mutation_created.send, mutation=mutation, sender=None )
def test_load_hardcoded_licenses_works(db): licenses.load(licenses.LICENSES)