# Path: spillway/models.py
# class UploadDir(object):
# class AbstractRasterStore(models.Model):
#     class Meta:
#     def __init__(self, path):
#     def __call__(self, instance, filename):
#     def __unicode__(self):
#     def clean_fields(self, *args, **kwargs):
#     def linear(self, limits=None, k=5):
#     def quantiles(self, k=5):
#     def save(self, *args, **kwargs):
#     def array(self, geom=None):
#     def raster(self):
#     def convert(self, format=None, geom=None):
# 
# Path: tests/models.py
# class RasterStore(AbstractRasterStore):
#     objects = RasterQuerySet.as_manager()


import io
import os
import operator
import tempfile
from django.utils.six.moves import reduce
from django.core.files.storage import default_storage
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db.models.fields.files import FieldFile
from django.test import SimpleTestCase, TestCase
from greenwich import raster
from PIL import Image
from spillway.models import upload_to
from .models import RasterStore

    @classmethod
    def setUpClass(cls):
        cls.f = create_image(cls.use_multiband)
        super(RasterTestBase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.f.close()
        super(RasterTestBase, cls).tearDownClass()

    def _image(self, imgdata):
        return Image.open(io.BytesIO(imgdata))
        #return Image.open(imgdata)


class RasterStoreTestBase(RasterTestBase, TestCase):
    def setUp(self):
        super(RasterStoreTestBase, self).setUp()
        self.object = RasterStore.objects.create(image=self.data['image'].name)
        self.qs = RasterStore.objects.all()


class RasterStoreTestCase(RasterStoreTestBase):
    def test_array(self):
        point = self.object.geom.centroid.transform(3310, clone=True)
        self.assertEqual(self.object.array(point).squeeze(), 12)

    def test_save_uploadfile(self):
        upload = SimpleUploadedFile('up.tif', self.object.image.read())

# Path: spillway/models.py
# class UploadDir(object):
# class AbstractRasterStore(models.Model):
#     class Meta:
#     def __init__(self, path):
#     def __call__(self, instance, filename):
#     def __unicode__(self):
#     def clean_fields(self, *args, **kwargs):
#     def linear(self, limits=None, k=5):
#     def quantiles(self, k=5):
#     def save(self, *args, **kwargs):
#     def array(self, geom=None):
#     def raster(self):
#     def convert(self, format=None, geom=None):
# 
# Path: tests/models.py
# class RasterStore(AbstractRasterStore):
#     objects = RasterQuerySet.as_manager()


# Path: tests/test_models.py
import io
import os
import operator
import tempfile
from django.utils.six.moves import reduce
from django.core.files.storage import default_storage
from django.core.files.uploadedfile import SimpleUploadedFile
from django.db.models.fields.files import FieldFile
from django.test import SimpleTestCase, TestCase
from greenwich import raster
from PIL import Image
from spillway.models import upload_to
from .models import RasterStore


    @classmethod
    def setUpClass(cls):
        cls.f = create_image(cls.use_multiband)
        super(RasterTestBase, cls).setUpClass()

    @classmethod
    def tearDownClass(cls):
        cls.f.close()
        super(RasterTestBase, cls).tearDownClass()

    def _image(self, imgdata):
        return Image.open(io.BytesIO(imgdata))
        #return Image.open(imgdata)


class RasterStoreTestBase(RasterTestBase, TestCase):
    def setUp(self):
        super(RasterStoreTestBase, self).setUp()
        self.object = RasterStore.objects.create(image=self.data['image'].name)
        self.qs = RasterStore.objects.all()


class RasterStoreTestCase(RasterStoreTestBase):
    def test_array(self):
        point = self.object.geom.centroid.transform(3310, clone=True)
        self.assertEqual(self.object.array(point).squeeze(), 12)

    def test_save_uploadfile(self):
        upload = SimpleUploadedFile('up.tif', self.object.image.read())

        rstore = RasterStore(image=upload)