def get_property_image_file_url(file_oid, org_file_name, cache_file_name,
                                    water_mark, max_size):
        """ 建物、部屋の画像のURLの取得 """

        CacheFileHelper.__prepare_cache_dir()
        cache_path = os.path.join(settings.CACHE_FILE_DIR, 'buildings',
                                  file_oid)
        cache_path = re.sub(r'\.+' + repr(os.sep), '', cache_path)
        cache_url = urljoin(settings.CACHE_FILE_URL,
                            "./buildings/" + file_oid + "/")
        if not os.path.isdir(cache_path):
            os.makedirs(cache_path)

        cache_file_url = None
        org_file_path = os.path.join(settings.ORIGINAL_FILE_DIR, 'buildings',
                                     file_oid, 'pictures', org_file_name)
        org_file_path = re.sub(r'\.+' + repr(os.sep), '', org_file_path)
        if os.path.isfile(org_file_path):
            cache_file_path = os.path.join(cache_path, cache_file_name)
            cache_file_path = re.sub(r'\.+' + repr(os.sep), '',
                                     cache_file_path)
            cache_file_url = urljoin(cache_url, cache_file_name)
            if not os.path.isfile(cache_file_path):
                ImageHelper.cache_image(org_file_path, cache_file_path,
                                        water_mark, max_size)

        return urljoin(settings.BASE_URL, cache_file_url)
 def test_cache_image(self):
     src_path = os.path.join(settings.MEDIA_ROOT, 'test_data',
                             'sample_picture.jpg')
     cache_test_dir = os.path.join(settings.CACHE_FILE_DIR, 'test_data')
     os.makedirs(cache_test_dir)
     cache_path = os.path.join(cache_test_dir, 'cache_test_picture.jpg')
     ImageHelper.cache_image(src_path, cache_path, 'YWorks',
                             settings.MEDIUM_IMAGE_SIZE)
     self.assertTrue(os.path.exists(cache_path))
     shutil.rmtree(cache_test_dir)