@@ 1929-1986 (lines=58) @@ | ||
1926 | assert dim['width'] == 256 |
|
1927 | assert dim['height'] == 256 |
|
1928 | ||
1929 | def test_api__get_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
1930 | """ |
|
1931 | Set one file of a content |
|
1932 | """ |
|
1933 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1934 | admin = dbsession.query(models.User) \ |
|
1935 | .filter(models.User.email == '[email protected]') \ |
|
1936 | .one() |
|
1937 | workspace_api = WorkspaceApi( |
|
1938 | current_user=admin, |
|
1939 | session=dbsession, |
|
1940 | config=self.app_config |
|
1941 | ) |
|
1942 | content_api = ContentApi( |
|
1943 | current_user=admin, |
|
1944 | session=dbsession, |
|
1945 | config=self.app_config |
|
1946 | ) |
|
1947 | business_workspace = workspace_api.get_one(1) |
|
1948 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
1949 | test_file = content_api.create( |
|
1950 | content_type_slug=CONTENT_TYPES.File.slug, |
|
1951 | workspace=business_workspace, |
|
1952 | parent=tool_folder, |
|
1953 | label='Test file', |
|
1954 | do_save=False, |
|
1955 | do_notify=False, |
|
1956 | ) |
|
1957 | test_file.file_extension = '.txt' |
|
1958 | test_file.depot_file = FileIntent( |
|
1959 | b'Test file', |
|
1960 | 'Test_file.txt', |
|
1961 | 'text/plain', |
|
1962 | ) |
|
1963 | dbsession.flush() |
|
1964 | transaction.commit() |
|
1965 | content_id = int(test_file.content_id) |
|
1966 | image = create_1000px_png_test_image() |
|
1967 | self.testapp.authorization = ( |
|
1968 | 'Basic', |
|
1969 | ( |
|
1970 | '[email protected]', |
|
1971 | '[email protected]' |
|
1972 | ) |
|
1973 | ) |
|
1974 | self.testapp.put( |
|
1975 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
1976 | upload_files=[ |
|
1977 | ('files', image.name, image.getvalue()) |
|
1978 | ], |
|
1979 | status=204, |
|
1980 | ) |
|
1981 | res = self.testapp.get( |
|
1982 | '/api/v2/workspaces/1/files/{}/preview/jpg'.format(content_id), |
|
1983 | status=200 |
|
1984 | ) |
|
1985 | assert res.body != image.getvalue() |
|
1986 | assert res.content_type == 'image/jpeg' |
|
1987 | ||
1988 | def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
1989 | """ |
|
@@ 1988-2041 (lines=54) @@ | ||
1985 | assert res.body != image.getvalue() |
|
1986 | assert res.content_type == 'image/jpeg' |
|
1987 | ||
1988 | def test_api__get_sized_jpeg_preview__ok__200__nominal_case(self) -> None: |
|
1989 | """ |
|
1990 | get 256x256 preview of a txt file |
|
1991 | """ |
|
1992 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1993 | admin = dbsession.query(models.User) \ |
|
1994 | .filter(models.User.email == '[email protected]') \ |
|
1995 | .one() |
|
1996 | workspace_api = WorkspaceApi( |
|
1997 | current_user=admin, |
|
1998 | session=dbsession, |
|
1999 | config=self.app_config |
|
2000 | ) |
|
2001 | content_api = ContentApi( |
|
2002 | current_user=admin, |
|
2003 | session=dbsession, |
|
2004 | config=self.app_config |
|
2005 | ) |
|
2006 | business_workspace = workspace_api.get_one(1) |
|
2007 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
2008 | test_file = content_api.create( |
|
2009 | content_type_slug=CONTENT_TYPES.File.slug, |
|
2010 | workspace=business_workspace, |
|
2011 | parent=tool_folder, |
|
2012 | label='Test file', |
|
2013 | do_save=True, |
|
2014 | do_notify=False, |
|
2015 | ) |
|
2016 | dbsession.flush() |
|
2017 | transaction.commit() |
|
2018 | content_id = int(test_file.content_id) |
|
2019 | image = create_1000px_png_test_image() |
|
2020 | self.testapp.authorization = ( |
|
2021 | 'Basic', |
|
2022 | ( |
|
2023 | '[email protected]', |
|
2024 | '[email protected]' |
|
2025 | ) |
|
2026 | ) |
|
2027 | self.testapp.put( |
|
2028 | '/api/v2/workspaces/1/files/{}/raw'.format(content_id), |
|
2029 | upload_files=[ |
|
2030 | ('files', image.name, image.getvalue()) |
|
2031 | ], |
|
2032 | status=204, |
|
2033 | ) |
|
2034 | res = self.testapp.get( |
|
2035 | '/api/v2/workspaces/1/files/{}/preview/jpg/256x256'.format(content_id), # nopep8 |
|
2036 | status=200 |
|
2037 | ) |
|
2038 | assert res.body != image.getvalue() |
|
2039 | assert res.content_type == 'image/jpeg' |
|
2040 | new_image = Image.open(io.BytesIO(res.body)) |
|
2041 | assert 256, 256 == new_image.size |
|
2042 | ||
2043 | def test_api__get_sized_jpeg_preview__err__400__SizeNotAllowed(self) -> None: # nopep8 |
|
2044 | """ |