Commit bed35493 authored by Mickaël Desfrênes's avatar Mickaël Desfrênes
Browse files

add rpc.replace_file test

parent b13caffd
Loading
Loading
Loading
Loading
+587 KiB
Loading image diff...
+464 KiB
Loading image diff...
+163 KiB
Loading image diff...
+24 −0
Original line number Diff line number Diff line
@@ -4,6 +4,8 @@ from resources import models
from django.contrib.auth.models import User
from resources.management.commands.loadfixtures import load_fixtures
from rpc.methods import ServiceException
from pathlib import Path
import os


class ServiceTestCase(TestCase):
@@ -294,3 +296,25 @@ class ServiceTestCase(TestCase):
            owner=self.test_user, description="test description 2"
        )
        self.assertEqual(models.UserTask.objects.count(), 2)

    def test_replace_file(self):
        from resources.helpers import handle_local_file

        self.assertTrue(
            models.Resource.objects.filter(deleted_at__isnull=True).count() == 0
        )
        id1 = handle_local_file(
            Path(os.path.dirname(__file__), "test_assets", "cat_1.png"),
            self.test_project,
        )
        id2 = handle_local_file(
            Path(os.path.dirname(__file__), "test_assets", "cat_2.png"),
            self.test_project,
        )
        self.assertTrue(
            models.Resource.objects.filter(deleted_at__isnull=True).count() == 2
        )
        methods.replace_file(self.test_user, id1, id2)
        self.assertTrue(
            models.Resource.objects.filter(deleted_at__isnull=True).count() == 1
        )