コード例 #1
0
ファイル: test_resource.py プロジェクト: dante087/django-s3
 def test_get_public_url(self, settings, resource):
     # Create a resource for each resource type and test for the correct url.
     resource_name_template = "{}001-B0001_320x320.SVG"
     for code, category in settings.S3_CATEGORY_MAP.items():
         res = Resource(resource_name_template.format(code))
         assert res.public_url == \
                settings.S3_AWS_BASE_PUBLIC_URL + settings.S3_BUCKET_NAME + '/' + category + \
                '/{}/'.format(res.folder_name) + res.name
コード例 #2
0
ファイル: test_resource.py プロジェクト: dante087/django-s3
 def test_get_url(self, settings, resource):
     # Create a resource for each resource type and test for the correct url.
     resource_name_template = "{}001-B0001_320x320.SVG"
     for code, category in settings.S3_CATEGORY_MAP.items():
         res = Resource(resource_name_template.format(code))
         folder_name = url_pattern.match(res.name).groupdict()['folder_name']
         assert res.url == \
                settings.S3_AWS_BASE_URL + settings.S3_BUCKET_NAME + '/' + category + \
                '/{}/'.format(res.folder_name) + res.name
コード例 #3
0
ファイル: test_resource.py プロジェクト: dante087/django-s3
    def test_folder_name(self, settings, resource):
        names_results = {
            "F001-1_WHITE_70x70.JPG": "F001-1"
        }

        for name, result in names_results.items():

            resource = Resource(name)
            match = url_pattern.match(name)
            assert resource.folder_name == result, 'The name must be extracted correctly.'
コード例 #4
0
    def download_by_name(self, name):
        """
        
        :param name: Name for the resource to download. 
        :return: A 2-tuple object containing a resource and the final path of the resource.
        """

        resource = Resource(name)
        filename = self.download(resource)

        return resource, filename
コード例 #5
0
 def test_get_category_code(self, settings, resource):
     samples = [('B0001_DEFAULT.JPG', 'B'),
                ('F0001_WHITE_DEFAULT.JPG', 'F'),
                ('F2344-B0001_DEFAULT.JPG', 'F'),
                ('CF0001_WHITE_DEFAULT.JPG', 'CF'),
                ('WF0001_WHITE_DEFAULT.JPG', 'WF'),
                ('CR01-047_B0001_320x320.JPG', 'CR'),
                ('PP0001_00000_0000.jpg', 'PP'),
                ('CM991992_0000_000.png', 'CM')]
     for file_name, expected_code in samples:
         res = Resource(file_name)
         assert res.category_code == expected_code, \
             _("Expected category {} for the resource with name {}, see the settings "
               "configuration: S3_CATEGORY_MAP.".format(expected_code, file_name))
コード例 #6
0
 def test_get_category(self, settings, resource):
     samples = [('B0001_DEFAULT.JPG', 'BACKGROUND'),
                ('F0001_WHITE_DEFAULT.JPG', 'VASE'),
                ('F2344-B0001_DEFAULT.JPG', 'VASE'),
                ('CF0001_WHITE_DEFAULT.JPG', 'CLIPPING-FLOWER'),
                ('WF0001_WHITE_DEFAULT.JPG', 'WRAPPING-FLOWER'),
                ('CR01-047_B0001_320x320.JPG', 'CATALOGUE-PRODUCT'),
                ('PP0001_00000_0000.jpg', 'PERSONALIZED-PRODUCT'),
                ('CM991992_0000_000.png', 'COMPOSITION')]
     for file_name, expected_category in samples:
         res = Resource(file_name)
         assert res.category == expected_category, \
             _("Expected category {} for the resource with name {}, see the settings "
               "configuration: S3_CATEGORY_MAP.".format(expected_category, file_name))
コード例 #7
0
 def test_creation_wrong_names(self, settings, resource):
     wrong_names = [
         '03323_12331-230x234.jgp',  # Starting with a number.
         ' 03323_12331-230x234.jgp',  # Starting with a space.
         '_3323_12331-230x234.jgp',  # Starting with a special character.
         'FFFF033_2312331-230x234.jgp',  # Starting with mora than 2 letters.
         'FF0332312331-230x234.jgp',  # Starting with mora than 2 letters.
         'fF0332312331-230x234.jgp',  # Missing '_' with a small letter.
         'FF03323_123:31-230x234.jgp',  # Containing spacial character in the middle.
         'FF3323_123\31-230x234.jgp',  # Containing spacial character in the middle (2).
     ]
     for sample in wrong_names:
         with pytest.raises(ResourceNameError):
             res = Resource(sample)
コード例 #8
0
ファイル: test_resource.py プロジェクト: dante087/django-s3
 def test_get_size(self, settings, resource):
     resource_name_without_size = 'B0001_DEFAULT.JPG'
     resource = Resource(resource_name_without_size)
     with pytest.raises(ResourceSizeError) as exceinfo:
         size = resource.size()
コード例 #9
0
ファイル: conftest.py プロジェクト: nilbert/django-s3
def resource():
    return Resource('F0001-B0001_320x320.SVG')