コード例 #1
0
class UploadedFileViewTests(TestCase):
    """
    Generic uploadedfile view tests' setup and tearDown.
    """
    def setUp(self):
        # avoid cluttered console output (for instance logging all the http requests)
        logging.disable(logging.WARNING)

        self.content_type = 'application/vnd.collection+json'
        self.chris_username = '******'
        self.chris_password = '******'
        self.username = '******'
        self.password = '******'
        self.other_username = '******'
        self.other_password = '******'

        # create the chris superuser and two additional users
        User.objects.create_user(username=self.chris_username,
                                 password=self.chris_password)
        User.objects.create_user(username=self.other_username,
                                 password=self.other_password)
        user = User.objects.create_user(username=self.username,
                                        password=self.password)

        # create a file in the DB "already uploaded" to the server)
        self.uploadedfile = UploadedFile(owner=user)
        self.uploadedfile.fname.name = '{}/uploads/file1.txt'.format(user)
        self.uploadedfile.save()

    def tearDown(self):
        # re-enable logging
        logging.disable(logging.NOTSET)
コード例 #2
0
 def create(self, validated_data):
     """
     Overriden to take care of the password hashing and create a welcome file
     for the user in its personal storage space.
     """
     username = validated_data.get('username')
     email = validated_data.get('email')
     password = validated_data.get('password')
     user = User.objects.create_user(username, email, password)
     swift_manager = SwiftManager(settings.SWIFT_CONTAINER_NAME,
                                  settings.SWIFT_CONNECTION_PARAMS)
     welcome_file_path = '%s/uploads/welcome.txt' % username
     try:
         with io.StringIO('Welcome to ChRIS!') as f:
             swift_manager.upload_obj(welcome_file_path,
                                      f.read(),
                                      content_type='text/plain')
         welcome_file = UploadedFile(owner=user)
         welcome_file.fname.name = welcome_file_path
         welcome_file.save()
     except Exception as e:
         logger.error(
             'Could not create welcome file in user space, detail: %s' %
             str(e))
     return user
コード例 #3
0
class UploadedFileViewTests(TestCase):
    """
    Generic uploadedfile view tests' setup and tearDown
    """

    def setUp(self):
        # avoid cluttered console output (for instance logging all the http requests)
        logging.disable(logging.CRITICAL)

        self.content_type = 'application/vnd.collection+json'
        self.chris_username = '******'
        self.chris_password = '******'
        self.username = '******'
        self.password = '******'
        self.other_username = '******'
        self.other_password = '******'

        # create the chris superuser and two additional users
        User.objects.create_user(username=self.chris_username,
                                 password=self.chris_password)
        User.objects.create_user(username=self.other_username,
                                 password=self.other_password)
        user = User.objects.create_user(username=self.username,
                                 password=self.password)

        # create a file in the DB "already uploaded" to the server)
        self.uploadedfile = UploadedFile(upload_path='/file1.txt', owner=user)
        self.uploadedfile.fname.name = 'test/uploads/file1.txt'
        self.uploadedfile.save()

    def tearDown(self):
        # re-enable logging
        logging.disable(logging.DEBUG)
コード例 #4
0
class UploadedFileViewTests(TestCase):
    """
    Generic uploadedfile view tests' setup and tearDown
    """
    def setUp(self):
        self.content_type = 'application/vnd.collection+json'

        self.chris_username = '******'
        self.chris_password = '******'
        self.username = '******'
        self.password = '******'
        self.other_username = '******'
        self.other_password = '******'

        # create the chris superuser and two additional users
        User.objects.create_user(username=self.chris_username,
                                 password=self.chris_password)
        User.objects.create_user(username=self.other_username,
                                 password=self.other_password)
        user = User.objects.create_user(username=self.username,
                                        password=self.password)

        # create a file in the DB "already uploaded" to the server)
        self.uploadedfile = UploadedFile(upload_path='/file1.txt', owner=user)
        self.uploadedfile.fname.name = 'test/uploads/file1.txt'
        self.uploadedfile.save()
