def test_translated_yourwords_competition_page_exists(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        self.client.post(reverse(
            'add_translation', args=[comp.id, 'fr']))
        page = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        page.save_revision().publish()

        response = self.client.get(reverse(
            'wagtailadmin_explore', args=[self.competition_index.id]))
        page = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        self.assertContains(response,
                            '<a href="/admin/pages/%s/edit/"'
                            % page.id)
    def test_translated_competition_entry_stored_against_the_main_lang(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        en_comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=en_comp)
        en_comp.save_revision().publish()

        self.client.post(reverse(
            'add_translation', args=[en_comp.id, 'fr']))
        fr_comp = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        fr_comp.save_revision().publish()

        self.client.post(
            reverse('molo.yourwords:competition_entry', args=[fr_comp.slug]), {
                'story_name': 'this is a french story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})

        entry = YourWordsCompetitionEntry.objects.all().first()
        self.assertEqual(entry.story_name, 'this is a french story')
        self.assertEqual(entry.competition.id, en_comp.id)
    def test_yourwords_wagtail_entries_view(self):

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True
        )

        entry = YourWordsCompetitionEntry.objects.all().first()

        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        response = self.client.get(
            '/admin/yourwords/yourwordscompetitionentry/'
        )

        self.assertContains(response, entry.story_name)
    def test_download_as_csv(self):
        self.client.login(username=self.superuser_name,
                          password=self.superuser_password)

        comp = YourWordsCompetition(title='Test Competition',
                                    description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True)
        response = download_as_csv(YourWordsCompetitionEntryAdmin, None,
                                   YourWordsCompetitionEntry.objects.all())
        date = str(datetime.datetime.now().date())
        expected_output = ('id,competition,submission_date,user,story_name,'
                           'story_text,terms_or_conditions_approved,'
                           'hide_real_name,is_read,is_shortlisted,'
                           'is_winner,article_page\r\n1,'
                           'Test Competition,' + date + ''
                           ',superuser,test,test body,'
                           'True,True,False,False,False,\r\n')
        self.assertContains(response, expected_output)
Пример #5
0
    def test_translated_competition_entry_stored_against_the_main_lang(self):
        client = Client()
        client.login(username='******', password='******')

        en_comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=en_comp)
        en_comp.save_revision().publish()

        self.client.post(reverse(
            'add_translation', args=[en_comp.id, 'fr']))
        fr_comp = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        fr_comp.save_revision().publish()

        client.post(
            reverse('molo.yourwords:competition_entry', args=[fr_comp.slug]), {
                'story_name': 'this is a french story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})

        entry = YourWordsCompetitionEntry.objects.all().first()
        self.assertEqual(entry.story_name, 'this is a french story')
        self.assertEqual(entry.competition.id, en_comp.id)
Пример #6
0
    def test_download_as_csv(self):
        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True
        )
        client = Client()
        client.login(username='******', password='******')
        response = download_as_csv(YourWordsCompetitionEntryAdmin,
                                   None,
                                   YourWordsCompetitionEntry.objects.all())
        date = str(datetime.datetime.now().date())
        expected_output = ('Content-Type: text/csv\r\nContent-Disposition:'
                           ' attachment;filename=export.csv\r\n\r\nid,'
                           'competition,submission_date,user,story_name,'
                           'story_text,terms_or_conditions_approved,'
                           'hide_real_name,is_read,is_shortlisted,'
                           'is_winner,article_page\r\n1,Test Competition,' +
                           date + ',superuser,test,test body,'
                           'True,True,False,False,False,\r\n')
        self.assertEquals(str(response), expected_output)
    def test_yourwords_validation_for_fields(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        comp = YourWordsCompetition.objects.get(slug='test-competition')

        self.client.get(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]))

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]),
            {'story_name': 'this is a story'})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]),
            {'story_name': 'This is a story', 'story_text': 'The text'})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(YourWordsCompetitionEntry.objects.all().count(), 1)

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true',
                'hide_real_name': 'true'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(YourWordsCompetitionEntry.objects.all().count(), 2)
Пример #8
0
    def test_yourwords_validation_for_fields(self):
        client = Client()
        client.login(username='******', password='******')

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        comp = YourWordsCompetition.objects.get(slug='test-competition')

        client.get(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]))

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]),
            {'story_name': 'this is a story'})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]),
            {'story_name': 'This is a story', 'story_text': 'The text'})
        self.assertEquals(response.status_code, 200)
        self.assertContains(response, 'This field is required')

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(YourWordsCompetitionEntry.objects.all().count(), 1)

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true',
                'hide_real_name': 'true'})
        self.assertEquals(response.status_code, 302)
        self.assertEquals(YourWordsCompetitionEntry.objects.all().count(), 2)
