|
@@ 1330-1409 (lines=80) @@
|
| 1327 |
|
|
| 1328 |
|
fixtures = [BaseFixture, ContentFixtures] |
| 1329 |
|
|
| 1330 |
|
def test_api__get_file__ok_200__nominal_case(self) -> None: |
| 1331 |
|
""" |
| 1332 |
|
Get one file of a content |
| 1333 |
|
""" |
| 1334 |
|
dbsession = get_tm_session(self.session_factory, transaction.manager) |
| 1335 |
|
admin = dbsession.query(models.User) \ |
| 1336 |
|
.filter(models.User.email == '[email protected]') \ |
| 1337 |
|
.one() |
| 1338 |
|
workspace_api = WorkspaceApi( |
| 1339 |
|
current_user=admin, |
| 1340 |
|
session=dbsession, |
| 1341 |
|
config=self.app_config |
| 1342 |
|
) |
| 1343 |
|
content_api = ContentApi( |
| 1344 |
|
current_user=admin, |
| 1345 |
|
session=dbsession, |
| 1346 |
|
config=self.app_config |
| 1347 |
|
) |
| 1348 |
|
business_workspace = workspace_api.get_one(1) |
| 1349 |
|
tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
| 1350 |
|
test_file = content_api.create( |
| 1351 |
|
content_type_slug=CONTENT_TYPES.File.slug, |
| 1352 |
|
workspace=business_workspace, |
| 1353 |
|
parent=tool_folder, |
| 1354 |
|
label='Test file', |
| 1355 |
|
do_save=False, |
| 1356 |
|
do_notify=False, |
| 1357 |
|
) |
| 1358 |
|
content_api.update_file_data( |
| 1359 |
|
test_file, |
| 1360 |
|
'Test_file.txt', |
| 1361 |
|
new_mimetype='plain/text', |
| 1362 |
|
new_content=b'Test file', |
| 1363 |
|
) |
| 1364 |
|
with new_revision( |
| 1365 |
|
session=dbsession, |
| 1366 |
|
tm=transaction.manager, |
| 1367 |
|
content=test_file, |
| 1368 |
|
): |
| 1369 |
|
content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
| 1370 |
|
dbsession.flush() |
| 1371 |
|
transaction.commit() |
| 1372 |
|
|
| 1373 |
|
self.testapp.authorization = ( |
| 1374 |
|
'Basic', |
| 1375 |
|
( |
| 1376 |
|
'[email protected]', |
| 1377 |
|
'[email protected]' |
| 1378 |
|
) |
| 1379 |
|
) |
| 1380 |
|
res = self.testapp.get( |
| 1381 |
|
'/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
| 1382 |
|
status=200 |
| 1383 |
|
) |
| 1384 |
|
content = res.json_body |
| 1385 |
|
assert content['content_type'] == 'file' |
| 1386 |
|
assert content['content_id'] == test_file.content_id |
| 1387 |
|
assert content['is_archived'] is False |
| 1388 |
|
assert content['is_deleted'] is False |
| 1389 |
|
assert content['label'] == 'Test_file' |
| 1390 |
|
assert content['parent_id'] == 1 |
| 1391 |
|
assert content['show_in_ui'] is True |
| 1392 |
|
assert content['slug'] == 'test-file' |
| 1393 |
|
assert content['status'] == 'open' |
| 1394 |
|
assert content['workspace_id'] == 1 |
| 1395 |
|
assert content['current_revision_id'] |
| 1396 |
|
# TODO - G.M - 2018-06-173 - check date format |
| 1397 |
|
assert content['created'] |
| 1398 |
|
assert content['author'] |
| 1399 |
|
assert content['author']['user_id'] == 1 |
| 1400 |
|
assert content['author']['avatar_url'] is None |
| 1401 |
|
assert content['author']['public_name'] == 'Global manager' |
| 1402 |
|
# TODO - G.M - 2018-06-173 - check date format |
| 1403 |
|
assert content['modified'] |
| 1404 |
|
assert content['last_modifier'] == content['author'] |
| 1405 |
|
assert content['raw_content'] == '<p>description</p>' # nopep8 |
| 1406 |
|
assert content['mimetype'] == 'plain/text' |
| 1407 |
|
assert content['size'] == len(b'Test file') |
| 1408 |
|
assert content['page_nb'] == 1 |
| 1409 |
|
assert content['pdf_available'] is True |
| 1410 |
|
|
| 1411 |
|
def test_api__get_file__ok_200__no_file_add(self) -> None: |
| 1412 |
|
""" |
|
@@ 1898-1980 (lines=83) @@
|
| 1895 |
|
status=400 |
| 1896 |
|
) |
| 1897 |
|
|
| 1898 |
|
def test_api__get_file_revisions__ok_200__nominal_case( |
| 1899 |
|
self |
| 1900 |
|
) -> None: |
| 1901 |
|
""" |
| 1902 |
|
Get file revisions |
| 1903 |
|
""" |
| 1904 |
|
dbsession = get_tm_session(self.session_factory, transaction.manager) |
| 1905 |
|
admin = dbsession.query(models.User) \ |
| 1906 |
|
.filter(models.User.email == '[email protected]') \ |
| 1907 |
|
.one() |
| 1908 |
|
workspace_api = WorkspaceApi( |
| 1909 |
|
current_user=admin, |
| 1910 |
|
session=dbsession, |
| 1911 |
|
config=self.app_config |
| 1912 |
|
) |
| 1913 |
|
content_api = ContentApi( |
| 1914 |
|
current_user=admin, |
| 1915 |
|
session=dbsession, |
| 1916 |
|
config=self.app_config |
| 1917 |
|
) |
| 1918 |
|
business_workspace = workspace_api.get_one(1) |
| 1919 |
|
tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
| 1920 |
|
test_file = content_api.create( |
| 1921 |
|
content_type_slug=CONTENT_TYPES.File.slug, |
| 1922 |
|
workspace=business_workspace, |
| 1923 |
|
parent=tool_folder, |
| 1924 |
|
label='Test file', |
| 1925 |
|
do_save=False, |
| 1926 |
|
do_notify=False, |
| 1927 |
|
) |
| 1928 |
|
content_api.update_file_data( |
| 1929 |
|
test_file, |
| 1930 |
|
'Test_file.txt', |
| 1931 |
|
new_mimetype='plain/text', |
| 1932 |
|
new_content=b'Test file', |
| 1933 |
|
) |
| 1934 |
|
with new_revision( |
| 1935 |
|
session=dbsession, |
| 1936 |
|
tm=transaction.manager, |
| 1937 |
|
content=test_file, |
| 1938 |
|
): |
| 1939 |
|
content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
| 1940 |
|
dbsession.flush() |
| 1941 |
|
transaction.commit() |
| 1942 |
|
|
| 1943 |
|
self.testapp.authorization = ( |
| 1944 |
|
'Basic', |
| 1945 |
|
( |
| 1946 |
|
'[email protected]', |
| 1947 |
|
'[email protected]' |
| 1948 |
|
) |
| 1949 |
|
) |
| 1950 |
|
res = self.testapp.get( |
| 1951 |
|
'/api/v2/workspaces/1/files/{}/revisions'.format(test_file.content_id), # nopep8 |
| 1952 |
|
status=200 |
| 1953 |
|
) |
| 1954 |
|
revisions = res.json_body |
| 1955 |
|
assert len(revisions) == 1 |
| 1956 |
|
revision = revisions[0] |
| 1957 |
|
assert revision['content_type'] == 'file' |
| 1958 |
|
assert revision['content_id'] == test_file.content_id |
| 1959 |
|
assert revision['is_archived'] is False |
| 1960 |
|
assert revision['is_deleted'] is False |
| 1961 |
|
assert revision['label'] == 'Test_file' |
| 1962 |
|
assert revision['parent_id'] == 1 |
| 1963 |
|
assert revision['show_in_ui'] is True |
| 1964 |
|
assert revision['slug'] == 'test-file' |
| 1965 |
|
assert revision['status'] == 'open' |
| 1966 |
|
assert revision['workspace_id'] == 1 |
| 1967 |
|
assert revision['revision_id'] |
| 1968 |
|
assert revision['sub_content_types'] |
| 1969 |
|
# TODO - G.M - 2018-06-173 - Test with real comments |
| 1970 |
|
assert revision['comment_ids'] == [] |
| 1971 |
|
# TODO - G.M - 2018-06-173 - check date format |
| 1972 |
|
assert revision['created'] |
| 1973 |
|
assert revision['author'] |
| 1974 |
|
assert revision['author']['user_id'] == 1 |
| 1975 |
|
assert revision['author']['avatar_url'] is None |
| 1976 |
|
assert revision['author']['public_name'] == 'Global manager' |
| 1977 |
|
assert revision['mimetype'] == 'plain/text' |
| 1978 |
|
assert revision['size'] == len(b'Test file') |
| 1979 |
|
assert revision['page_nb'] == 1 |
| 1980 |
|
assert revision['pdf_available'] is True |
| 1981 |
|
|
| 1982 |
|
def test_api__set_file_status__ok_200__nominal_case(self) -> None: |
| 1983 |
|
""" |