@@ 1273-1347 (lines=75) @@ | ||
1270 | ||
1271 | fixtures = [BaseFixture, ContentFixtures] |
|
1272 | ||
1273 | def test_api__get_file__ok_200__nominal_case(self) -> None: |
|
1274 | """ |
|
1275 | Get one file of a content |
|
1276 | """ |
|
1277 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1278 | admin = dbsession.query(models.User) \ |
|
1279 | .filter(models.User.email == '[email protected]') \ |
|
1280 | .one() |
|
1281 | workspace_api = WorkspaceApi( |
|
1282 | current_user=admin, |
|
1283 | session=dbsession, |
|
1284 | config=self.app_config |
|
1285 | ) |
|
1286 | content_api = ContentApi( |
|
1287 | current_user=admin, |
|
1288 | session=dbsession, |
|
1289 | config=self.app_config |
|
1290 | ) |
|
1291 | business_workspace = workspace_api.get_one(1) |
|
1292 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
1293 | test_file = content_api.create( |
|
1294 | content_type_slug=CONTENT_TYPES.File.slug, |
|
1295 | workspace=business_workspace, |
|
1296 | parent=tool_folder, |
|
1297 | label='Test file', |
|
1298 | do_save=False, |
|
1299 | do_notify=False, |
|
1300 | ) |
|
1301 | content_api.update_file_data( |
|
1302 | test_file, |
|
1303 | 'Test_file.txt', |
|
1304 | new_mimetype='plain/text', |
|
1305 | new_content=b'Test file', |
|
1306 | ) |
|
1307 | test_file.file_mimetype = test_file.depot_file.content_type |
|
1308 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
1309 | dbsession.flush() |
|
1310 | transaction.commit() |
|
1311 | ||
1312 | self.testapp.authorization = ( |
|
1313 | 'Basic', |
|
1314 | ( |
|
1315 | '[email protected]', |
|
1316 | '[email protected]' |
|
1317 | ) |
|
1318 | ) |
|
1319 | res = self.testapp.get( |
|
1320 | '/api/v2/workspaces/1/files/{}'.format(test_file.content_id), |
|
1321 | status=200 |
|
1322 | ) |
|
1323 | content = res.json_body |
|
1324 | assert content['content_type'] == 'file' |
|
1325 | assert content['content_id'] == test_file.content_id |
|
1326 | assert content['is_archived'] is False |
|
1327 | assert content['is_deleted'] is False |
|
1328 | assert content['label'] == 'Test_file' |
|
1329 | assert content['parent_id'] == 1 |
|
1330 | assert content['show_in_ui'] is True |
|
1331 | assert content['slug'] == 'test-file' |
|
1332 | assert content['status'] == 'open' |
|
1333 | assert content['workspace_id'] == 1 |
|
1334 | assert content['current_revision_id'] |
|
1335 | # TODO - G.M - 2018-06-173 - check date format |
|
1336 | assert content['created'] |
|
1337 | assert content['author'] |
|
1338 | assert content['author']['user_id'] == 1 |
|
1339 | assert content['author']['avatar_url'] is None |
|
1340 | assert content['author']['public_name'] == 'Global manager' |
|
1341 | # TODO - G.M - 2018-06-173 - check date format |
|
1342 | assert content['modified'] |
|
1343 | assert content['last_modifier'] == content['author'] |
|
1344 | assert content['raw_content'] == '<p>description</p>' # nopep8 |
|
1345 | assert content['mimetype'] == 'plain/text' |
|
1346 | assert content['size'] == len(b'Test file') |
|
1347 | assert content['page_nb'] == 1 |
|
1348 | ||
1349 | def test_api__get_file__ok_200__no_file_add(self) -> None: |
|
1350 | """ |
|
@@ 1678-1754 (lines=77) @@ | ||
1675 | assert content['size'] == len(b'Test file') |
|
1676 | assert content['page_nb'] == 1 |
|
1677 | ||
1678 | def test_api__get_file_revisions__ok_200__nominal_case( |
|
1679 | self |
|
1680 | ) -> None: |
|
1681 | """ |
|
1682 | Get file revisions |
|
1683 | """ |
|
1684 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
1685 | admin = dbsession.query(models.User) \ |
|
1686 | .filter(models.User.email == '[email protected]') \ |
|
1687 | .one() |
|
1688 | workspace_api = WorkspaceApi( |
|
1689 | current_user=admin, |
|
1690 | session=dbsession, |
|
1691 | config=self.app_config |
|
1692 | ) |
|
1693 | content_api = ContentApi( |
|
1694 | current_user=admin, |
|
1695 | session=dbsession, |
|
1696 | config=self.app_config |
|
1697 | ) |
|
1698 | business_workspace = workspace_api.get_one(1) |
|
1699 | tool_folder = content_api.get_one(1, content_type=CONTENT_TYPES.Any_SLUG) |
|
1700 | test_file = content_api.create( |
|
1701 | content_type_slug=CONTENT_TYPES.File.slug, |
|
1702 | workspace=business_workspace, |
|
1703 | parent=tool_folder, |
|
1704 | label='Test file', |
|
1705 | do_save=False, |
|
1706 | do_notify=False, |
|
1707 | ) |
|
1708 | content_api.update_file_data( |
|
1709 | test_file, |
|
1710 | 'Test_file.txt', |
|
1711 | new_mimetype='plain/text', |
|
1712 | new_content=b'Test file', |
|
1713 | ) |
|
1714 | content_api.update_content(test_file, 'Test_file', '<p>description</p>') # nopep8 |
|
1715 | dbsession.flush() |
|
1716 | transaction.commit() |
|
1717 | ||
1718 | self.testapp.authorization = ( |
|
1719 | 'Basic', |
|
1720 | ( |
|
1721 | '[email protected]', |
|
1722 | '[email protected]' |
|
1723 | ) |
|
1724 | ) |
|
1725 | res = self.testapp.get( |
|
1726 | '/api/v2/workspaces/1/files/{}/revisions'.format(test_file.content_id), # nopep8 |
|
1727 | status=200 |
|
1728 | ) |
|
1729 | revisions = res.json_body |
|
1730 | assert len(revisions) == 1 |
|
1731 | revision = revisions[0] |
|
1732 | assert revision['content_type'] == 'file' |
|
1733 | assert revision['content_id'] == test_file.content_id |
|
1734 | assert revision['is_archived'] is False |
|
1735 | assert revision['is_deleted'] is False |
|
1736 | assert revision['label'] == 'Test_file' |
|
1737 | assert revision['parent_id'] == 1 |
|
1738 | assert revision['show_in_ui'] is True |
|
1739 | assert revision['slug'] == 'test-file' |
|
1740 | assert revision['status'] == 'open' |
|
1741 | assert revision['workspace_id'] == 1 |
|
1742 | assert revision['revision_id'] |
|
1743 | assert revision['sub_content_types'] |
|
1744 | # TODO - G.M - 2018-06-173 - Test with real comments |
|
1745 | assert revision['comment_ids'] == [] |
|
1746 | # TODO - G.M - 2018-06-173 - check date format |
|
1747 | assert revision['created'] |
|
1748 | assert revision['author'] |
|
1749 | assert revision['author']['user_id'] == 1 |
|
1750 | assert revision['author']['avatar_url'] is None |
|
1751 | assert revision['author']['public_name'] == 'Global manager' |
|
1752 | assert revision['mimetype'] == 'plain/text' |
|
1753 | assert revision['size'] == len(b'Test file') |
|
1754 | assert revision['page_nb'] == 1 |
|
1755 | ||
1756 | def test_api__set_file_status__ok_200__nominal_case(self) -> None: |
|
1757 | """ |