Exemplo n.º 1
0
    def setUp(self):
        user_1 = StorageUser()
        user_1.email = '*****@*****.**'
        user_1.first_name = 'derek'
        user_1.last_name = 'shephard'
        user_1.set_password('password')
        user_1.save()
        self.user_1 = user_1

        user_2 = StorageUser()
        user_2.email = '*****@*****.**'
        user_2.first_name = 'richard'
        user_2.last_name = 'jones'
        user_2.set_password('password')
        user_2.save()
        self.user_2 = user_2

        folder_root_1 = Folder()
        folder_root_1.name = 'user_1_root'
        folder_root_1.owner = user_1
        folder_root_1.save()
        self.folder_root_1 = folder_root_1

        folder_1 = Folder()
        folder_1.name = 'test_folder_1'
        folder_1.parent = folder_root_1
        folder_1.owner = user_1
        folder_1.save()
        self.folder_1 = folder_1

        folder_2 = Folder()
        folder_2.name = 'test_folder_2'
        folder_2.owner = user_2
        folder_2.save()
        self.folder_2 = folder_2
Exemplo n.º 2
0
 def create(self, validated_data):
     """
     Create folder using validated data (validated by serializer)
     """
     folder = Folder()
     folder.name = validated_data['name']
     folder.parent = validated_data['parent']
     folder.owner = validated_data['user']
     folder.save()
     return folder
Exemplo n.º 3
0
    def test_put_folder_detail_success(self):
        # Create a new folder to act as a new parent for folder_1
        folder_3 = Folder()
        folder_3.name = 'test_folder_3'
        folder_3.parent = self.folder_root_1
        folder_3.owner = self.user_1
        folder_3.save()

        url = '/api/folders/{}/'.format(self.folder_1.id)
        self.client.force_authenticate(user=self.user_1)
        data = {'name': 'folder_1a', 'parent': folder_3.id}
        response = self.client.put(url, data, format='json')
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(
            Folder.objects.get(name='folder_1a').id, self.folder_1.id)