예제 #1
0
    def mk_pages(
            self, workspace, count=2, timestamp_cb=None, language='eng_GB',
            **kwargs):  # pragma: no cover
        timestamp_cb = (
            timestamp_cb or (lambda i: datetime.utcnow().isoformat()))
        pages = []
        for i in range(count):
            data = {}
            data.update({
                'title': u'Test Page %s' % (i,),
                'content': u'this is sample content for pg %s' % (i,),
                'modified_at': timestamp_cb(i),
                'language': language,
                'position': i
            })
            data.update(kwargs)
            data.update({
                'slug': slugify(data['title'])
            })
            page = Page(data)
            workspace.save(page, message=u'Added page %s.' % (i,))
            pages.append(page)

        workspace.refresh_index()
        return pages
예제 #2
0
    def test_search_single_language_no_results(self):
        mother_english = Page({
            'title': 'title for english mother', 'language': 'eng_GB',
            'position': 2, 'content': 'Page for mother test page'})
        self.workspace.save(mother_english, 'Add mother page')
        self.workspace.refresh_index()

        self.app.get('/locale/spa_ES/', status=302)
        resp = self.app.get('/search/', params={'q': 'mother'}, status=200)
        self.assertTrue('No results found' in resp.body)
    def test_fastforward(self):
        page1 = Page({
            'title': 'foo'
        })
        page2 = Page({
            'title': 'bar'
        })

        self.remote_workspace.save(page1, 'Saving page1.')
        self.remote_workspace.save(page2, 'Saving page2.')

        self.local_workspace.repo.create_remote(
            'origin', self.remote_workspace.working_dir)

        self.assertEqual(
            self.local_workspace.S(Page).count(), 0)
        fastforward(self.local_workspace.working_dir,
                    self.local_workspace.index_prefix)
        self.assertEqual(
            self.local_workspace.S(Page).count(), 2)
예제 #4
0
    def create_pages(self, workspace, count=2, locale='eng_UK', **kwargs):
        pages = []
        for data, i in self.create_page_data_iter(count=count,
                                                  locale=locale,
                                                  **kwargs):
            page = Page(data)
            workspace.save(page, message=u'Added page %s.' % (i, ))
            pages.append(page)

        workspace.refresh_index()
        return pages
예제 #5
0
    def test_pages_ordering(self):
        [category] = self.create_categories(self.workspace, count=1)
        page1 = Page({
            'title': 'title 1',
            'language': 'eng_GB',
            'position': 3,
            'primary_category': category.uuid
        })
        page2 = Page({
            'title': 'title 2',
            'language': 'eng_GB',
            'position': 0,
            'primary_category': category.uuid
        })
        page3 = Page({
            'title': 'title 3',
            'language': 'eng_GB',
            'position': 1,
            'primary_category': category.uuid
        })
        page4 = Page({
            'title': 'title 4',
            'language': 'eng_GB',
            'position': 2,
            'primary_category': category.uuid
        })
        self.workspace.save(page1, 'Update position')
        self.workspace.save(page2, 'Update position')
        self.workspace.save(page3, 'Update position')
        self.workspace.save(page4, 'Update position')
        self.workspace.refresh_index()

        request = self.mk_request(matchdict={'category': category.uuid})
        views = CmsViews(request)
        cat = views.category()
        p1, p2, p3, p4 = cat['pages']

        self.assertEqual(p1.uuid, page2.uuid)
        self.assertEqual(p2.uuid, page3.uuid)
        self.assertEqual(p3.uuid, page4.uuid)
        self.assertEqual(p4.uuid, page1.uuid)
예제 #6
0
    def test_search_added_page(self):
        mother_page = Page({
            'title': 'title for mother', 'language': 'eng_GB', 'position': 2,
            'content': 'Page for mother test page'})
        self.workspace.save(mother_page, 'Add mother page')

        self.workspace.refresh_index()

        resp = self.app.get('/search/', params={'q': 'mother'}, status=200)

        self.assertTrue('mother' in resp.body)
        self.assertFalse('No results found' in resp.body)
예제 #7
0
    def test_homepage_page(self):
        self.workspace.setup_custom_mapping(
            Page, {
                'properties': {
                    'slug': {
                        'type': 'string',
                        'index': 'not_analyzed',
                    },
                    'language': {
                        'type': 'string',
                    }
                }
            })
        self.workspace.setup_custom_mapping(
            Localisation, {
                'properties': {
                    'locale': {
                        'type': 'string',
                        'index': 'not_analyzed',
                    }
                }
            })

        self.create_categories(self.workspace, count=1)
        self.create_localisation(
            self.workspace,
            'eng_GB',
            image='some-uuid',
            image_host='http://some.site.com',
        )

        intro_page = Page({
            'title': 'Homepage Intro Title',
            'language': 'eng_GB',
            'description': 'this is the description text',
            'slug': 'homepage-intro',
            'content': 'this is the body of work',
            'position': 0,
            'modified_at': datetime.utcnow().isoformat()
        })
        self.workspace.save(intro_page, 'save intro')
        self.workspace.refresh_index()

        resp = self.app.get('/', status=200)
        self.assertTrue(
            '<img alt="Welcome to the a4w" '
            'src="http://some.site.com/VNlJN07VKnfaB6k1imziAts4n0o='
            '/320x0/some-uuid"/>' in resp.body)

        resp = self.app.get('/?_LOCALE_=eng_UK', status=200)
        self.assertTrue('<a href="/">Home</a>' in resp.body)
예제 #8
0
    def test_homepage_page(self):
        self.create_categories(self.workspace, count=1)

        intro_page = Page({
            'title': 'Homepage Intro Title',
            'language': 'eng_GB',
            'description': 'this is the description text',
            'slug': 'homepage-intro',
            'content': 'this is the body of work',
            'position': 0,
            'modified_at': datetime.utcnow().isoformat()
        })
        self.workspace.save(intro_page, 'save intro')
        self.workspace.refresh_index()

        resp = self.app.get('/', status=200)
        self.assertTrue('<a href="/">Home</a>' in resp.body)
예제 #9
0
 def setUp(self):
     self.request = testing.DummyRequest()
     self.request.route_url = mock.Mock(return_value='content_url')
     self.request.locale_name = 'eng_GB'
     self.request.user = User(None, {
         'uuid': 'user_uuid',
         'app_data': {
             'display_name': 'Foo'
         }
     })
     self.request.session = mock.Mock(get_csrf_token=mock.Mock(
         return_value='csrf_foo'))
     self.request.registry.commentclient = CommentClient(app_id='app_uuid',
                                                         host='host_url')
     self.content_object = Page({
         'uuid': 'content_uuid',
         'title': 'content_title'
     })
     self.form = CommentForm(self.request, self.content_object)