@@ 2011-2068 (lines=58) @@ | ||
2008 | assert dim['width'] == 256 |
|
2009 | assert dim['height'] == 256 |
|
2010 | ||
2011 | def test_api__get_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
2012 | """ |
|
2013 | Set one file of a content |
|
2014 | """ |
|
2015 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2016 | admin = dbsession.query(models.User) \ |
|
2017 | .filter(models.User.email == '[email protected]') \ |
|
2018 | .one() |
|
2019 | workspace_api = WorkspaceApi( |
|
2020 | current_user=admin, |
|
2021 | session=dbsession, |
|
2022 | config=self.app_config |
|
2023 | ) |
|
2024 | content_api = ContentApi( |
|
2025 | current_user=admin, |
|
2026 | session=dbsession, |
|
2027 | config=self.app_config |
|
2028 | ) |
|
2029 | business_workspace = workspace_api.get_one(1) |
|
2030 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2031 | test_file = content_api.create( |
|
2032 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2033 | workspace=business_workspace, |
|
2034 | parent=tool_folder, |
|
2035 | label='Test file', |
|
2036 | do_save=False, |
|
2037 | do_notify=False, |
|
2038 | ) |
|
2039 | test_file.file_extension = '.txt' |
|
2040 | test_file.depot_file = FileIntent( |
|
2041 | b'Test file', |
|
2042 | 'Test_file.txt', |
|
2043 | 'text/plain', |
|
2044 | ) |
|
2045 | dbsession.flush() |
|
2046 | transaction.commit() |
|
2047 | content_id = int(test_file.content_id) |
|
2048 | image = create_1000px_png_test_image() |
|
2049 | self.testapp.authorization = ( |
|
2050 | 'Basic', |
|
2051 | ( |
|
2052 | '[email protected]', |
|
2053 | '[email protected]' |
|
2054 | ) |
|
2055 | ) |
|
2056 | self.testapp.put( |
|
2057 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2058 | upload_files=[ |
|
2059 | ('files', image.name, image.getvalue()) |
|
2060 | ], |
|
2061 | status=204, |
|
2062 | ) |
|
2063 | res = self.testapp.get( |
|
2064 | '/api/v2/workspaces/1/files/{}/preview/jpg'.format(content_id), |
|
2065 | status=200 |
|
2066 | ) |
|
2067 | assert res.body != image.getvalue() |
|
2068 | assert res.content_type == 'image/jpeg' |
|
2069 | ||
2070 | def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
2071 | """ |
|
@@ 2070-2123 (lines=54) @@ | ||
2067 | assert res.body != image.getvalue() |
|
2068 | assert res.content_type == 'image/jpeg' |
|
2069 | ||
2070 | def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
2071 | """ |
|
2072 | get 256x256 preview of a txt file |
|
2073 | """ |
|
2074 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
2075 | admin = dbsession.query(models.User) \ |
|
2076 | .filter(models.User.email == '[email protected]') \ |
|
2077 | .one() |
|
2078 | workspace_api = WorkspaceApi( |
|
2079 | current_user=admin, |
|
2080 | session=dbsession, |
|
2081 | config=self.app_config |
|
2082 | ) |
|
2083 | content_api = ContentApi( |
|
2084 | current_user=admin, |
|
2085 | session=dbsession, |
|
2086 | config=self.app_config |
|
2087 | ) |
|
2088 | business_workspace = workspace_api.get_one(1) |
|
2089 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2090 | test_file = content_api.create( |
|
2091 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2092 | workspace=business_workspace, |
|
2093 | parent=tool_folder, |
|
2094 | label='Test file', |
|
2095 | do_save=True, |
|
2096 | do_notify=False, |
|
2097 | ) |
|
2098 | dbsession.flush() |
|
2099 | transaction.commit() |
|
2100 | content_id = int(test_file.content_id) |
|
2101 | image = create_1000px_png_test_image() |
|
2102 | self.testapp.authorization = ( |
|
2103 | 'Basic', |
|
2104 | ( |
|
2105 | '[email protected]', |
|
2106 | '[email protected]' |
|
2107 | ) |
|
2108 | ) |
|
2109 | self.testapp.put( |
|
2110 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2111 | upload_files=[ |
|
2112 | ('files', image.name, image.getvalue()) |
|
2113 | ], |
|
2114 | status=204, |
|
2115 | ) |
|
2116 | res = self.testapp.get( |
|
2117 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256'.format(content_id), # nopep8 |
|
2118 | status=200 |
|
2119 | ) |
|
2120 | assert res.body != image.getvalue() |
|
2121 | assert res.content_type == 'image/jpeg' |
|
2122 | new_image = Image.open(io.BytesIO(res.body)) |
|
2123 | assert 256, 256 == new_image.size |
|
2124 | ||
2125 | def test_api__get_sized_jpeg_preview__err__400__SizeNotAllowed(self) -> None: # nopep8 |
|
2126 | """ |