Exemple #1
0
    def test_mapstory_twitter_cards(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 04')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should get a 200 response from the URL
        self.client.login(username=testUser.username, password="******")
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should use the correct template
        self.assertTemplateUsed(response, 'maps/map_detail.html')
        self.assertContains(response, test_mapstory.title)

        # Should have the meta tags included
        soup = BeautifulSoup(response.content, "html.parser")
        card_type = soup.findAll(attrs={"name": "twitter:card"})
        title = soup.findAll(attrs={"name": "twitter:title"})
        description = soup.findAll(attrs={"name": "twitter:description"})
        image = soup.findAll(attrs={"name": "twitter:image"})
        site = soup.findAll(attrs={"name": "twitter:site"})

        # Assert we have the correct values
        self.assertEqual(card_type[0]['content'].encode('utf-8'), "summary")
        self.assertEqual(title[0]['content'].encode(
            'utf-8'), test_mapstory.title)
        self.assertTrue(
            test_mapstory.abstract in description[0]['content'].encode('utf-8'))
        self.assertIsNotNone(image[0]['content'].encode('utf-8'))
        self.assertEqual(site[0]['content'].encode('utf-8'), "@MapStory")
Exemple #2
0
    def test_mapstory_twitter_cards(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 04')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should get a 200 response from the URL
        self.client.login(username=testUser.username, password="******")
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should use the correct template
        self.assertTemplateUsed(response, 'maps/map_detail.html')
        self.assertContains(response, test_mapstory.title)

        # Should have the meta tags included
        soup = BeautifulSoup(response.content, "html.parser")
        card_type = soup.findAll(attrs={"name": "twitter:card"})
        title = soup.findAll(attrs={"name": "twitter:title"})
        description = soup.findAll(attrs={"name": "twitter:description"})
        image = soup.findAll(attrs={"name": "twitter:image"})
        site = soup.findAll(attrs={"name": "twitter:site"})

        # Assert we have the correct values
        self.assertEqual(card_type[0]['content'].encode('utf-8'), "summary")
        self.assertEqual(title[0]['content'].encode('utf-8'),
                         test_mapstory.title)
        self.assertTrue(test_mapstory.abstract in description[0]
                        ['content'].encode('utf-8'))
        self.assertIsNotNone(image[0]['content'].encode('utf-8'))
        self.assertEqual(site[0]['content'].encode('utf-8'), "@MapStory")
Exemple #3
0
    def test_mapstory_details_share_buttons(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 05')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should get a 200 response from the URL
        self.client.login(username=testUser.username, password="******")
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should have the meta tags included
        soup = BeautifulSoup(response.content, "html.parser")
        twitter_icon = soup.findAll("a", {"class": "share-btn twitter"})
        google_icon = soup.findAll("a", {"class": "share-btn google-plus"})
        facebook_icon = soup.findAll("a", {"class": "share-btn facebook"})
        stumble_icon = soup.findAll("a", {"class": "share-btn stumbleupon"})
        reddit_icon = soup.findAll("a", {"class": "share-btn reddit"})
        linkedin_icon = soup.findAll("a", {"class": "share-btn linkedin"})
        email_icon = soup.findAll("a", {"class": "share-btn email"})
        self.assertIsNotNone(twitter_icon[0])
        self.assertIsNotNone(google_icon[0])
        self.assertIsNotNone(facebook_icon[0])
        self.assertIsNotNone(stumble_icon[0])
        self.assertIsNotNone(reddit_icon[0])
        self.assertIsNotNone(linkedin_icon[0])
        self.assertIsNotNone(email_icon[0])
Exemple #4
0
    def test_mapstory_details_share_buttons(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 05')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should get a 200 response from the URL
        self.client.login(username=testUser.username, password="******")
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should have the meta tags included
        soup = BeautifulSoup(response.content, "html.parser")
        twitter_icon = soup.findAll("a", {"class": "share-btn twitter"})
        google_icon = soup.findAll("a", {"class": "share-btn google-plus"})
        facebook_icon = soup.findAll("a", {"class": "share-btn facebook"})
        stumble_icon = soup.findAll("a", {"class": "share-btn stumbleupon"})
        reddit_icon = soup.findAll("a", {"class": "share-btn reddit"})
        linkedin_icon = soup.findAll("a", {"class": "share-btn linkedin"})
        email_icon = soup.findAll("a", {"class": "share-btn email"})
        self.assertIsNotNone(twitter_icon[0])
        self.assertIsNotNone(google_icon[0])
        self.assertIsNotNone(facebook_icon[0])
        self.assertIsNotNone(stumble_icon[0])
        self.assertIsNotNone(reddit_icon[0])
        self.assertIsNotNone(linkedin_icon[0])
        self.assertIsNotNone(email_icon[0])
Exemple #5
0
    def test_post_mapstory_detail_keyword_post(self):
        # Should create add a keyword
        test_mapstory = create_mapstory(testUser, 'Testing Map 02')
        self.client.login(username=testUser.username, password="******")
        response = self.client.post(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}),
            {'add_keyword': 'test_keyword'})
        self.assertEquals(response.status_code, 200)

        # Should remove the keyword
        response = self.client.post(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}),
            {'remove_keyword': 'test_keyword'})

        self.assertEquals(response.status_code, 200)

        # Should handle Keywords form post
        form_data = {
            'keywords': ['testKeyword01', 'testKeyword02', 'testKeyword03']
        }
        form = KeywordsForm(data=form_data)
        self.assertTrue(form.is_valid())
        response = self.client.post(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}),
            form_data)
        self.assertEquals(response.status_code, 200)
