Beispiel #1
0
def test_more_relevant_should_come_first():
    second = ContentFactory(title="About music and music")
    third = ContentFactory(title="About music")
    first = ContentFactory(title="About music and music but also music")
    assert Content.objects.count() == 3
    assert first == list(Search.search(text__match="music"))[0]
    assert second == list(Search.search(text__match="music"))[1]
    assert third == list(Search.search(text__match="music"))[2]
Beispiel #2
0
def test_tag_cloud_should_return_most_common_tags():
    ContentFactory(tags=['plane', 'boat'])
    ContentFactory(tags=['plane', 'bike'])
    ContentFactory(tags=['plane', 'boat'])
    context = tag_cloud('xxxx', limit=2)
    tags = [t.name for t in context['tags']]
    assert tags[0] == 'plane'
    assert tags[1] == 'boat'
Beispiel #3
0
def test_by_tag_page_should_be_filtered_by_tag(app):
    plane = ContentFactory(status=Content.PUBLISHED, tags=['plane'])
    boat = ContentFactory(status=Content.PUBLISHED, tags=['boat'])
    plane2 = BookSpecimenFactory(book__tags=['plane'])
    boat2 = BookSpecimenFactory(book__tags=['boat'])
    response = app.get(reverse('by_tag', kwargs={'tag': 'plane'}))
    assert plane.title in response.content
    assert plane2.book.title in response.content
    assert boat.title not in response.content
    assert boat2.book.title not in response.content
Beispiel #4
0
def test_by_tag_page_is_paginated(app, monkeypatch):
    monkeypatch.setattr(ByTag, 'paginate_by', 2)
    ContentFactory.create_batch(size=2, status=Content.PUBLISHED,
                                tags=['plane'])
    BookSpecimenFactory.create_batch(size=2, book__tags=['plane'])
    url = reverse('by_tag', kwargs={'tag': 'plane'})
    response = app.get(url)
    assert response.pyquery.find('.pagination')
    assert response.pyquery.find('.next')
    assert not response.pyquery.find('.previous')
    response = app.get(url + '?page=2')
    assert response.pyquery.find('.pagination')
    assert not response.pyquery.find('.next')
    assert response.pyquery.find('.previous')
    response = app.get(url + '?page=3', status=404)
Beispiel #5
0
def test_tag_cloud_should_be_filtered_by_model_if_given():
    ContentFactory(tags=['plane', 'boat'])
    BookFactory(tags=['bike', 'boat'])
    context = tag_cloud('xxxx', limit=2, model=Content)
    assert [t.name for t in context['tags']] == ['boat', 'plane']
    context = tag_cloud('xxxx', limit=2, model=Book)
    assert [t.name for t in context['tags']] == ['bike', 'boat']
Beispiel #6
0
def test_by_tag_page_is_paginated(app, monkeypatch):
    monkeypatch.setattr(ByTag, 'paginate_by', 2)
    ContentFactory.create_batch(size=2,
                                status=Content.PUBLISHED,
                                tags=['plane'])
    BookSpecimenFactory.create_batch(size=2, book__tags=['plane'])
    url = reverse('by_tag', kwargs={'tag': 'plane'})
    response = app.get(url)
    assert response.pyquery.find('.pagination')
    assert response.pyquery.find('.next')
    assert not response.pyquery.find('.previous')
    response = app.get(url + '?page=2')
    assert response.pyquery.find('.pagination')
    assert not response.pyquery.find('.next')
    assert response.pyquery.find('.previous')
    response = app.get(url + '?page=3', status=404)
Beispiel #7
0
def test_search_view_should_return_mixed_content(app):
    content = ContentFactory(title='test content', status=Content.PUBLISHED)
    book = BookFactory(title='test book')
    form = app.get(reverse('search:search')).forms['search']
    form['q'] = 'test'
    page = form.submit()
    assert content.title in page.content
    assert book.title in page.content
Beispiel #8
0
def test_search_view_should_not_return_deleted_to_staff_user(staffapp):
    content = ContentFactory(title='test content', status=Content.DELETED)
    form = staffapp.get(reverse('search:search')).forms['search']
    form['q'] = 'test'
    page = form.submit()
    assert content.title in page.content
Beispiel #9
0
def test_search_view_should_not_return_draft_content_to_logged_user(loggedapp):
    content = ContentFactory(title='test content', status=Content.DRAFT)
    form = loggedapp.get(reverse('search:search')).forms['search']
    form['q'] = 'test'
    page = form.submit()
    assert content.title not in page.content
Beispiel #10
0
def test_search_view_should_show_results(app):
    content = ContentFactory(title='test content', status=Content.PUBLISHED)
    form = app.get(reverse('search:search')).forms['search']
    form['q'] = 'test'
    page = form.submit()
    assert content.title in page.content
