Beispiel #1
0
    def test_check_status_working(self):
        """Test check_status returns True when storage is working properly."""
        default_storage_health = DefaultFileStorageHealthCheck()
        default_storage = default_storage_health.get_storage()
        default_storage_open = '{}.{}.open'.format(
            default_storage.__module__,
            default_storage.__class__.__name__
        )

        with mock.patch(default_storage_open, mock.mock_open(read_data=default_storage_health.get_file_content())):
            self.assertTrue(default_storage_health.check_status())
    def testHealthCheck(self):
        request = self.factory.get('/?type=db')
        request = Request(request)
        # print "debug>>", request.query_params['type'], "<<debug"
        plugin = DjangoDatabaseBackend()
        # print plugin.status, "debug"
        response = healthcheck(request)
        response.render()
        response_json = json.loads(response.content)
        self.assertEqual(response_json['status'], plugin.pretty_status())

        request = self.factory.get('/?type=cache')
        request = Request(request)
        # print "debug>>", request.query_params['type'], "<<debug"
        plugin = CacheBackend()
        # print plugin.status, "debug"
        response = healthcheck(request)
        response.render()
        response_json = json.loads(response.content)
        self.assertEqual(response_json['status'], plugin.pretty_status())

        request = self.factory.get('/?type=storage')
        request = Request(request)
        # print "debug>>", request.query_params['type'], "<<debug"
        plugin = DefaultFileStorageHealthCheck()
        # print plugin.status, "debug"
        response = healthcheck(request)
        response.render()
        response_json = json.loads(response.content)
        self.assertEqual(response_json['status'], plugin.pretty_status())
def healthcheck(request):
    plugin = None

    if request.query_params['type'] == 'db':
        plugin = DjangoDatabaseBackend()
    elif request.query_params['type'] == 'cache':
        plugin = CacheBackend()
    elif request.query_params['type'] == 'storage':
        plugin = DefaultFileStorageHealthCheck()

    if not plugin.status:  # Will return True or None
        return Response({"status": plugin.pretty_status()}, status=500)
    return Response({"status": plugin.pretty_status()}, status=200)
Beispiel #4
0
 def test_file_not_deleted(self):
     """Test check_status raises ServiceUnavailable when file is not deleted."""
     default_storage_health = DefaultFileStorageHealthCheck()
     with self.assertRaises(ServiceUnavailable):
         default_storage_health.check_status()
Beispiel #5
0
 def test_get_storage(self):
     """Test get_storage method returns None on the base class, but a Storage instance on default."""
     base_storage = StorageHealthCheck()
     self.assertIsNone(base_storage.get_storage())
     default_storage = DefaultFileStorageHealthCheck()
     self.assertIsInstance(default_storage.get_storage(), Storage)
 def test_file_not_deleted(self):
     default_storage_health = DefaultFileStorageHealthCheck()
     with self.assertRaises(ServiceUnavailable):
         default_storage_health.check_status()
 def test_check_status_working(self):
     default_storage = DefaultFileStorageHealthCheck()
     self.assertTrue(default_storage.check_status())
 def test_get_storage(self):
     base_storage = StorageHealthCheck()
     self.assertIsNone(base_storage.get_storage())
     default_storage = DefaultFileStorageHealthCheck()
     self.assertIsInstance(default_storage.get_storage(), Storage)