Exemple #6
0
    def test_add_mapstory_helper(self):
        test_mapstory = create_mapstory(get_test_user(), 'Testing Map 01')

        initial_count = models.InitiativeMapStory.objects.all().count()
        o = get_initiative()
        membership = models.InitiativeMembership.objects.create(
            user=get_test_user(), initiative=o, is_admin=True)

        self.assertIsNotNone(o.add_mapstory(test_mapstory, membership))
        self.assertEqual(initial_count + 1,
                         models.InitiativeMapStory.objects.all().count())
Exemple #7
0
    def test_add_mapstory_helper(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 01')

        initial_count = models.OrganizationMapStory.objects.all().count()
        o = get_test_organization()
        membership = models.OrganizationMembership.objects.create(
            user=get_test_user(), organization=o, is_admin=True)

        self.assertIsNotNone(o.add_mapstory(test_mapstory, membership))
        self.assertEqual(initial_count + 1,
                         models.OrganizationMapStory.objects.all().count())
Exemple #8
0
    def test_mapstory_actor_streams(self):
        action_list = get_actions_for_model('MapStory')
        initial_count = len(action_list)

        test_utils.create_mapstory(self.user, "Action Mapstory Test")
        final_count = len(action_list)

        # Action count should increase by one
        self.assertTrue(initial_count + 1, final_count)

        stream = actor_stream(self.user)
        self.assertEqual(len(stream), 1)
        self.assertEqual(self.user.id, stream[0].actor.id)

        test_utils.create_mapstory(self.user, "Action Mapstory Test 2")
        stream = actor_stream(self.user)
        self.assertEqual(len(stream), 2)

        # Create another actor and stream
        self.create_user('testactor', 'testactor1232432', is_superuser=False)
        other_user = get_user_model().objects.filter(username='******')[0]
        test_utils.create_mapstory(other_user, "Action Mapstory Test 3")
        other_stream = actor_stream(other_user)
        self.assertEqual(len(other_stream), 1)

        # The other actor's stream should not change
        same_stream = actor_stream(self.user)
        self.assertEqual(len(same_stream), 2)

        c = Collection.objects.create(name='default')
        icon = Icon.objects.create(collection=c, name='icon', owner=self.user)
        same_stream = actor_stream(self.user)
        self.assertEqual(len(same_stream), 3)
Exemple #9
0
    def test_mapstory_actor_streams(self):
        action_list = get_actions_for_model('MapStory')
        initial_count = len(action_list)

        test_utils.create_mapstory(self.user, "Action Mapstory Test")
        final_count = len(action_list)

        # Action count should increase by one
        self.assertTrue(initial_count + 1, final_count)

        stream = actor_stream(self.user)
        self.assertEqual(len(stream), 1)
        self.assertEqual(self.user.id, stream[0].actor.id)

        test_utils.create_mapstory(self.user, "Action Mapstory Test 2")
        stream = actor_stream(self.user)
        self.assertEqual(len(stream), 2)

        # Create another actor and stream
        self.create_user('testactor', 'testactor1232432', is_superuser=False)
        other_user = get_user_model().objects.filter(username='******')[0]
        test_utils.create_mapstory(other_user, "Action Mapstory Test 3")
        other_stream = actor_stream(other_user)
        self.assertEqual(len(other_stream), 1)

        # The other actor's stream should not change
        same_stream = actor_stream(self.user)
        self.assertEqual(len(same_stream), 2)

        c = Collection.objects.create(name='default')
        icon = Icon.objects.create(collection=c, name='icon', owner=self.user)
        same_stream = actor_stream(self.user)
        self.assertEqual(len(same_stream), 3)
Exemple #10
0
 def test_add_mapstory_without_membership(self):
     user = User.objects.create_user(username="******",
                                     password="******")
     o = models.Organization()
     o.title = "Testing"
     o.save()
     mapstory = create_mapstory(user, "Testing Mapstory")
     response = self.client.post(reverse("organizations:add_mapstory",
                                         kwargs={
                                             'slug': o.slug,
                                             'mapstory_pk': mapstory.pk
                                         }), {},
                                 follow=True)
     self.assertEqual(404, response.status_code)
Exemple #11
0
 def test_organization_detail_view_post_add_featured_mapstory(self):
     o = get_initiative()
     u = get_test_user()
     map_created = create_mapstory(u, "Title")
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.InitiativeMembership.objects.create(
         initiative=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("initiatives:detail", kwargs={"slug": o.slug}), data={
         "add_featured_mapstory": "q",
         "layer_pk": layer.pk,
         "mapstory_pk": map_created.pk,
     })
     self.assertEqual(404, r.status_code)
Exemple #12
0
 def test_add_mapstory_without_membership(self):
     user = User.objects.create_user(username="******",
                                     password="******")
     count = models.InitiativeMapStory.objects.all().count()
     o = get_initiative()
     mapstory = create_mapstory(user, "Testing Mapstory")
     response = self.client.post(reverse("initiatives:add_mapstory",
                                         kwargs={
                                             'slug': o.slug,
                                             'mapstory_pk': mapstory.pk
                                         }), {},
                                 follow=True)
     self.assertEqual(200, response.status_code)
     self.assertEqual(count,
                      models.InitiativeMapStory.objects.all().count())
Exemple #13
0
 def test_organization_detail_view_post_add_featured_mapstory(self):
     o = get_test_organization()
     u = get_test_user()
     map_created = create_mapstory(u, "Title")
     layer = create_layer('Test Layer', 'Abstract', u)
     membership = models.OrganizationMembership.objects.create(
         organization=o, user=u)
     o.add_layer(layer, membership)
     r = self.client.post(reverse("organizations:detail",
                                  kwargs={"slug": o.slug}),
                          data={
                              "add_featured_mapstory": "q",
                              "layer_pk": layer.pk,
                              "mapstory_pk": map_created.pk,
                          })
     self.assertEqual(404, r.status_code)
Exemple #14
0
    def test_mapstory_detail_publish_status_form(self):
        # Should not be published yet
        test_mapstory = create_mapstory(testUser, 'Testing Map 03')
        self.assertFalse(test_mapstory.is_published)

        # Send POST
        form_data = {'is_published': True, 'published_submit_btn': True}
        form = PublishStatusForm(data=form_data)
        self.assertTrue(form.is_valid())
        self.client.login(username=testUser.username, password="******")
        response = self.client.post(reverse('mapstory_detail',
                                            kwargs={"slug": test_mapstory.slug}), form_data)
        self.assertEquals(response.status_code, 200)

        # Should be published
        test_mapstory = MapStory.objects.get(id=test_mapstory.id)
        self.assertTrue(test_mapstory.is_published)
Exemple #15
0
    def test_mapstory_detail_view(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 01')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should exist in the database
        found = MapStory.objects.get(id=test_mapstory.id)
        self.assertEquals(found.title, test_mapstory.title)
        self.client.login(username=testUser.username, password="******")
        # Should get a 200 response from the URL
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should use the correct template
        self.assertTemplateUsed(response, 'maps/map_detail.html')
        self.assertContains(response, test_mapstory.title)
Exemple #16
0
    def test_mapstory_detail_view(self):
        test_mapstory = create_mapstory(testUser, 'Testing Map 01')
        self.assertIsNotNone(test_mapstory)
        self.assertIsNotNone(test_mapstory.id)

        # Should exist in the database
        found = MapStory.objects.get(id=test_mapstory.id)
        self.assertEquals(found.title, test_mapstory.title)
        self.client.login(username=testUser.username, password="******")
        # Should get a 200 response from the URL
        response = self.client.get(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}))
        self.assertEquals(response.status_code, 200)

        # Should use the correct template
        self.assertTemplateUsed(response, 'maps/map_detail.html')
        self.assertContains(response, test_mapstory.title)
