Beispiel #1
0
    def test_upload(self):
        client = Client()
        secret_obj = Secret.objects.get(pk=1)
        secret = secret_obj.value
        api_key = secret_obj.application.api_key
        user_id = secret_obj.user.pk

        workspace_id = 1
        workspace = Workspace.objects.get(pk=workspace_id)
        metadata_dict = {
            'namespace': 'dc',
            'name': 'title',
            'value': 'test',
            'lang': 'en'
        }
        params = {'workspace_id': workspace_id, 'media_type': 'image/jpeg'}

        params = _get_final_parameters(api_key=api_key,
                                       secret=secret,
                                       user_id=user_id,
                                       kwargs=params)

        response = client.post(
            '/api/item/new/',
            params,
        )
        resp_dict = simplejson.loads(response.content)
        print 'so far so good! resp_dict is ', resp_dict
        item = Item.objects.get(pk=resp_dict['id'])

        file = open(file_path)
        rendition_id = 1
        params = _get_final_parameters(api_key=api_key,
                                       secret=secret,
                                       user_id=user_id,
                                       kwargs={
                                           'workspace_id': workspace_id,
                                           'rendition_id': rendition_id
                                       })
        params['files_to_upload'] = file

        response = client.post(
            '/api/item/%s/upload/' % item.pk,
            params,
        )
        print 'response after upload is:', response

        file.close()
        hash_source = md5(file_path)

        self.assertTrue(response.content == '')

        component = Variant.objects.get(pk=rendition_id).get_component(
            workspace, item)

        hash_uploaded = md5(component.get_file_path())
        print 'component.get_file_path() ', component.get_file_path()

        self.assertTrue(hash_uploaded == hash_source)
Beispiel #2
0
    def test_upload(self):
        client = Client()
        secret_obj = Secret.objects.get(pk=1)
        secret = secret_obj.value
        api_key = secret_obj.application.api_key
        user_id = secret_obj.user.pk

        workspace_id = 1
        workspace = Workspace.objects.get(pk=workspace_id)
        metadata_dict = {"namespace": "dc", "name": "title", "value": "test", "lang": "en"}
        params = {"workspace_id": workspace_id, "media_type": "image/jpeg"}

        params = _get_final_parameters(api_key=api_key, secret=secret, user_id=user_id, kwargs=params)

        response = client.post("/api/item/new/", params)
        resp_dict = simplejson.loads(response.content)
        print "so far so good! resp_dict is ", resp_dict
        item = Item.objects.get(pk=resp_dict["id"])

        file = open(file_path)
        rendition_id = 1
        params = _get_final_parameters(
            api_key=api_key,
            secret=secret,
            user_id=user_id,
            kwargs={"workspace_id": workspace_id, "rendition_id": rendition_id},
        )
        params["files_to_upload"] = file

        response = client.post("/api/item/%s/upload/" % item.pk, params)
        print "response after upload is:", response

        file.close()
        hash_source = md5(file_path)

        self.assertTrue(response.content == "")

        component = Variant.objects.get(pk=rendition_id).get_component(workspace, item)

        hash_uploaded = md5(component.get_file_path())
        print "component.get_file_path() ", component.get_file_path()

        self.assertTrue(hash_uploaded == hash_source)
Beispiel #3
0
    def test_upload(self):
        client = Client()
        secret_obj = Secret.objects.get(pk = 1)  
        secret = secret_obj.value
        api_key = secret_obj.application.api_key
        user_id = secret_obj.user.pk
        
        workspace_id = 1
        workspace = Workspace.objects.get(pk = workspace_id)
        metadata_dict = {'namespace':'dc',  'name':'title',  'value': 'test',  'lang': 'en'}
        params = {'workspace_id':workspace_id, 'media_type': 'image/jpeg' }

        params = _get_final_parameters(api_key = api_key, secret = secret, user_id = user_id, kwargs = params)                
        
        response = client.post('/api/item/new/', params,)                
        resp_dict = simplejson.loads(response.content)
        print 'so far so good! resp_dict is ', resp_dict
        item = Item.objects.get(pk = resp_dict['id'])

        file = open(file_path)
        rendition_id = 1
        params = _get_final_parameters(api_key = api_key, secret = secret, user_id = user_id, kwargs = {'workspace_id': workspace_id,  'rendition_id':rendition_id})                
        params['files_to_upload'] = file
        
        
        response = client.post('/api/item/%s/upload/'%item.pk, params, )            
        print 'response after upload is:', response
        
       
        
        file.close()
        hash_source = md5(file_path)
       
        self.assertTrue(response.content == '')        
        
        component = Variant.objects.get(pk = rendition_id).get_component(workspace,  item)
        
        hash_uploaded = md5(component.get_file_path())
        print 'component.get_file_path() ', component.get_file_path()
        
        self.assertTrue(hash_uploaded == hash_source)
 def get_final_parameters(self, kwargs=None):
     "add api_key user_id and secret (required by check sum)"
     return _get_final_parameters(self.api_key, self.secret, self.user_id,
                                  kwargs)
Beispiel #5
0
TOTAL = 1

