Пример #1
0
    def test_read_model_mixin_must_return_last_modified_header(self):
        dummy = DummyModel.objects.create(name='my dum dum')

        class DummyResource(ModelResource):
            model = DummyModel

        request = self.req.get('/dummies')
        mixin = ReadModelMixin()
        mixin.resource = DummyResource

        response = mixin.get(request, dummy.id)
        self.assertEquals(dummy.name, response.cleaned_content.name)
        self.assertTrue(response.headers.has_key('Last-Modified'))
        self.assertEqual(response.headers['Last-Modified'], dummy.last_modified)
Пример #2
0
    def test_read_model_mixin_must_return_last_modified_header_as_now(self):
        dummier = DummierModel.objects.create(name='my dummier')

        class DummierResource(ModelResource):
            model = DummierModel

        request = self.req.get('/dummiers')
        mixin = ReadModelMixin()
        mixin.resource = DummierResource

        response = mixin.get(request, dummier.id)
        self.assertEquals(dummier.name, response.cleaned_content.name)
        self.assertTrue(response.headers.has_key('Last-Modified'))
        last_modified = response.headers['Last-Modified']
        # no error should occur, meaning we have the right format
        last_modified_datetime = parse_http_date(last_modified)
        self.assertEqual(last_modified_datetime, time.mktime(datetime(2012, 12, 12, 6, 6, 6).timetuple()))