Exemple #17
0
 def test_add_mapstory_without_membership(self):
     user = User.objects.create_user(
         username="******",
         password="******"
     )
     o = models.Organization()
     o.name = "Testing"
     o.save()
     mapstory = create_mapstory(user, "Testing Mapstory")
     response = self.client.post(
         reverse("organizations:add_mapstory", kwargs={
             'slug': o.slug,
             'mapstory_pk': mapstory.pk
         }),
         {},
         follow=True
     )
     self.assertEqual(404, response.status_code)
Exemple #18
0
    def test_mapstory_detail_publish_status_form(self):
        # Should not be published yet
        test_mapstory = create_mapstory(testUser, 'Testing Map 03')
        self.assertFalse(test_mapstory.is_published)

        # Send POST
        form_data = {'is_published': True, 'published_submit_btn': True}
        form = PublishStatusForm(data=form_data)
        self.assertTrue(form.is_valid())
        self.client.login(username=testUser.username, password="******")
        response = self.client.post(
            reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}),
            form_data)
        self.assertEquals(response.status_code, 200)

        # Should be published
        test_mapstory = MapStory.objects.get(id=test_mapstory.id)
        self.assertTrue(test_mapstory.is_published)
Exemple #19
0
 def test_add_mapstory_without_membership(self):
     user = User.objects.create_user(
         username="******",
         password="******"
     )
     count = models.InitiativeMapStory.objects.all().count()
     o = get_initiative()
     mapstory = create_mapstory(user, "Testing Mapstory")
     response = self.client.post(
         reverse("initiatives:add_mapstory", kwargs={
             'slug': o.slug,
             'mapstory_pk': mapstory.pk
         }),
         {},
         follow=True
     )
     self.assertEqual(200, response.status_code)
     self.assertEqual(
         count, models.InitiativeMapStory.objects.all().count())