コード例 #5
0
    def setUp(self):
        # avoid cluttered console output (for instance logging all the http requests)
        logging.disable(logging.WARNING)

        self.content_type = 'application/vnd.collection+json'
        self.chris_username = '******'
        self.chris_password = '******'
        self.username = '******'
        self.password = '******'
        self.other_username = '******'
        self.other_password = '******'

        # create the chris superuser and two additional users
        User.objects.create_user(username=self.chris_username,
                                 password=self.chris_password)
        User.objects.create_user(username=self.other_username,
                                 password=self.other_password)
        user = User.objects.create_user(username=self.username,
                                        password=self.password)

        # create a file in the DB "already uploaded" to the server)
        self.swift_manager = SwiftManager(settings.SWIFT_CONTAINER_NAME,
                                          settings.SWIFT_CONNECTION_PARAMS)
        # upload file to Swift storage
        self.upload_path = f'{self.username}/uploads/file1.txt'
        with io.StringIO("test file") as file1:
            self.swift_manager.upload_obj(self.upload_path,
                                          file1.read(),
                                          content_type='text/plain')
            self.uploadedfile = UploadedFile(owner=user)
            self.uploadedfile.fname.name = self.upload_path
            self.uploadedfile.save()
コード例 #6
0
    def setUp(self):
        super(FileBrowserPathListQuerySearchViewTests, self).setUp()

        # create a file in the DB "already uploaded" to the server)
        user = User.objects.get(username=self.username)
        upload_path = f'{self.username}/uploads/myfolder/file1.txt'
        uploadedfile = UploadedFile(owner=user)
        uploadedfile.fname.name = upload_path
        uploadedfile.save()
        self.read_url = reverse('filebrowserpath-list-query-search'
                                ) + f'?path={self.username}/uploads/'
コード例 #7
0
    def setUp(self):
        super(FileBrowserPathViewTests, self).setUp()

        # create a file in the DB "already uploaded" to the server)
        user = User.objects.get(username=self.username)
        upload_path = f'{self.username}/uploads/myfolder/file1.txt'
        uploadedfile = UploadedFile(owner=user)
        uploadedfile.fname.name = upload_path
        uploadedfile.save()

        self.read_url = reverse("filebrowserpath",
                                kwargs={"path": f'{self.username}/uploads'})
コード例 #8
0
    def setUp(self):
        super(FileBrowserPathFileListViewTests, self).setUp()

        # create a file in the DB "already uploaded" to the server)
        self.swift_manager = SwiftManager(settings.SWIFT_CONTAINER_NAME,
                                          settings.SWIFT_CONNECTION_PARAMS)

        # upload file to Swift storage
        self.upload_path = f'{self.username}/uploads/file2.txt'
        with io.StringIO("test file") as file1:
            self.swift_manager.upload_obj(self.upload_path,
                                          file1.read(),
                                          content_type='text/plain')
        user = User.objects.get(username=self.username)
        uploadedfile = UploadedFile(owner=user)
        uploadedfile.fname.name = self.upload_path
        uploadedfile.save()

        self.read_url = reverse("filebrowserpathfile-list",
                                kwargs={"path": f'{self.username}/uploads'})
コード例 #9
0
    def setUp(self):
        # avoid cluttered console output (for instance logging all the http requests)
        logging.disable(logging.CRITICAL)

        self.content_type = 'application/vnd.collection+json'
        self.chris_username = '******'
        self.chris_password = '******'
        self.username = '******'
        self.password = '******'
        self.other_username = '******'
        self.other_password = '******'

        # create the chris superuser and two additional users
        User.objects.create_user(username=self.chris_username,
                                 password=self.chris_password)
        User.objects.create_user(username=self.other_username,
                                 password=self.other_password)
        user = User.objects.create_user(username=self.username,
                                 password=self.password)

        # create a file in the DB "already uploaded" to the server)
        self.uploadedfile = UploadedFile(upload_path='/file1.txt', owner=user)
        self.uploadedfile.fname.name = 'test/uploads/file1.txt'
        self.uploadedfile.save()
コード例 #10
0
 def test_str(self):
     uploadedfile_mock = mock.MagicMock(spec=UploadedFile)
     uploadedfile_mock.upload_path = '/myuploads'
     self.assertEqual(UploadedFile.__str__(uploadedfile_mock), '/myuploads')
コード例 #11
0
 def test_str(self):
     uploadedfile_mock = mock.MagicMock(spec=UploadedFile)
     uploadedfile_mock.upload_path = '/myuploads'
     self.assertEqual(UploadedFile.__str__(uploadedfile_mock), '/myuploads')
コード例 #12
0
 def test_str(self):
     uploadedfile_mock = mock.MagicMock(spec=UploadedFile)
     uploadedfile_mock.fname.name = 'foo/uploads/myuploads'
     self.assertEqual(UploadedFile.__str__(uploadedfile_mock),
                      'foo/uploads/myuploads')