|
@@ -432,6 +432,187 @@ class TestUserReadStatusEndpoint(FunctionalTest):
|
432
|
432
|
# folder subcontent modification does not change folder order
|
433
|
433
|
assert res[6]['content_id'] == main_folder.content_id
|
434
|
434
|
|
|
435
|
+
|
|
436
|
+class TestUserSetContentAsRead(FunctionalTest):
|
|
437
|
+
|
|
438
|
+ def test_api_set_content_as_read__ok__200__nominal_case(self):
|
|
439
|
+ # init DB
|
|
440
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
441
|
+ admin = dbsession.query(models.User) \
|
|
442
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
443
|
+ .one()
|
|
444
|
+ workspace_api = WorkspaceApi(
|
|
445
|
+ current_user=admin,
|
|
446
|
+ session=dbsession,
|
|
447
|
+ config=self.app_config
|
|
448
|
+
|
|
449
|
+ )
|
|
450
|
+ workspace = WorkspaceApi(
|
|
451
|
+ current_user=admin,
|
|
452
|
+ session=dbsession,
|
|
453
|
+ config=self.app_config,
|
|
454
|
+ ).create_workspace(
|
|
455
|
+ 'test workspace',
|
|
456
|
+ save_now=True
|
|
457
|
+ )
|
|
458
|
+ api = ContentApi(
|
|
459
|
+ current_user=admin,
|
|
460
|
+ session=dbsession,
|
|
461
|
+ config=self.app_config,
|
|
462
|
+ )
|
|
463
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
464
|
+ # creation order test
|
|
465
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
466
|
+ api.mark_unread(firstly_created)
|
|
467
|
+ dbsession.flush()
|
|
468
|
+ transaction.commit()
|
|
469
|
+
|
|
470
|
+ self.testapp.authorization = (
|
|
471
|
+ 'Basic',
|
|
472
|
+ (
|
|
473
|
+ 'admin@admin.admin',
|
|
474
|
+ 'admin@admin.admin'
|
|
475
|
+ )
|
|
476
|
+ )
|
|
477
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
478
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
479
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
480
|
+ self.testapp.put(
|
|
481
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/read'.format( # nopep8
|
|
482
|
+ workspace_id=workspace.workspace_id,
|
|
483
|
+ content_id=firstly_created.content_id,
|
|
484
|
+ user_id=admin.user_id,
|
|
485
|
+ )
|
|
486
|
+ )
|
|
487
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
488
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
489
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
490
|
+
|
|
491
|
+ @pytest.mark.xfail(reason='To be done')
|
|
492
|
+ def test_api_set_content_as_read__ok__200__with_comments(self):
|
|
493
|
+ raise NotImplemented()
|
|
494
|
+
|
|
495
|
+
|
|
496
|
+class TestUserSetContentAsUnread(FunctionalTest):
|
|
497
|
+
|
|
498
|
+ def test_api_set_content_as_unread__ok__200__nominal_case(self):
|
|
499
|
+ # init DB
|
|
500
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
501
|
+ admin = dbsession.query(models.User) \
|
|
502
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
503
|
+ .one()
|
|
504
|
+ workspace_api = WorkspaceApi(
|
|
505
|
+ current_user=admin,
|
|
506
|
+ session=dbsession,
|
|
507
|
+ config=self.app_config
|
|
508
|
+
|
|
509
|
+ )
|
|
510
|
+ workspace = WorkspaceApi(
|
|
511
|
+ current_user=admin,
|
|
512
|
+ session=dbsession,
|
|
513
|
+ config=self.app_config,
|
|
514
|
+ ).create_workspace(
|
|
515
|
+ 'test workspace',
|
|
516
|
+ save_now=True
|
|
517
|
+ )
|
|
518
|
+ api = ContentApi(
|
|
519
|
+ current_user=admin,
|
|
520
|
+ session=dbsession,
|
|
521
|
+ config=self.app_config,
|
|
522
|
+ )
|
|
523
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
524
|
+ # creation order test
|
|
525
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
526
|
+ api.mark_read(firstly_created)
|
|
527
|
+ dbsession.flush()
|
|
528
|
+ transaction.commit()
|
|
529
|
+
|
|
530
|
+ self.testapp.authorization = (
|
|
531
|
+ 'Basic',
|
|
532
|
+ (
|
|
533
|
+ 'admin@admin.admin',
|
|
534
|
+ 'admin@admin.admin'
|
|
535
|
+ )
|
|
536
|
+ )
|
|
537
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
538
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
539
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
540
|
+ self.testapp.put(
|
|
541
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/contents/{content_id}/unread'.format( # nopep8
|
|
542
|
+ workspace_id=workspace.workspace_id,
|
|
543
|
+ content_id=firstly_created.content_id,
|
|
544
|
+ user_id=admin.user_id,
|
|
545
|
+ )
|
|
546
|
+ )
|
|
547
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
548
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
549
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
550
|
+
|
|
551
|
+ @pytest.mark.xfail(reason='To be done')
|
|
552
|
+ def test_api_set_content_as_unread__ok__200__with_comments(self):
|
|
553
|
+ raise NotImplemented()
|
|
554
|
+
|
|
555
|
+class TestUserSetWorkspaceAsRead(FunctionalTest):
|
|
556
|
+
|
|
557
|
+ def test_api_set_content_as_read__ok__200__nominal_case(self):
|
|
558
|
+ # init DB
|
|
559
|
+ dbsession = get_tm_session(self.session_factory, transaction.manager)
|
|
560
|
+ admin = dbsession.query(models.User) \
|
|
561
|
+ .filter(models.User.email == 'admin@admin.admin') \
|
|
562
|
+ .one()
|
|
563
|
+ workspace_api = WorkspaceApi(
|
|
564
|
+ current_user=admin,
|
|
565
|
+ session=dbsession,
|
|
566
|
+ config=self.app_config
|
|
567
|
+
|
|
568
|
+ )
|
|
569
|
+ workspace = WorkspaceApi(
|
|
570
|
+ current_user=admin,
|
|
571
|
+ session=dbsession,
|
|
572
|
+ config=self.app_config,
|
|
573
|
+ ).create_workspace(
|
|
574
|
+ 'test workspace',
|
|
575
|
+ save_now=True
|
|
576
|
+ )
|
|
577
|
+ api = ContentApi(
|
|
578
|
+ current_user=admin,
|
|
579
|
+ session=dbsession,
|
|
580
|
+ config=self.app_config,
|
|
581
|
+ )
|
|
582
|
+ main_folder = api.create(ContentType.Folder, workspace, None, 'this is randomized folder', '', True) # nopep8
|
|
583
|
+ # creation order test
|
|
584
|
+ firstly_created = api.create(ContentType.Page, workspace, main_folder, 'creation_order_test', '', True) # nopep8
|
|
585
|
+ api.mark_unread(main_folder)
|
|
586
|
+ api.mark_unread(firstly_created)
|
|
587
|
+ dbsession.flush()
|
|
588
|
+ transaction.commit()
|
|
589
|
+
|
|
590
|
+ self.testapp.authorization = (
|
|
591
|
+ 'Basic',
|
|
592
|
+ (
|
|
593
|
+ 'admin@admin.admin',
|
|
594
|
+ 'admin@admin.admin'
|
|
595
|
+ )
|
|
596
|
+ )
|
|
597
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
598
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
599
|
+ assert res.json_body[0]['read_by_user'] is False
|
|
600
|
+ assert res.json_body[1]['content_id'] == main_folder.content_id
|
|
601
|
+ assert res.json_body[1]['read_by_user'] is False
|
|
602
|
+ self.testapp.put(
|
|
603
|
+ '/api/v2/users/{user_id}/workspaces/{workspace_id}/read'.format( # nopep8
|
|
604
|
+ workspace_id=workspace.workspace_id,
|
|
605
|
+ content_id=firstly_created.content_id,
|
|
606
|
+ user_id=admin.user_id,
|
|
607
|
+ )
|
|
608
|
+ )
|
|
609
|
+ res = self.testapp.get('/api/v2/users/1/workspaces/{}/contents/read_status'.format(workspace.workspace_id), status=200) # nopep8
|
|
610
|
+ assert res.json_body[0]['content_id'] == firstly_created.content_id
|
|
611
|
+ assert res.json_body[0]['read_by_user'] is True
|
|
612
|
+ assert res.json_body[1]['content_id'] == main_folder.content_id
|
|
613
|
+ assert res.json_body[1]['read_by_user'] is True
|
|
614
|
+
|
|
615
|
+
|
435
|
616
|
class TestUserWorkspaceEndpoint(FunctionalTest):
|
436
|
617
|
"""
|
437
|
618
|
Tests for /api/v2/users/{user_id}/workspaces
|