def test_journal_add_view_image(self): from eportfolio.models.app import Application from eportfolio.views.journal import journal_add_view from cgi import MiniFieldStorage root = Application() project = self._add_project() student = self._add_student() project.students.append(student) # 'upload_directory' setting has to be set self.config.add_settings( upload_directory=join(dirname(__file__), 'data')) # Dummy repoze.filesafe data manager from repoze.filesafe.testing import setupDummyDataManager, cleanupDummyDataManager setupDummyDataManager() # Image file to upload image_path = join(dirname(__file__), 'data', 'image.jpg') fd = open(image_path, 'rb') storage = MiniFieldStorage('image', 'image.jpg') storage.file = fd storage.filename = 'image.jpg' # Student is logged in self.config.testing_securitypolicy(userid=student.email) request = testing.DummyRequest(root=root) request.POST['text'] = u'Entry with an image' request.POST['image'] = storage request.POST['form.submitted'] = 1 journal_add_view(project, request) self.assertEquals(1, project.journal_entries.count()) entry = project.journal_entries[0] self.assertEqual('image/jpeg', entry.image.content_type) cleanupDummyDataManager()
def test_journal_add_view_image(self): from eportfolio.models.app import Application from eportfolio.views.journal import journal_add_view from cgi import MiniFieldStorage root = Application() project = self._add_project() student = self._add_student() project.students.append(student) # 'upload_directory' setting has to be set self.config.add_settings(upload_directory=join(dirname(__file__), 'data')) # Dummy repoze.filesafe data manager from repoze.filesafe.testing import setupDummyDataManager, cleanupDummyDataManager setupDummyDataManager() # Image file to upload image_path = join(dirname(__file__), 'data', 'image.jpg') fd = open(image_path, 'rb') storage = MiniFieldStorage('image', 'image.jpg') storage.file = fd storage.filename = 'image.jpg' # Student is logged in self.config.testing_securitypolicy(userid=student.email) request = testing.DummyRequest(root=root) request.POST['text'] = u'Entry with an image' request.POST['image'] = storage request.POST['form.submitted'] = 1 journal_add_view(project, request) self.assertEquals(1, project.journal_entries.count()) entry = project.journal_entries[0] self.assertEqual('image/jpeg', entry.image.content_type) cleanupDummyDataManager()
def fin(): cleanupDummyDataManager()
def tearDown(self): cleanupDummyDataManager() super(ImageTestCase, self).tearDown() configure(None, None)