Beispiel #11
0
def test_theme_slug_for_content():
    content = ContentFactory()
    assert theme_slug(content) == '<span class="theme create">blog</span>'
Beispiel #12
0
def test_we_can_search_on_non_fts_fields_only():
    content = ContentFactory(title="music")
    assert content in Search.search(public=False)
Beispiel #13
0
def test_ids_only_returns_ids():
    content = ContentFactory(title="music")
    assert content.pk in Search.ids(text__match="music")
Beispiel #14
0
def test_searchable_model_is_indexed():
    assert Content.objects.count() == 0
    content = ContentFactory(title="music")
    assert Content.objects.count() == 1
    assert content in Search.search(text__match="music")
Beispiel #15
0
    def handle(self, *args, **options):
        if not settings.DEBUG:
            msg = ('This does not seem to be a dev project. Aborting. You need'
                   ' to be in DEBUG=True')
            raise CommandError(msg)

        # Create some users.
        staff = UserFactory(short_name='Amelia',
                            serial='123456',
                            password='******',
                            is_staff=True)
        UserFactory(short_name='Amy', password='******')
        UserFactory(short_name='Touria', password='******')

        # Create some blog content.
        text = ('The last voice transmission received on Howland Island from '
                'Earhart indicated she and Noonan were flying along a line of '
                'position (taken from a "sun line" running on 157-337 degrees)'
                ' which Noonan would have calculated and drawn on a chart as '
                'passing through Howland. After all contact was lost with '
                'Howland Island, attempts were made to reach the flyers with '
                'both voice and Morse code transmissions. Operators across the'
                ' Pacific and the United States may have heard signals from '
                'the downed Electra but these were unintelligible or weak')
        ContentFactory(
            title='1937 world flight',
            text=text,
            summary=text,
            status=Content.PUBLISHED,
            author=staff,
            tags=['plane', 'aviation'],
            image__from_path='ideasbox/tests/data/amelia-earhart.jpg')  # noqa
        ContentFactory(title='This is another article with a longer title',
                       text=text,
                       summary=text,
                       status=Content.PUBLISHED,
                       author=staff,
                       image=None)
        title = ('The Untold Story of Thirteen American Women and the Dream '
                 'of Space Flight')
        ContentFactory(title=title,
                       text=text,
                       summary=text,
                       status=Content.PUBLISHED,
                       author=staff,
                       tags=['plane', 'aviation', 'record'],
                       image__from_path='ideasbox/tests/data/plane.jpg')
        ContentFactory(title='This is a draft content',
                       text=text,
                       status=Content.DRAFT,
                       author=staff,
                       image=None)
        ContentFactory(title='This is a deleted content',
                       text=text,
                       status=Content.DELETED,
                       author=staff,
                       image=None)

        # Create some books.
        summary = ("If one chanced to examine the catalogues of Kingsbridge "
                   "College for the past hundred years it would be found that "
                   "in most of them is recorded the name of some dead and "
                   "gone Deering-a name famous in the annals of the South-who "
                   "came up from Louisiana, 'marched through the four long "
                   "happy years of college,' as the old song has it, with an "
                   "arts degree to his credit; or, perchance, marched out at "
                   "the end of one or two of them with nothing to his credit "
                   "at all. Kingsbridge was a tradition in the Deering "
                   "family, southern though it was-a tradition that was "
                   "hardly broken, even when in 1861 Victor Deering and a "
                   "hundred other chivalrous youths threw their text-books "
                   "out of the windows and enlisted in the armies of the "
                   "Confederacy. Victor's father, Basil, too, was in the "
                   "war, and laid down his arms at Appomattox as a "
                   "brigadier-general-brevetted for gallantry on the field of "
                   "action. For a while it seemed that no Deerings would go "
                   "to Kingsbridge, but time at length healed the old "
                   "antagonisms, and when it became a question where young "
                   "Anthony, Victor's boy, should go to[2] college, there was "
                   "no longer any question that Kingsbridge should be the "
                   "place.")
        path = 'ideasbox/tests/data/deering-of-deal.jpg'
        book = BookFactory(title='Deering of Deal',
                           summary=summary,
                           subtitle='The Spirit of the School',
                           authors=u'Latta Griswold',
                           lang='en',
                           cover__from_path=path,
                           tags=['plane', 'aviation'])
        BookSpecimenFactory(book=book, serial="1234567")
        summary = (u"Le roman raconte les aventures d'un Gascon impécunieux "
                   u"de 18 ans, d'Artagnan, venu à Paris pour faire carrière "
                   u"dans le corps des mousquetaires. Il se lie d'amitié avec "
                   u"Athos, Porthos et Aramis, mousquetaires du roi Louis "
                   u"XIII. Ces quatre hommes vont s'opposer au premier "
                   u"ministre, le cardinal de Richelieu et à ses agents, dont "
                   u"le comte de Rochefort et la belle et mystérieuse Milady "
                   u"de Winter, pour sauver l'honneur de la reine de France "
                   u"Anne d'Autriche.")
        path = 'ideasbox/tests/data/les-trois-mousquetaires.jpg'
        book = BookFactory(title='Les Trois Mousquetaires',
                           summary=summary,
                           authors=u'Alexandre Dumas',
                           lang='fr',
                           cover__from_path=path,
                           tags=['roman', 'aventure'])
        BookSpecimenFactory(book=book, serial="98765479")
        summary = ("With the title of Sense and Sensibility is connected one "
                   "of those minor problems which delight the cummin-splitters"
                   " of criticism. In the Cecilia of Madame D'Arblay-the "
                   "forerunner, if not the model, of Miss Austen-is a "
                   "sentence which at first sight suggests some relationship "
                   "to the name of the book which, in the present series, "
                   "inaugurated Miss Austen's novels. 'The whole of this "
                   "unfortunate business'-says a certain didactic Dr. Lyster, "
                   "talking in capitals, towards the end of volume three of "
                   "Cecilia-'has been the result of Pride and Prejudice,' and "
                   "looking to the admitted familiarity of Miss Austen with "
                   "Madame D'Arblay's work, it has been concluded that Miss "
                   "Austen borrowed from Cecilia, the title of her second "
                   "novel.")
        path = 'ideasbox/tests/data/sense-and-sensibility.jpg'
        book = BookFactory(title='Sense and Sensibility',
                           summary=summary,
                           authors=u'Jane Austen',
                           lang='en',
                           cover__from_path=path,
                           tags=['19th-century'])
        BookSpecimenFactory(book=book, serial="32657324")
        summary = (u"النبي (1923) أشهر كتب جبران كتبه بالإنجليزية وترجم إلى "
                   u"أكثر من خمسين لغة، وهو يعتبر بحق رائعة جبران العالمية، "
                   u"مضمونه اجتماعي، مثالي وتأملي فلسفي، وهو يحوي خلاصة "
                   u"الاراء الجبرانية في الحب والزواج والأولاد والبيوت "
                   u"والثياب والبيع والشراء والحرية والثانون والرحمة والعقاب "
                   u"والدين والأخلاق والحياة والموت واللذة والجمال والكرم "
                   u"والشرائع وغيرها، وقد وردت على لسان نبي سمي المصطفى "
                   u"ورسالة النبي رسالة المتصوف المؤمن بوحدة الوجود، وبأن "
                   u"الروح تتعطش للعودة إلى مصدرها، وبأن الحب جوهر الحياة. "
                   u"وفي كتاب النبي يعبر جبران عن آرائه في الحياة عن طريق "
                   u"معالجته للعلاقات الإنسانية التي تربط الإنسان بالإنسان.")
        path = 'ideasbox/tests/data/the-prophet.jpg'
        book = BookFactory(title=u'النبي (كتاب)',
                           summary=summary,
                           authors=u'جبران خليل جبران',
                           lang='ar',
                           cover__from_path=path)
        BookSpecimenFactory(book=book, serial="3213542")
        title = (u"Déclaration des droits de l'homme et du citoyen "
                 u"du 26 août 1789")
        summary = (u"Les Représentants du Peuple Français, constitués en "
                   u"Assemblée Nationale, considérant que l'ignorance, "
                   u"l'oubli ou le mépris des droits de l'Homme sont les "
                   u"seules causes des malheurs publics et de la corruption "
                   u"des Gouvernements, ont résolu d'exposer, dans une "
                   u"Déclaration solennelle, les droits naturels, "
                   u"inaliénables et sacrés de l'Homme, afin que cette "
                   u"Déclaration, constamment présente à tous les Membres du "
                   u"corps social, leur rappelle sans cesse leurs droits et "
                   u"leurs devoirs ; afin que leurs actes du pouvoir "
                   u"législatif, et ceux du pouvoir exécutif, pouvant être à "
                   u"chaque instant comparés avec le but de toute institution "
                   u"politique, en soient plus respectés ; afin que les "
                   u"réclamations des citoyens, fondées désormais sur des "
                   u"principes simples et incontestables, tournent toujours "
                   u"au maintien de la Constitution et au bonheur de tous.")
        path = 'ideasbox/tests/data/declaration-1789.pdf'
        DocumentFactory(title=title,
                        original__from_path=path,
                        summary=summary,
                        tags=['history', 'France'])
        path = 'ideasbox/tests/data/amelia-earhart.jpg'
        DocumentFactory(title="Picture of Amelia Earhart",
                        original__from_path=path,
                        tags=['plane', 'aviation'])
        self.stdout.write('Done.')