Example #1
0
    def test_copy(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()

        target_filemeta = FileMeta()
        target_filemeta.delivery = self.filemeta.delivery
        target_filemeta.size = 0
        target_filemeta.filename = 'test2.txt'
        target_filemeta.save()
        store.copy(self.filemeta, target_filemeta)
        self.assertEquals(store.read_open(target_filemeta).read(), 'hello')
    def test_copy(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()

        target_filemeta = FileMeta()
        target_filemeta.delivery = self.filemeta.delivery
        target_filemeta.size = 0
        target_filemeta.filename = 'test2.txt'
        target_filemeta.save()
        store.copy(self.filemeta, target_filemeta)
        self.assertEquals(store.read_open(target_filemeta).read(), 'hello')
class DeliveryStoreTestMixin(TestHelper):
    """ Mixin-class that tests if
    :class:`devilry.core.deliverystore.DeliveryStoreInterface` is
    implemented correctly.

    You only need to override
    :meth:`get_storageobj`, and maybe :meth:`setUp` and :meth:`tearDown`,
    but make sure you call ``super(..., self).setUp()`` if you override it.
    
    You **must** mixin this class before :class:`django.test.TestCase` like
    so::

        class TestMyDeliveryStore(DeliveryStoreTestMixin, django.test.TestCase):
            ...
    """

    def get_storageobj(self):
        """ Return a object implementing
        :class:`devilry.core.deliverystore.DeliveryStoreInterface` """
        raise NotImplementedError()

    def setUp(self):
        """ Make sure to call this if you override it in subclasses, or the
        tests **will fail**. """
        self.add(nodes="uio.ifi",
                 subjects=["inf1100"],
                 periods=["period"],
                 assignments=["assignment1"],
                 assignmentgroups=["g1:candidate(student1)"],
                 deadlines=['d1:ends(10)'])
        # file and verdict
        self.goodFile = {"good.py": "print awesome"}
        d = self.add_delivery("inf1100.period.assignment1.g1", self.goodFile)
        self.filemeta = FileMeta()
        self.filemeta.delivery = d
        self.filemeta.size = 0
        self.filemeta.filename = 'test.txt'
        self.filemeta.save()

    def test_writemany(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.write(' world')
        w.write('!')
        w.close()
        r = store.read_open(self.filemeta)
        self.assertEquals(r.read(), 'hello world!')

    def test_readwrite(self):
        store = self.get_storageobj()
        self.assertFalse(store.exists(self.filemeta))
        self.assertRaises(FileNotFoundError, store.read_open, self.filemeta)
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()
        self.assertTrue(store.exists(self.filemeta))
        store.remove(self.filemeta)
        self.assertFalse(store.exists(self.filemeta))
        self.assertRaises(FileNotFoundError, store.remove, self.filemeta)

    def test_copy(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()

        target_filemeta = FileMeta()
        target_filemeta.delivery = self.filemeta.delivery
        target_filemeta.size = 0
        target_filemeta.filename = 'test2.txt'
        target_filemeta.save()
        store.copy(self.filemeta, target_filemeta)
        self.assertEquals(store.read_open(target_filemeta).read(), 'hello')
Example #4
0
class DeliveryStoreTestMixin(TestHelper):
    """ Mixin-class that tests if
    :class:`devilry.core.deliverystore.DeliveryStoreInterface` is
    implemented correctly.

    You only need to override
    :meth:`get_storageobj`, and maybe :meth:`setUp` and :meth:`tearDown`,
    but make sure you call ``super(..., self).setUp()`` if you override it.
    
    You **must** mixin this class before :class:`django.test.TestCase` like
    so::

        class TestMyDeliveryStore(DeliveryStoreTestMixin, django.test.TestCase):
            ...
    """
    def get_storageobj(self):
        """ Return a object implementing
        :class:`devilry.core.deliverystore.DeliveryStoreInterface` """
        raise NotImplementedError()

    def setUp(self):
        """ Make sure to call this if you override it in subclasses, or the
        tests **will fail**. """
        self.add(nodes="uio.ifi",
                 subjects=["inf1100"],
                 periods=["period"],
                 assignments=["assignment1"],
                 assignmentgroups=["g1:candidate(student1)"],
                 deadlines=['d1:ends(10)'])
        # file and verdict
        self.goodFile = {"good.py": "print awesome"}
        d = self.add_delivery("inf1100.period.assignment1.g1", self.goodFile)
        self.filemeta = FileMeta()
        self.filemeta.delivery = d
        self.filemeta.size = 0
        self.filemeta.filename = 'test.txt'
        self.filemeta.save()

    def test_writemany(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.write(' world')
        w.write('!')
        w.close()
        r = store.read_open(self.filemeta)
        self.assertEquals(r.read(), 'hello world!')

    def test_readwrite(self):
        store = self.get_storageobj()
        self.assertFalse(store.exists(self.filemeta))
        self.assertRaises(FileNotFoundError, store.read_open, self.filemeta)
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()
        self.assertTrue(store.exists(self.filemeta))
        store.remove(self.filemeta)
        self.assertFalse(store.exists(self.filemeta))
        self.assertRaises(FileNotFoundError, store.remove, self.filemeta)

    def test_copy(self):
        store = self.get_storageobj()
        w = store.write_open(self.filemeta)
        w.write('hello')
        w.close()

        target_filemeta = FileMeta()
        target_filemeta.delivery = self.filemeta.delivery
        target_filemeta.size = 0
        target_filemeta.filename = 'test2.txt'
        target_filemeta.save()
        store.copy(self.filemeta, target_filemeta)
        self.assertEquals(store.read_open(target_filemeta).read(), 'hello')