Пример #9
0
    def test_export_csv(self):
        self.client.login(username=self.superuser_name,
                          password=self.superuser_password)

        comp = YourWordsCompetition(title='Test Competition',
                                    description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        comp2 = YourWordsCompetition(title='Test Competition2',
                                     description='This is the description2')
        self.competition_index_main2.add_child(instance=comp2)
        comp2.save_revision().publish()

        YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True)
        YourWordsCompetitionEntry.objects.create(
            competition=comp2,
            user=self.user,
            story_name='test2',
            story_text='test body2',
            terms_or_conditions_approved=True,
            hide_real_name=True)

        response = self.client.post('/admin/yourwords/'
                                    'yourwordscompetitionentry/')

        date = str(datetime.datetime.now().date())

        expected_output = (
            'country,competition,submission_date,user,story_name,story_text,'
            'terms_or_conditions_approved,hide_real_name,is_read,'
            'is_shortlisted,is_winner\r\n'
            'Main,{0},{1},1,test,test body,1,1,0,0,0'.format(comp.pk, date))
        self.assertContains(response, expected_output)

        client = Client(HTTP_HOST=self.site2.hostname)
        client.login(username=self.superuser_name,
                     password=self.superuser_password)
        response = client.post('/admin/login/', {
            'username': '******',
            'password': '******'
        })
        response = client.post('/admin/yourwords/yourwordscompetitionentry/')

        date = str(datetime.datetime.now().date())

        expected_output = (
            'country,competition,submission_date,user,story_name,story_text,'
            'terms_or_conditions_approved,hide_real_name,is_read,'
            'is_shortlisted,is_winner\r\n'
            'Main,{0},{1},1,test2,test body2,1,1,0,0,0'.format(comp2.pk, date))
        self.assertContains(response, expected_output)
