|
@@ -1459,6 +1459,206 @@ class TestFiles(FunctionalTest):
|
1459
|
1459
|
status=400
|
1460
|
1460
|
)
|
1461
|
1461
|
|
|
1462
|
+ def test_api__get_pdf_preview__ok__200__nominal_case(self) -> None:
|
|
1463
|
+ """
|
|
1464
|
+ get full pdf preview of a txt file
|
|
1465
|
+ """
|
|
1466
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
1467
|
+ admin = dbsession.query(models.User) \
|
|
1468
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
1469
|
+ .one()
|
|
1470
|
+ workspace_api = WorkspaceApi(
|
|
1471
|
+ current_user=admin,
|
|
1472
|
+ session=dbsession,
|
|
1473
|
+ config=self.app_config
|
|
1474
|
+ )
|
|
1475
|
+ content_api = ContentApi(
|
|
1476
|
+ current_user=admin,
|
|
1477
|
+ session=dbsession,
|
|
1478
|
+ config=self.app_config
|
|
1479
|
+ )
|
|
1480
|
+ business_workspace = workspace_api.get_one(1)
|
|
1481
|
+ tool_folder = content_api.get_one(1, content_type=ContentType.Any)
|
|
1482
|
+ test_file = content_api.create(
|
|
1483
|
+ content_type=ContentType.File,
|
|
1484
|
+ workspace=business_workspace,
|
|
1485
|
+ parent=tool_folder,
|
|
1486
|
+ label='Test file',
|
|
1487
|
+ do_save=True,
|
|
1488
|
+ do_notify=False,
|
|
1489
|
+ )
|
|
1490
|
+ with new_revision(
|
|
1491
|
+ session=dbsession,
|
|
1492
|
+ tm=transaction.manager,
|
|
1493
|
+ content=test_file,
|
|
1494
|
+ ):
|
|
1495
|
+ test_file.file_extension = '.txt'
|
|
1496
|
+ test_file.depot_file = FileIntent(
|
|
1497
|
+ b'Test file',
|
|
1498
|
+ 'Test_file.txt',
|
|
1499
|
+ 'text/plain',
|
|
1500
|
+ )
|
|
1501
|
+ content_api.update_content(test_file, 'Test_file', '<p>description</p>')
|
|
1502
|
+ dbsession.flush()
|
|
1503
|
+ transaction.commit()
|
|
1504
|
+ content_id = int(test_file.content_id)
|
|
1505
|
+ self.testapp.authorization = (
|
|
1506
|
+ 'Basic',
|
|
1507
|
+ (
|
|
1508
|
+ 'admin@admin.admin',
|
|
1509
|
+ 'admin@admin.admin'
|
|
1510
|
+ )
|
|
1511
|
+ )
|
|
1512
|
+ res = self.testapp.put(
|
|
1513
|
+ '/api/v2/workspaces/1/files/{}/raw'.format(content_id),
|
|
1514
|
+ upload_files=[
|
|
1515
|
+ ('files', test_file.file_name, test_file.depot_file.file.read())
|
|
1516
|
+ ],
|
|
1517
|
+ status=204,
|
|
1518
|
+ )
|
|
1519
|
+ params = {'page': 0}
|
|
1520
|
+ res = self.testapp.get(
|
|
1521
|
+ '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id),
|
|
1522
|
+ status=200,
|
|
1523
|
+ params=params,
|
|
1524
|
+ )
|
|
1525
|
+ assert res.content_type == 'application/pdf'
|
|
1526
|
+
|
|
1527
|
+ def test_api__get_pdf_preview__ok__err__400_page_of_preview_not_found(self) -> None:
|
|
1528
|
+ """
|
|
1529
|
+ get full pdf preview of a txt file
|
|
1530
|
+ """
|
|
1531
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
1532
|
+ admin = dbsession.query(models.User) \
|
|
1533
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
1534
|
+ .one()
|
|
1535
|
+ workspace_api = WorkspaceApi(
|
|
1536
|
+ current_user=admin,
|
|
1537
|
+ session=dbsession,
|
|
1538
|
+ config=self.app_config
|
|
1539
|
+ )
|
|
1540
|
+ content_api = ContentApi(
|
|
1541
|
+ current_user=admin,
|
|
1542
|
+ session=dbsession,
|
|
1543
|
+ config=self.app_config
|
|
1544
|
+ )
|
|
1545
|
+ business_workspace = workspace_api.get_one(1)
|
|
1546
|
+ tool_folder = content_api.get_one(1, content_type=ContentType.Any)
|
|
1547
|
+ test_file = content_api.create(
|
|
1548
|
+ content_type=ContentType.File,
|
|
1549
|
+ workspace=business_workspace,
|
|
1550
|
+ parent=tool_folder,
|
|
1551
|
+ label='Test file',
|
|
1552
|
+ do_save=True,
|
|
1553
|
+ do_notify=False,
|
|
1554
|
+ )
|
|
1555
|
+ with new_revision(
|
|
1556
|
+ session=dbsession,
|
|
1557
|
+ tm=transaction.manager,
|
|
1558
|
+ content=test_file,
|
|
1559
|
+ ):
|
|
1560
|
+ test_file.file_extension = '.txt'
|
|
1561
|
+ test_file.depot_file = FileIntent(
|
|
1562
|
+ b'Test file',
|
|
1563
|
+ 'Test_file.txt',
|
|
1564
|
+ 'text/plain',
|
|
1565
|
+ )
|
|
1566
|
+ content_api.update_content(test_file, 'Test_file', '<p>description</p>')
|
|
1567
|
+ dbsession.flush()
|
|
1568
|
+ transaction.commit()
|
|
1569
|
+ content_id = int(test_file.content_id)
|
|
1570
|
+ self.testapp.authorization = (
|
|
1571
|
+ 'Basic',
|
|
1572
|
+ (
|
|
1573
|
+ 'admin@admin.admin',
|
|
1574
|
+ 'admin@admin.admin'
|
|
1575
|
+ )
|
|
1576
|
+ )
|
|
1577
|
+ res = self.testapp.put(
|
|
1578
|
+ '/api/v2/workspaces/1/files/{}/raw'.format(content_id),
|
|
1579
|
+ upload_files=[
|
|
1580
|
+ ('files', test_file.file_name, test_file.depot_file.file.read())
|
|
1581
|
+ ],
|
|
1582
|
+ status=204,
|
|
1583
|
+ )
|
|
1584
|
+ params = {'page': 1}
|
|
1585
|
+ res = self.testapp.get(
|
|
1586
|
+ '/api/v2/workspaces/1/files/{}/preview/pdf'.format(content_id),
|
|
1587
|
+ status=400,
|
|
1588
|
+ params=params,
|
|
1589
|
+ )
|
|
1590
|
+
|
|
1591
|
+ def test_api__get_pdf_revision_preview__ok__200__nominal_case(self) -> None:
|
|
1592
|
+ """
|
|
1593
|
+ get pdf revision preview of content
|
|
1594
|
+ """
|
|
1595
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
1596
|
+ admin = dbsession.query(models.User) \
|
|
1597
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
1598
|
+ .one()
|
|
1599
|
+ workspace_api = WorkspaceApi(
|
|
1600
|
+ current_user=admin,
|
|
1601
|
+ session=dbsession,
|
|
1602
|
+ config=self.app_config
|
|
1603
|
+ )
|
|
1604
|
+ content_api = ContentApi(
|
|
1605
|
+ current_user=admin,
|
|
1606
|
+ session=dbsession,
|
|
1607
|
+ config=self.app_config
|
|
1608
|
+ )
|
|
1609
|
+ business_workspace = workspace_api.get_one(1)
|
|
1610
|
+ tool_folder = content_api.get_one(1, content_type=ContentType.Any)
|
|
1611
|
+ test_file = content_api.create(
|
|
1612
|
+ content_type=ContentType.File,
|
|
1613
|
+ workspace=business_workspace,
|
|
1614
|
+ parent=tool_folder,
|
|
1615
|
+ label='Test file',
|
|
1616
|
+ do_save=False,
|
|
1617
|
+ do_notify=False,
|
|
1618
|
+ )
|
|
1619
|
+ test_file.file_extension = '.txt'
|
|
1620
|
+ test_file.depot_file = FileIntent(
|
|
1621
|
+ b'Test file',
|
|
1622
|
+ 'Test_file.txt',
|
|
1623
|
+ 'text/plain',
|
|
1624
|
+ )
|
|
1625
|
+ dbsession.flush()
|
|
1626
|
+ transaction.commit()
|
|
1627
|
+ content_id = int(test_file.content_id)
|
|
1628
|
+ revision_id = int(test_file.revision_id)
|
|
1629
|
+ image = create_test_image()
|
|
1630
|
+ self.testapp.authorization = (
|
|
1631
|
+ 'Basic',
|
|
1632
|
+ (
|
|
1633
|
+ 'admin@admin.admin',
|
|
1634
|
+ 'admin@admin.admin'
|
|
1635
|
+ )
|
|
1636
|
+ )
|
|
1637
|
+ res = self.testapp.put(
|
|
1638
|
+ '/api/v2/workspaces/1/files/{}/raw'.format(content_id),
|
|
1639
|
+ upload_files=[
|
|
1640
|
+ ('files', image.name, image.getvalue())
|
|
1641
|
+ ],
|
|
1642
|
+ status=204,
|
|
1643
|
+ )
|
|
1644
|
+ res = self.testapp.get(
|
|
1645
|
+ '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/raw'.format(
|
|
1646
|
+ content_id=content_id,
|
|
1647
|
+ revision_id=revision_id,
|
|
1648
|
+ ),
|
|
1649
|
+ status=200
|
|
1650
|
+ )
|
|
1651
|
+ assert res.content_type == 'text/plain'
|
|
1652
|
+ params = {'page': 0}
|
|
1653
|
+ res = self.testapp.get(
|
|
1654
|
+ '/api/v2/workspaces/1/files/{content_id}/revisions/{revision_id}/preview/pdf'.format(
|
|
1655
|
+ content_id=content_id,
|
|
1656
|
+ revision_id=revision_id,
|
|
1657
|
+ ),
|
|
1658
|
+ status=200
|
|
1659
|
+ )
|
|
1660
|
+ assert res.content_type == 'application/pdf'
|
|
1661
|
+
|
1462
|
1662
|
|
1463
|
1663
|
class TestThreads(FunctionalTest):
|
1464
|
1664
|
"""
|