Exemplo n.º 1
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.username = '******'
        self.password = '******'

        User.objects.create_user(username=self.username,
                                 password=self.password)

        service = Service(identifier='MyService')
        service.save()

        # create a service file in the DB "already registered" to the server)
        self.swift_manager = SwiftManager(settings.SWIFT_CONTAINER_NAME,
                                          settings.SWIFT_CONNECTION_PARAMS)
        # upload file to Swift storage
        self.path = 'SERVICES/MyService/123456-crazy/brain_crazy_study/brain_crazy_mri/file1.dcm'
        with io.StringIO("test file") as file1:
            self.swift_manager.upload_obj(self.path,
                                          file1.read(),
                                          content_type='text/plain')
        service_file = ServiceFile(service=service)
        service_file.fname.name = self.path
        service_file.save()
Exemplo n.º 2
0
 def test_servicefile_create_failure_already_exists(self):
     chris_username = '******'
     chris_password = '******'
     User.objects.create_user(username=chris_username, password=chris_password)
     self.client.login(username=chris_username, password=chris_password)
     path = 'SERVICES/MyService/123456-crazy/brain_crazy_study/brain_crazy_mri/file2.dcm'
     service = Service.objects.get(identifier='MyService')
     service_file = ServiceFile(service=service)
     service_file.fname.name = path
     service_file.save()
     response = self.client.post(self.create_read_url, data=self.post,
                                 content_type=self.content_type)
     self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
 def test_validate_validates_path_has_not_already_been_registered(self):
     """
     Test whether overriden validate method validates that the submitted path
     has not been already registered.
     """
     path = 'SERVICES/MyService/123456-crazy/brain_crazy_study/brain_crazy_mri/file1.dcm'
     data = {'service_name': 'MyService', 'path': path}
     servicefiles_serializer = ServiceFileSerializer()
     service = Service(identifier='MyService')
     service.save()
     service_file = ServiceFile(service=service)
     service_file.fname.name = path
     service_file.save()
     with self.assertRaises(serializers.ValidationError):
         servicefiles_serializer.validate(data)
Exemplo n.º 4
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.username = '******'
        self.password = '******'

        User.objects.create_user(username=self.username, password=self.password)

        # create a pacs file in the DB "already registered" to the server)
        service = Service(identifier='MyService')
        service.save()

        self.path = 'SERVICES/MyService/123456-crazy/brain_crazy_study/brain_crazy_mri/file1.dcm'
        service_file = ServiceFile(service=service)
        service_file.fname.name = self.path
        service_file.save()
Exemplo n.º 5
0
    def test_get_path_folders(self):
        """
        Test whether services.get_path_folders function appends a collection+json
        template to its response argument
        """
        username = self.username

        path = f'{username}'
        folders = services.get_path_folders(path, username)
        self.assertIn('uploads', folders)

        path = 'SERVICES'
        # create a service's files in the DB
        service = Service(identifier='lolo')
        service.save()
        f1 = ServiceFile(service=service)
        f1.fname.name = 'SERVICES/lolo/lele/a.txt'
        f1.save()
        f2 = ServiceFile(service=service)
        f2.fname.name = 'SERVICES/lolo/b.txt'
        f2.save()
        f3 = ServiceFile(service=service)
        f3.fname.name = 'SERVICES/lili/c.txt'
        f3.save()
        folders = services.get_path_folders(path, username)
        self.assertEqual(sorted(folders), ['PACS', 'lili', 'lolo'])