Пример #10
0
    def test_yourwords_competition_page(self):
        client = Client()
        client.login(username='******', password='******')

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        comp = YourWordsCompetition.objects.get(slug='test-competition')

        response = client.get('/Your-words-competition/test-competition/')
        self.assertContains(response, 'Test Competition')
        self.assertContains(response, 'This is the description')
    def test_convert_to_article(self):
        self.client.login(username=self.superuser_name,
                          password=self.superuser_password)

        comp = YourWordsCompetition(title='Test Competition',
                                    description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        entry = YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True)

        response = self.client.get(
            '/django-admin/yourwords/yourwordscompetitionentry/%d/convert/' %
            entry.id)
        article = ArticlePage.objects.get(title='test')
        entry = YourWordsCompetitionEntry.objects.get(pk=entry.pk)
        self.assertEquals(entry.story_name, article.title)
        self.assertEquals(entry.article_page, article)
        self.assertEquals(
            article.body.stream_data,
            [{
                u'type': u'paragraph',
                u'id': entry.article_page.body.stream_data[0]['id'],
                u'value': u'Written by: Anonymous'
            }, {
                "type": "paragraph",
                u'id': entry.article_page.body.stream_data[1]['id'],
                "value": entry.story_text
            }])

        self.assertEquals(ArticlePage.objects.all().count(), 1)
        self.assertEquals(response['Location'],
                          '/admin/pages/%d/move/' % article.id)

        # second time it should redirect to the edit page
        response = self.client.get(
            '/django-admin/yourwords/yourwordscompetitionentry/%d/convert/' %
            entry.id)
        self.assertEquals(response['Location'],
                          '/admin/pages/%d/edit/' % article.id)
        self.assertEquals(ArticlePage.objects.all().count(), 1)
    def test_yourwords_wagtail_competition_view(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        response = self.client.get(
            '/admin/yourwords/yourwordscompetition/'
        )

        self.assertContains(response, comp.title)
Пример #13
0
    def test_yourwords_thank_you_page(self):
        client = Client()
        client.login(username='******', password='******')

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        response = client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})
        self.assertEqual(
            response['Location'],
            '/yourwords/thankyou/test-competition/')
    def test_yourwords_competition_page(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()
        self.competition_index.save()

        comp = YourWordsCompetition.objects.get(slug='test-competition')

        response = self.client.get(comp.url)
        self.assertContains(response, 'Test Competition')
        self.assertContains(response, 'This is the description')
Пример #15
0
    def test_convert_to_article(self):
        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        entry = YourWordsCompetitionEntry.objects.create(
            competition=comp,
            user=self.user,
            story_name='test',
            story_text='test body',
            terms_or_conditions_approved=True,
            hide_real_name=True
        )
        client = Client()
        client.login(username='******', password='******')
        response = client.get(
            '/django-admin/yourwords/yourwordscompetitionentry/%d/convert/' %
            entry.id)
        article = ArticlePage.objects.get(title='test')
        entry = YourWordsCompetitionEntry.objects.get(pk=entry.pk)
        self.assertEquals(entry.story_name, article.title)
        self.assertEquals(entry.article_page, article)
        self.assertEquals(article.body.stream_data, [{
            "type": "paragraph", "value": "Written by: Anonymous",
            "type": "paragraph", "value": entry.story_text,
        }])

        self.assertEquals(ArticlePage.objects.all().count(), 1)
        self.assertEquals(
            response['Location'],
            '/admin/pages/%d/move/' % article.id)

        # second time it should redirect to the edit page
        response = client.get(
            '/django-admin/yourwords/yourwordscompetitionentry/%d/convert/' %
            entry.id)
        self.assertEquals(
            response['Location'],
            '/admin/pages/%d/edit/' % article.id)
        self.assertEquals(ArticlePage.objects.all().count(), 1)
    def test_translated_yourwords_competition_page_exists_section(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        section = self.mk_section(
            SectionIndexPage.objects.child_of(self.main).first(),
            title='test-section',
            slug='test-section',
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')

        section.add_child(instance=comp)
        comp.save_revision().publish()

        self.client.post(reverse(
            'add_translation', args=[comp.id, 'fr']))
        page = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        page.save_revision().publish()

        response = self.client.get(section.url)
        self.assertContains(response, 'Test Competition')
        self.assertContains(response, 'This is the description')

        response = self.client.get('/')
        self.assertContains(response, 'Test Competition')
        self.assertContains(response, 'This is the description')

        self.client.get('/locale/fr/')

        response = self.client.get(section.url)
        self.assertContains(response, page.title)

        response = self.client.get('/')
        self.assertContains(response, page.title)
    def test_yourwords_thank_you_page(self):
        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        response = self.client.post(
            reverse('molo.yourwords:competition_entry', args=[comp.slug]), {
                'story_name': 'This is a story',
                'story_text': 'The text',
                'terms_or_conditions_approved': 'true'})
        self.assertEqual(
            response['Location'],
            '/yourwords/thankyou/test-competition/')
Пример #18
0
    def test_translated_yourwords_competition_page_exists(self):
        client = Client()
        client.login(username='******', password='******')

        comp = YourWordsCompetition(
            title='Test Competition',
            description='This is the description',
            slug='test-competition')
        self.competition_index.add_child(instance=comp)
        comp.save_revision().publish()

        self.client.post(reverse(
            'add_translation', args=[comp.id, 'fr']))
        page = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        page.save_revision().publish()

        response = self.client.get(reverse(
            'wagtailadmin_explore', args=[self.competition_index.id]))
        page = YourWordsCompetition.objects.get(
            slug='french-translation-of-test-competition')
        self.assertContains(response,
                            '<a href="/admin/pages/%s/edit/"'
                            % page.id)
    def test_competition_multisite(self):
        section = self.mk_section(
            SectionIndexPage.objects.child_of(self.main).first(),
            title='test-section',
            slug='test-section',
        )

        comp = YourWordsCompetition(
            title='Test Competition Main1',
            description='This is the description')
        section.add_child(instance=comp)
        comp.save_revision().publish()

        section_main2 = self.mk_section(
            SectionIndexPage.objects.child_of(self.main2).first(),
            title='test-section',
            slug='test-section',
        )
        comp_main2 = YourWordsCompetition(
            title='Test Competition Main2',
            description='This is the description')
        section_main2.add_child(instance=comp_main2)
        comp_main2.save_revision().publish()

        self.assertEquals(2, SectionPage.objects.count())

        self.client.login(
            username=self.superuser_name,
            password=self.superuser_password
        )
        response = self.client.get(section.url)
        self.assertContains(response, 'Test Competition Main1')
        self.assertNotContains(response, 'Test Competition Main2')

        self.client2.login(
            username=self.superuser_name,
            password=self.superuser_password
        )
        response = self.client2.get(section_main2.url)

        self.assertContains(response, 'Test Competition Main2')
        self.assertNotContains(response, 'Test Competition Main1')