Exemple #20
0
    def test_post_mapstory_detail_keyword_post(self):
        # Should create add a keyword
        test_mapstory = create_mapstory(testUser, 'Testing Map 02')
        self.client.login(username=testUser.username, password="******")
        response = self.client.post(reverse('mapstory_detail', kwargs={
                                    "slug": test_mapstory.slug}), {'add_keyword': 'test_keyword'})
        self.assertEquals(response.status_code, 200)

        # Should remove the keyword
        response = self.client.post(reverse('mapstory_detail', kwargs={"slug": test_mapstory.slug}),
                                    {'remove_keyword': 'test_keyword'})

        self.assertEquals(response.status_code, 200)

        # Should handle Keywords form post
        form_data = {'keywords': ['testKeyword01',
                                  'testKeyword02', 'testKeyword03']}
        form = KeywordsForm(data=form_data)
        self.assertTrue(form.is_valid())
        response = self.client.post(reverse('mapstory_detail', kwargs={
                                    "slug": test_mapstory.slug}), form_data)
        self.assertEquals(response.status_code, 200)
Exemple #21
0
    def test_add_mapstory_with_membership(self):
        user = get_test_user()
        self.assertTrue(
            self.client.login(username=user.username,
                              password="******"))
        o = get_test_organization()
        self.assertIsNotNone(o.add_member(user, is_admin=True))
        mapstory = create_mapstory(user, "Testing Mapstory")
        self.assertIsNotNone(mapstory)

        initial_count = models.OrganizationMapStory.objects.filter(
            organization=o).count()
        response = self.client.post(reverse("organizations:add_mapstory",
                                            kwargs={
                                                'slug': o.slug,
                                                'mapstory_pk': mapstory.pk
                                            }), {'data': 'data'},
                                    follow=True)
        self.assertEqual(200, response.status_code)
        # Should have added 1 mapstory to the organization
        final_count = models.OrganizationMapStory.objects.filter(
            organization=o).count()
        self.assertEqual(initial_count + 1, final_count)
Exemple #22
0
    def test_add_mapstory_with_membership(self):
        user = get_test_user()
        self.assertTrue(self.client.login(
            username=user.username, password="******"))
        o = get_initiative()
        self.assertIsNotNone(o.add_member(user, is_admin=True))
        mapstory = create_mapstory(user, "Testing Mapstory")
        self.assertIsNotNone(mapstory)

        initial_count = models.InitiativeMapStory.objects.filter(
            initiative=o).count()
        response = self.client.post(
            reverse("initiatives:add_mapstory", kwargs={
                'slug': o.slug,
                'mapstory_pk': mapstory.pk
            }),
            {'data': 'data'},
            follow=True
        )
        self.assertEqual(200, response.status_code)
        # Should have added 1 mapstory to the initiative
        final_count = models.InitiativeMapStory.objects.filter(
            initiative=o).count()
        self.assertEqual(initial_count + 1, final_count)