Пример #1
0
 def test__api_notifications_no_request(self):
     "[test_ui.py] api_notifications: no request"
     with self.assertRaisesRegex(
             Http404,
             r'Internal error \(No request was provided\) for /__notifications.json'
     ):
         api_notifications(None)
Пример #2
0
 def test__api_notifications_notification_not_empty(self):
     "[test_ui.py] api_notifications: notification file not empty"
     settings.OPUS_NOTIFICATION_FILE = 'test_api/data/test_ui_notification.html'
     request = self.factory.get('__notifications.json')
     ret = api_notifications(request)
     data = json.loads(ret.content)
     print(data)
     self.assertEqual(data['notification'], "<div><p>test</p></div>")
     self.assertIsNotNone(data['notification_mdate'])
Пример #3
0
 def test__api_notifications_files_missing(self):
     "[test_ui.py] api_notifications: missing last blog update and notification files"
     settings.OPUS_LAST_BLOG_UPDATE_FILE = 'test_api/data/xyxyxyxyxyx.txt'
     settings.OPUS_NOTIFICATION_FILE = 'test_api/data/xyxyxyxyxyx.html'
     request = self.factory.get('__notifications.json')
     ret = api_notifications(request)
     print(ret)
     self.assertEqual(
         ret.content,
         b'{"lastupdate": null, "notification": null, "notification_mdate": null}'
     )
Пример #4
0
 def test__api_notifications_notification_file_empty(self):
     "[test_ui.py] api_notifications: notification file empty"
     settings.OPUS_LAST_BLOG_UPDATE_FILE = 'test_api/data/lastblogupdate.txt'
     settings.OPUS_NOTIFICATION_FILE = 'test_api/data/notification.html'
     request = self.factory.get('__notifications.json')
     ret = api_notifications(request)
     data = json.loads(ret.content)
     print(data)
     self.assertEqual(data['lastupdate'], "2019-JAN-01")
     self.assertIsNone(data['notification'])
     self.assertIsNotNone(data['notification_mdate'])
Пример #5
0
 def test__api_notifications_blog_update_file_ok(self):
     "[test_ui.py] api_notifications: blog update file ok"
     settings.OPUS_LAST_BLOG_UPDATE_FILE = 'test_api/data/lastblogupdate.txt'
     settings.OPUS_NOTIFICATION_FILE = 'test_api/data/xyxyxyxyxyx.html'
     request = self.factory.get('__notifications.json')
     ret = api_notifications(request)
     print(ret)
     self.assertEqual(
         ret.content,
         b'{"lastupdate": "2019-JAN-01", "notification": null, "notification_mdate": null}'
     )
Пример #6
0
 def test__api_notifications_blog_update_file_missing_notification_file_not_empty(
         self):
     "[test_ui.py] api_notifications: blog update missing, notification file empty"
     settings.OPUS_LAST_BLOG_UPDATE_FILE = 'test_api/data/xyxyxyxyxyx.txt'
     settings.OPUS_NOTIFICATION_FILE = 'test_api/data/test_ui_notification.html'
     request = self.factory.get('__notifications.json')
     ret = api_notifications(request)
     data = json.loads(ret.content)
     print(data)
     self.assertIsNone(data['lastupdate'])
     self.assertEqual(data['notification'], "<div><p>test</p></div>")
     self.assertIsNotNone(data['notification_mdate'])
Пример #7
0
 def test__api_notifications_no_get(self):
     "[test_ui.py] api_notifications: no GET"
     request = self.factory.get('__notifications.json')
     request.GET = None
     with self.assertRaises(Http404):
         api_notifications(request)