def afterSetUp(self): """ Set up """ from zope.publisher.browser import TestRequest from eea.design.browser.frontpage import Frontpage portal = self.portal wf = portal.portal_workflow # Create the 'spotlight' and 'multimedia' promotion categories: self.setRoles(['Manager']) portal.SITE.invokeFactory('Folder', id='quicklinks') portal.SITE.quicklinks.invokeFactory('Folder', id='spotlight', title=u'Spotlight') portal.SITE.quicklinks.invokeFactory('Folder', id='multimedia', title=u'Multimedia') portal.SITE.reindexObject() portal.SITE.quicklinks.reindexObject() portal.SITE.quicklinks.spotlight.reindexObject() portal.SITE.quicklinks.multimedia.reindexObject() wf.doActionFor(portal.SITE, 'publish') wf.doActionFor(portal.SITE.quicklinks, 'publish') wf.doActionFor(portal.SITE.quicklinks.spotlight, 'publish') wf.doActionFor(portal.SITE.quicklinks.multimedia, 'publish') # Also make sure promotion categories with non-ascii titles work: portal.SITE.quicklinks.invokeFactory('Folder', id='mat', title=u'Räksmörgås') wf.doActionFor(portal.SITE.quicklinks.mat, 'publish') # Set up the frontpage: portal_properties = getToolByName(portal, 'portal_properties') frontpage_properties = getattr(portal_properties, 'frontpage_properties') frontpage_properties.manage_changeProperties( promotionFolder='/plone/SITE/quicklinks') request = TestRequest() request.RESPONSE = DummyResponse() frontpage = Frontpage(self.portal, request) # Create a news item: self.setRoles(['Manager']) nid = portal.invokeFactory('News Item', id='test') item = portal[nid] item.setTitle(u'Foobar') wf.doActionFor(item, 'publish') self.item = item self.frontpage = frontpage self.request = request
def afterSetUp(self): """ Set up """ from zope.publisher.browser import TestRequest from eea.design.browser.frontpage import Frontpage portal = self.portal wf = portal.portal_workflow # Create the 'spotlight' and 'multimedia' promotion categories: self.setRoles(['Manager']) portal.SITE.invokeFactory('Folder', id='quicklinks') portal.SITE.quicklinks.invokeFactory( 'Folder', id='spotlight', title=u'Spotlight') portal.SITE.quicklinks.invokeFactory( 'Folder', id='multimedia', title=u'Multimedia') portal.SITE.reindexObject() portal.SITE.quicklinks.reindexObject() portal.SITE.quicklinks.spotlight.reindexObject() portal.SITE.quicklinks.multimedia.reindexObject() wf.doActionFor(portal.SITE, 'publish') wf.doActionFor(portal.SITE.quicklinks, 'publish') wf.doActionFor(portal.SITE.quicklinks.spotlight, 'publish') wf.doActionFor(portal.SITE.quicklinks.multimedia, 'publish') # Also make sure promotion categories with non-ascii titles work: portal.SITE.quicklinks.invokeFactory( 'Folder', id='mat', title=u'Räksmörgås') wf.doActionFor(portal.SITE.quicklinks.mat, 'publish') # Set up the frontpage: portal_properties = getToolByName(portal, 'portal_properties') frontpage_properties = getattr(portal_properties, 'frontpage_properties') frontpage_properties.manage_changeProperties( promotionFolder='/plone/SITE/quicklinks') request = TestRequest() request.RESPONSE = DummyResponse() frontpage = Frontpage(self.portal, request) # Create a news item: self.setRoles(['Manager']) nid = portal.invokeFactory('News Item', id='test') item = portal[nid] item.setTitle(u'Foobar') wf.doActionFor(item, 'publish') self.item = item self.frontpage = frontpage self.request = request
def _upload_file(self, filename, title=None, description=None): from collective.quickupload.browser.quick_upload import QuickUploadFile portal = self.layer['portal'] request = TestRequest() # We need a RESPONSE object. request.RESPONSE = request._createResponse() # Signal that this is an ajax upload: request.HTTP_X_REQUESTED_WITH = 'XHR' # Set file name: request.HTTP_X_FILE_NAME = filename request.BODYFILE = StringIO('dummy file content') if title is not None: request.form['title'] = title if description is not None: request.form['description'] = description view = QuickUploadFile(portal, request) return json.loads(view())
def _upload_file(self, filename, title=None, description=None): from collective.quickupload.browser.quick_upload import QuickUploadFile portal = self.layer["portal"] request = TestRequest() # We need a RESPONSE object. request.RESPONSE = request._createResponse() # Signal that this is an ajax upload: request.HTTP_X_REQUESTED_WITH = "XHR" # Set file name: request.HTTP_X_FILE_NAME = filename request.BODYFILE = StringIO("dummy file content") if title is not None: request.form["title"] = title if description is not None: request.form["description"] = description view = QuickUploadFile(portal, request) return json.loads(view())
def test_save_and_view_redirect(self, template, save, statusmessage): """Test that user gets redirected back to context if he clicks 'Save and view' button. """ template.return_value = True save.return_value = True # fill test request with values form = {'form.view': True} # create a Components view with a special TestRequest object # that has the RESPONSE attribute request = TestRequest(form=form) request.RESPONSE = mock.Mock(spec='redirect'.split()) view = self.makeComponentsView(request=request) view() request.RESPONSE.redirect.assert_called_with('http://plone/article')
def new_request(**kwargs): request = TestRequest(form=kwargs) request.RESPONSE=RESPONSE() return request
def add_number_of_each_review_type(portal, number_of_each, rez_classes=ALL_TYPES): '''Add a particular number of each Review/Presentation type This is useful for testing ''' # Prepare values for the Review/Presentation fields pdf_file = open(os.path.join(os.path.dirname(__file__), 'tests', 'test_content', 'Review.pdf'), 'r') pdf_obj = File(id='test-pdf', title='Test Pdf', file=pdf_file, content_type='application/pdf') word_doc_file = open(os.path.join(os.path.dirname(__file__), 'tests', 'test_content', 'Review.doc'), 'r') word_doc_obj = File(id='test-word-doc', title='Test Word Doc', file=word_doc_file, content_type='application/msword') gif_file = open(os.path.join(os.path.dirname(__file__), 'tests', 'test_content', 'Review.gif'), 'r') gif_obj = File(id='test-gif', title='Test coverImage', file=gif_file, content_type='image/gif') gif_file.close() review_text = \ u''' TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT Deutschland, Österreich, der Schweiz, Tschechien, Ungarn, Kroatien, Slowenien, der Republik Moldau, der Ukraine, Großbritannien und Frankreich. Das Themenspektrum reicht von den frühesten deutschsprachigen Zeitungen und Zeitschriften in Osteuropa aus der Zeit vor 1848 bis hin zu dem nach dem Zweiten Weltkrieg für die deutsche Minderheit in Rumänien gegründeten Blatt Neuer Weg. Der dritte Teil des Bandes beleuchtet die Zeitungslandschaft der Bukowina und ihrer Hauptstadt Czernowitz/Černivci/Cernăuţi. Einige Aufsätze, die die thematische Spannweite des Bandes zeigen, seien im Folgenden exemplarisch genannt: Walter Schmitz: Medien und Milieu. Deutschsprachige Zeitschriften in Prag um 1900; Hans-Jürgen Schrader: „Gottes starres Lid“ – Reflexionen geographischer und metaphysischer Grenzen in der Lyrik Manfred Winklers; Peter Vodopivec: Die Presse der Deutschen in der Untersteiermark und in Krain 1861–1941; András F. Balogh: Deutsche Presse in den Revolutionsjahren 1848/49 in Ungarn; Marijan Bobinac: Niedergang des deutschen und das Aufkommen des kroatischen Theaters in Zagreb nach 1848 im Spiegelbild der zeitgenössischen Publizistik; Bianca Bican: Die Zeitschrift „Frühling“ (Hermannstadt, 1920) und ihre Herausgeber; Mihai-Ştefan Ceauşu: Die Presse und das politische Leben in der Bukowina am Anfang des 20. Jahrhunderts. Der Fall der Zeitschrift „Die Wahrheit“; Mariana Hausleitner: Öffentlichkeit und Pressezensur in der Bukowina und in Bessarabien zwischen 1918 und 1938. Ana-Maria Pălimariu ''' authors_list = [dict(firstname='Tadeusz', lastname=u'Kot\u0142owski' ), dict(firstname=u'F\xfcrchtegott', lastname=u'Huberm\xfcller'), dict(firstname=u'Fran\xe7ois', lastname=u'Lam\xe8re' ), dict(firstname='Harald', lastname='Schmidt'), dict(lastname=u'Стоичков', fistname=u'Христо')] referenceAuthors_list = [dict(firstname='Tadeusz', lastname=u'Kot\u0142owski', email=u'*****@*****.**', address=u'', phone=u''), dict(firstname=u'F\xfcrchtegott', lastname=u'Huberm\xfcller', email=u'*****@*****.**', address=u'', phone=u''), dict(firstname=u'Fran\xe7ois', lastname=u'Lam\xe8re', email=u'*****@*****.**', address=u'', phone=u''), dict(firstname='Harald', lastname='Schmidt', email=u'*****@*****.**', address=u'', phone=u'')] voc = getToolByName(portal, 'portal_vocabularies') ddcPlace = voc.getVocabularyByName('region_values') ddcPlace_list = ddcPlace.getDisplayList(ddcPlace).keys() ddcSubject = voc.getVocabularyByName('topic_values') ddcSubject_list = ddcSubject.getDisplayList(ddcSubject).keys() ddcTime = voc.getVocabularyByName('epoch_values') ddcTime_list = ddcTime.getDisplayList(ddcTime).keys() random = Random() random.seed('recensio.syslab.com') def isbn(): for idx in range(1000): yield (lambda s: '-'.join([s[:3], s[3:5], s[5:10], s[10:12], s[12]]))(str(9788360448396 + idx)) isbn_generator = isbn() def test_data(): '''Randomise the values in certain fields ''' return { 'authors': [random.choice(authors_list)], 'referenceAuthors': [random.choice(referenceAuthors_list), random.choice(referenceAuthors_list)], 'ddcPlace': random.choice(ddcPlace_list), 'ddcSubject': random.choice(ddcSubject_list), 'ddcTime': random.choice(ddcTime_list), 'description': u'', 'doc': word_doc_obj, 'documenttypes_institution': u'', 'documenttypes_cooperation': u'', 'documenttypes_referenceworks': u'', 'documenttypes_bibliographical': u'', 'documenttypes_fulltexts': u'', 'documenttypes_periodicals': u'', 'yearOfPublication': u'2008', 'placeOfPublication': u'Krakow', 'officialYearOfPublication': '2008', 'number': u'2', 'editor': u'Avalon', 'editorCollectedEdition': u'', 'institution': [dict(institution=u'', lastname=u'', firstname=u'')], 'isbn': isbn_generator.next(), 'isLicenceApproved': True, 'issn': u'1822-4016', 'issue': u'5', 'shortnameJournal': u'', 'volume': '2', 'pageStart': '2', 'pageEnd': '3', 'pageStartOfReviewInJournal': '2', 'pageEndOfReviewInJournal': '3', 'pdf': pdf_obj, 'languageReviewedText': 'en', 'languageReview': 'de', 'recensioID': u'', 'series': u'', 'seriesVol': u'', 'review': review_text, 'reviewAuthor': u'', 'subject': u'', 'pages': u'', 'title': u'Niemcy', 'subtitle': u'Dzieje państwa i społeczeństwa 1890–1945', 'uri': 'http://www.syslab.com', 'idBvb': u'', 'publisher': u'', 'customCitation': u'', 'reviewAuthorHonorific': u'Dr. rer nat', 'reviewAuthors': [{'lastname': u'Стоичков', 'firstname': u'Христо'}], 'reviewAuthorEmail': u'*****@*****.**', 'titleJournal': u'', 'documenttypes_institution': u'', 'documenttypes_cooperation': u'', 'documenttypes_bibliographical': u'', 'documenttypes_individual': u'', 'documenttypes_referenceworks': u'', 'coverPicture': gif_obj, 'existingOnlineReviews': [dict(name=u'Dzieje państwa', url='')], 'publishedReviews': [dict(details=u'Journal A, 2008')], 'titleCollectedEdition': u'', 'editorsCollectedEdition': [random.choice(authors_list)], 'urn': u'testing-data-urn', 'doi': u'10.15463/rec.0123456', } # Add a folder to contain the sample-reviews portal_id = 'recensio' if 'sample-reviews' not in portal.objectIds(): portal.invokeFactory('Folder', id='sample-reviews', title='Sample Reviews') sample_reviews = portal.get('sample-reviews') for rez_class in rez_classes: # Fill in all fields with dummy content data = test_data() for # field in rez_class.ordered_fields: try: data[field] = # test_data[field] except: print "MISSING", field if rez_class.__doc__.startswith('Review'): if 'newspapera' not in sample_reviews.objectIds(): sample_reviews.invokeFactory('Publication', id='newspapera', title='Zeitschrift 1') sample_reviews['newspapera'].invokeFactory('Document', id='index_html') if 'newspaperb' not in sample_reviews.objectIds(): sample_reviews.invokeFactory('Publication', id='newspaperb', title='Zeitschrift 2') newspapera = sample_reviews['newspapera'] newspaperb = sample_reviews['newspaperb'] if 'summer' not in newspapera.objectIds(): newspapera.invokeFactory('Volume', id='summer', title='Summer') summera = newspapera['summer'] if 'summer' not in newspaperb.objectIds(): newspaperb.invokeFactory('Volume', id='summer', title='Summer') summerb = newspaperb['summer'] if 'issue-2' not in summera.objectIds(): summera.invokeFactory('Issue', id='issue-2', title='Issue 2') containera = summera['issue-2'] if 'issue-2' not in summerb.objectIds(): summerb.invokeFactory('Issue', id='issue-2', title='Issue 2') containerb = summerb['issue-2'] data = test_data() data['title'] = 'test title' data['languageReviewedText'] = 'de' data['languageReview'] = 'fr' data['shortnameJournal'] = 'Zeitschrift 1' obj = addOneItem(containerb, rez_class, data) item = containerb.objectValues()[0] comment = createObject('plone.Comment') IConversation(item).addComment(comment) containerb = summerb['issue-2'] container = containera else: pm = portal.portal_membership pm.addMember(id='fake_member', password='******', roles=[], domains=[]) pm.createMemberArea('fake_member') container = pm.getMembersFolder().get('fake_member') for i in range(number_of_each): data = test_data() if i / 3 == 1: data['languageReviewedText'] = 'fr' data['languageReview'] = 'en' elif i / 3 == 2: data['languageReviewedText'] = 'de' data['languageReview'] = 'fr' data['shortnameJournal'] = 'Zeitschrift 1' data['title'] = 'Test %s No %d' % (rez_class.portal_type, i) obj = addOneItem(container, rez_class, data) # Create sample sehepunkte and francia reviews if 'rezensionen' not in portal.objectIds(): portal.invokeFactory('Folder', 'rezensionen') rezensionen = portal.rezensionen if 'zeitschriften' not in rezensionen.objectIds(): rezensionen.invokeFactory('Folder', 'zeitschriften') zeitschriften = rezensionen.zeitschriften if 'sehepunkte' not in zeitschriften.objectIds(): zeitschriften.invokeFactory('Publication', 'sehepunkte') sehepunkte = zeitschriften.sehepunkte sehepunkte.invokeFactory('Volume', 'vol1') sp_vol1 = sehepunkte.vol1 sp_vol1.invokeFactory('Issue', 'issue1') sp_issue1 = sp_vol1.issue1 sp_issue1.invokeFactory('Review Monograph', 'sp-rm', **test_data()) sp_issue1.invokeFactory('Review Journal', 'sp-rj', **test_data()) if 'francia-recensio' not in zeitschriften.objectIds(): zeitschriften.invokeFactory('Publication', 'francia-recensio') francia_recensio = zeitschriften['francia-recensio'] francia_recensio.invokeFactory('Volume', 'vol1') fr_vol1 = francia_recensio.vol1 fr_vol1.invokeFactory('Issue', 'issue1') fr_issue1 = fr_vol1.issue1 fr_issue1.invokeFactory('Review Monograph', 'fr-rm', **test_data()) fr_issue1.invokeFactory('Review Journal', 'fr-rj', **test_data()) request = TestRequest() class FakeResponse(object): def write(a, b): pass request.RESPONSE = FakeResponse() view = getMultiAdapter((portal, request), name='solr-maintenance') view.clear() view.reindex()