if __name__ == "__main__":
    client = Client()
    secret_obj = Secret.objects.get(pk=1)
    secret = secret_obj.value
    api_key = secret_obj.application.api_key
    user_id = secret_obj.user.pk

    #metadata_dict = {'namespace':'dc',  'name':'title',  'value': 'test',  'lang': 'en', }
    workspace_id = 1
    workspace = Workspace.objects.get(pk=workspace_id)
    print 'workspace is: ', workspace
    params_a = {'workspace_id': workspace_id, 'media_type': 'image/jpeg'}
    params_a = _get_final_parameters(api_key=api_key,
                                     secret=secret,
                                     user_id=user_id,
                                     kwargs=params_a)
    file = open(INPUT_FILE)
    for i in range(TOTAL):

        print "\n************* START ***************\n"
        print('\n\n**** i = %d **** \n' % i)
        item_id = 'ITEM_' + str(i).zfill(10)
        print 'item_id = ', item_id
        try:
            response = client.post(
                '/api/item/new/',
                params_a,
            )
        except Exception, err:
            print 'error in client post item new: ', err
Beispiel #6
0
 def get_final_parameters(self, kwargs = None):
     "add api_key user_id and secret (required by check sum)"
     return _get_final_parameters(self.api_key, self.secret, self.user_id, kwargs)
TOTAL = 1


if __name__ == "__main__":
    client = Client()
    secret_obj = Secret.objects.get(pk = 1)  
    secret = secret_obj.value
    api_key = secret_obj.application.api_key
    user_id = secret_obj.user.pk
    
    #metadata_dict = {'namespace':'dc',  'name':'title',  'value': 'test',  'lang': 'en', }
    workspace_id = 1
    workspace = Workspace.objects.get(pk = workspace_id) 
    print 'workspace is: ', workspace
    params_a = {'workspace_id':workspace_id, 'media_type': 'image/jpeg' }
    params_a = _get_final_parameters(api_key = api_key, secret = secret, user_id = user_id, kwargs = params_a)                
    file = open(INPUT_FILE)
    for i in range(TOTAL):
        
        print "\n************* START ***************\n"
        print ('\n\n**** i = %d **** \n' % i)
        item_id = 'ITEM_' + str(i).zfill(10)
        print 'item_id = ', item_id
        try:
            response = client.post('/api/item/new/', params_a,)                
        except Exception, err:
            print 'error in client post item new: ', err
        resp_dict = simplejson.loads(response.content)
        print '\n====> resp_dict: ', resp_dict
        item = Item.objects.get(pk=resp_dict['id'])
        print 'item id is: ', item.pk
Beispiel #8
0
 if len(sys.argv) == 1:
     print 'I need a root directory as input'
     sys.exit(0)
 else:
     my_root_dir = sys.argv[1]
     print 'starting from directory ', my_root_dir
 client = Client()
 secret_obj = Secret.objects.get(pk = 1)  
 secret = secret_obj.value
 api_key = secret_obj.application.api_key
 user_id = secret_obj.user.pk
 
 #metadata_dict = {'namespace':'dc',  'name':'title',  'value': 'test',  'lang': 'en', }
 workspace = Workspace.objects.get(name = WORKSPACE_NAME) 
 params_a = {'workspace_id':workspace.pk, 'media_type': MEDIA_TYPE}
 params_a = _get_final_parameters(api_key = api_key, secret = secret, user_id = user_id, kwargs = params_a)                
 allimages = []
 subfiles = []
 badfiles = []
 current_keyword = ''
 keywords_list_history = {}
 keywords_list = []
 for (path,dirs,files) in os.walk(my_root_dir):
     print 'path: ', path
     print 'dirs: ', dirs
     print 'files: ', files
     print 'basename of path: ', os.path.basename(path)
     if os.path.basename(path) != current_keyword:
         current_keyword = os.path.basename(path)
         all_ks = path.split('/')
         print 'list of keywords for each file in files is: ', all_ks
Beispiel #9
0
        print 'I need a root directory as input'
        sys.exit(0)
    else:
        my_root_dir = sys.argv[1]
        print 'starting from directory ', my_root_dir
    client = Client()
    secret_obj = Secret.objects.get(pk=1)
    secret = secret_obj.value
    api_key = secret_obj.application.api_key
    user_id = secret_obj.user.pk

    #metadata_dict = {'namespace':'dc',  'name':'title',  'value': 'test',  'lang': 'en', }
    workspace = Workspace.objects.get(name=WORKSPACE_NAME)
    params_a = {'workspace_id': workspace.pk, 'media_type': MEDIA_TYPE}
    params_a = _get_final_parameters(api_key=api_key,
                                     secret=secret,
                                     user_id=user_id,
                                     kwargs=params_a)
    allimages = []
    subfiles = []
    badfiles = []
    current_keyword = ''
    keywords_list_history = {}
    keywords_list = []
    for (path, dirs, files) in os.walk(my_root_dir):
        print 'path: ', path
        print 'dirs: ', dirs
        print 'files: ', files
        print 'basename of path: ', os.path.basename(path)
        if os.path.basename(path) != current_keyword:
            current_keyword = os.path.basename(path)
            all_ks = path.split('/')