Ejemplo n.º 1
0
 def test_upload_image_wrong_image_format(self):
     with safe_change_dju_settings():
         dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG',)
         clear_profile_configs_cache()
         f = get_img_file(create_test_image(1000, 1000))
         r = self.client.post(self.upload_url, {'images[]': [f]})
         self.assertEqual(r.status_code, 200)
         d = self.get_json(r)
         self.assertEqual(len(d['uploaded']), 0)
         self.assertEqual(len(d['errors']), 1)
         self.assertEqual(
             d['errors'][0],
             unicode(VIEWS_ERRORS['wrong_file_format']) % {
                 'name': 'images[]',
                 'formats': ', '.join(map(lambda t: t.upper(), dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES']))
             }
         )
Ejemplo n.º 2
0
def safe_change_dju_settings():
    """
    with safe_change_dju_settings():
        dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG',)
        ...
    # dju settings will be restored
    ...
    """
    settings_bak = {}
    for k, v in dju_settings.__dict__.iteritems():
        if k[:4] == 'DJU_':
            settings_bak[k] = copy.deepcopy(v)
    try:
        yield
    finally:
        for k, v in settings_bak.iteritems():
            setattr(dju_settings, k, v)
        clear_profile_configs_cache()
Ejemplo n.º 3
0
def safe_change_dju_settings():
    """
    with safe_change_dju_settings():
        dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG',)
        ...
    # dju settings will be restored
    ...
    """
    settings_bak = {}
    for k, v in dju_settings.__dict__.iteritems():
        if k[:4] == 'DJU_':
            settings_bak[k] = copy.deepcopy(v)
    try:
        yield
    finally:
        for k, v in settings_bak.iteritems():
            setattr(dju_settings, k, v)
        clear_profile_configs_cache()
Ejemplo n.º 4
0
 def test_upload_image_wrong_image_format(self):
     with safe_change_dju_settings():
         dju_settings.DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES'] = ('PNG', )
         clear_profile_configs_cache()
         f = get_img_file(create_test_image(1000, 1000))
         r = self.client.post(self.upload_url, {'images[]': [f]})
         self.assertEqual(r.status_code, 200)
         d = self.get_json(r)
         self.assertEqual(len(d['uploaded']), 0)
         self.assertEqual(len(d['errors']), 1)
         self.assertEqual(
             d['errors'][0],
             unicode(VIEWS_ERRORS['wrong_file_format']) % {
                 'name':
                 'images[]',
                 'formats':
                 ', '.join(
                     map(
                         lambda t: t.upper(), dju_settings.
                         DJU_IMG_UPLOAD_PROFILE_DEFAULT['TYPES']))
             })