Esempio n. 1
0
    def test__widgets__list__ok(self):
        widget = factories.WidgetConfigurationFactory(site=self.site)
        factories.WidgetConfigurationFactory(site=widget.site)
        factories.WidgetConfigurationFactory(
        )  # widget configuration of another user

        request = self.factory.get(self.path)
        self._authenticate_request(request, user=self.site.user)
        response = views.WidgetListCreateView.as_view()(request,
                                                        site_pk=self.site.pk)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data.__len__(), 2)
Esempio n. 2
0
    def test__widget_detail__update_buttons_plus(self, cache):
        site = factories.SiteFactory()
        widget = factories.WidgetConfigurationFactory(site=site)

        factories.FacebookWidgetButtonFactory(order=0,
                                              configuration=widget,
                                              is_extra_button=False)
        factories.GoogleWidgetButtonFactory(order=1,
                                            configuration=widget,
                                            is_extra_button=False)
        data = {
            'name':
            'New title',
            'type':
            constants.WIDGET_CONFIGURATION_SHARING_BUTTONS,
            'extra_button_animation':
            False,
            'orientation':
            constants.BUTTON_ORIENTATION_VERTICAL,
            'button_size':
            constants.BUTTON_SIZE_SMALL,
            'button_style':
            constants.BUTTON_STYLE_ICON,
            'counter_position':
            constants.COUNTER_POSITION_TOP,
            'is_active':
            True,
            'has_link_share_button':
            False,
            'buttons': [{
                'service': 'googlePlus',
                'is_extra_button': True,
                'is_short_link': True,
                'text': 'Google+',
                'has_counter': True,
                'follow_url': ''
            }, {
                'service': 'facebook',
                'is_extra_button': True,
                'is_short_link': True,
                'text': 'Facebook',
                'has_counter': True,
                'follow_url': ''
            }]
        }
        request = self.factory.patch(
            reverse('accounts_widget_detail', args=[site.pk, widget.pk]), data)
        self._authenticate_request(request, user=widget.site.user)

        response = views.WidgetRetrieveUpdateView.as_view()(
            request, site_pk=site.pk, widget_pk=widget.pk)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        expected = data.copy()
        expected['id'] = widget.pk
        expected['vanity_domain'] = ''
        expected['position'] = ''
        self.assertDictEqual(response.data, expected)
        cache.delete.assert_called_with(dict(site_id=site.pk))
        self.assertEqual(cache.delete.call_count, 1)
Esempio n. 3
0
    def test__site_detail__update(self, cache):
        site = factories.SiteFactory()
        widget_configuration = factories.WidgetConfigurationFactory()

        data_set = [
            dict(domain='new_site_detail.com'),
            dict(social_urls=[{
                'service': 'facebook',
                'url': 'http://fb.test.com'
            }]),
            dict(address_bar_sharing=True,
                 widget_configurations=[widget_configuration.pk]),
        ]

        for data in data_set:
            request = self.factory.patch(reverse('accounts_site_detail',
                                                 args=[site.pk]),
                                         data=data)
            self._authenticate_request(request, user=site.user)

            response = views.SiteRetrieveUpdateView.as_view()(request,
                                                              pk=site.pk)

            self.assertEqual(response.status_code, status.HTTP_200_OK,
                             response.data)
            fresh_site = models.Site.objects.get(pk=site.pk)
            self.assertDictEqual(response.data,
                                 serializers.SiteSerializer(fresh_site).data,
                                 msg=data)

        cache.delete.assert_called_with(dict(site_id=site.pk))
        self.assertEqual(cache.delete.call_count, 3)
Esempio n. 4
0
    def test__newsletter_widget_detail__update_media_url(self, cache):
        site = factories.SiteFactory()
        widget = factories.WidgetConfigurationFactory(
            site=site, type=constants.WIDGET_CONFIGURATION_NEWSLETTER)

        factories.FacebookWidgetButtonFactory(order=0, configuration=widget)
        factories.GoogleWidgetButtonFactory(order=1, configuration=widget)
        data = {
            'buttons': [{
                'service': 'twitter',
                'is_extra_button': True
            }, {
                'service': 'facebook',
                'is_extra_button': True
            }, {
                'service': 'pinterest',
                'is_extra_button': True
            }],
            'media_url':
            'http://test.com'
        }
        request = self.factory.patch(
            reverse('accounts_widget_detail', args=[site.pk, widget.pk]), data)
        self._authenticate_request(request, user=widget.site.user)

        response = views.WidgetRetrieveUpdateView.as_view()(
            request, site_pk=site.pk, widget_pk=widget.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['media_url'], 'http://test.com')
        cache.delete.assert_called_with(dict(site_id=site.pk))
        self.assertEqual(cache.delete.call_count, 1)

        # data without pinterest social service
        data = {
            'buttons': [{
                'service': 'twitter',
                'is_extra_button': True
            }],
            'media_url': 'http://test.com'
        }
        request = self.factory.patch(
            reverse('accounts_widget_detail', args=[site.pk, widget.pk]), data)
        self._authenticate_request(request, user=widget.site.user)

        response = views.WidgetRetrieveUpdateView.as_view()(
            request, site_pk=site.pk, widget_pk=widget.pk)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['media_url'], 'http://test.com')
        cache.delete.assert_called_with(dict(site_id=site.pk))
        self.assertEqual(cache.delete.call_count, 2)
Esempio n. 5
0
    def test__widget_detail__unauthorized(self):
        site = factories.SiteFactory()
        widget = factories.WidgetConfigurationFactory(site=site)

        request = self.factory.get(
            reverse('accounts_widget_detail', args=[site.pk, widget.pk]))
        # self._authenticate_request(request)

        response = views.WidgetRetrieveUpdateView.as_view()(
            request, site_pk=site.pk, widget_pk=widget.pk)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
        self.assertDictEqual(
            response.data,
            {'detail': 'Authentication credentials were not provided.'})
Esempio n. 6
0
    def test__widget_detail__update_buttons_with_duplicates(self):
        site = factories.SiteFactory()
        widget = factories.WidgetConfigurationFactory(site=site)

        data = {'buttons': [{'service': 'facebook'}, {'service': 'facebook'}]}
        request = self.factory.patch(
            reverse('accounts_widget_detail', args=[site.pk, widget.pk]), data)
        self._authenticate_request(request, user=widget.site.user)

        response = views.WidgetRetrieveUpdateView.as_view()(
            request, site_pk=site.pk, widget_pk=widget.pk)

        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data['buttons'],
            ['Service must be unique for the widget configuration.'])
Esempio n. 7
0
 def test__all_widgets(self):
     all_widgets = (
         (constants.WIDGET_CONFIGURATION_SHARING_BUTTONS,
          models.SharingButtonsWidget),
         (constants.WIDGET_CONFIGURATION_COPY_PASTE,
          models.CopyPasteWidget),
         (constants.WIDGET_CONFIGURATION_NEWSLETTER,
          models.NewsletterWidget),
         (constants.WIDGET_CONFIGURATION_MOBILE, models.MobileWidget),
         (constants.WIDGET_CONFIGURATION_FOLLOW, models.FollowWidget),
     )
     for widget_type, class_instance in all_widgets:
         site = factories.SiteFactory()
         class_instance.objects.all().delete()
         for i in range(5):
             factories.WidgetConfigurationFactory(site=site,
                                                  type=widget_type)
         # Check it from the object's manager
         self.assertEqual(class_instance.objects.all().count(), 5)
Esempio n. 8
0
    def test__widget_detail__get(self):
        serializers_map = {
            'sharing-buttons': serializers.SharingButtonsWidgetSerializer,
            'copy-paste': serializers.CopyPasteWidgetSerializer,
            'newsletter': serializers.NewsletterWidgetSerializer
        }

        for widget_type, serializer in serializers_map.items():
            site = factories.SiteFactory()
            widget = factories.WidgetConfigurationFactory(site=site,
                                                          type=widget_type)

            request = self.factory.get(
                reverse('accounts_widget_detail', args=[site.pk, widget.pk]))
            self._authenticate_request(request, user=widget.site.user)

            response = views.WidgetRetrieveUpdateView.as_view()(
                request, site_pk=site.pk, widget_pk=widget.pk)

            self.assertEqual(response.status_code, status.HTTP_200_OK)
            self.assertDictEqual(response.data, serializer(widget).data)
Esempio n. 9
0
    def test__widget_detail__update(self, cache):
        site = factories.SiteFactory()
        widget = factories.WidgetConfigurationFactory(site=site)

        data_set = [
            dict(name='new_widget_configuration_title'),
            dict(buttons=[{
                'service': 'facebook',
                'is_extra_button': True
            }, {
                'service': 'twitter',
                'is_extra_button': False
            }]),
            dict(orientation=constants.BUTTON_ORIENTATION_VERTICAL),
            dict(is_active=False),
        ]

        for data in data_set:
            request = self.factory.patch(reverse('accounts_widget_detail',
                                                 args=[site.pk, widget.pk]),
                                         data=data)
            self._authenticate_request(request, user=widget.site.user)

            response = views.WidgetRetrieveUpdateView.as_view()(
                request, site_pk=site.pk, widget_pk=widget.pk)

            self.assertEqual(response.status_code, status.HTTP_200_OK,
                             response.data)
            fresh_widget_configuration = models.WidgetConfiguration.objects.get(
                pk=widget.pk)
            self.assertDictEqual(response.data,
                                 serializers.SharingButtonsWidgetSerializer(
                                     fresh_widget_configuration).data,
                                 msg=data)
        cache.delete.assert_has_calls([call(dict(site_id=site.pk))])
        self.assertEqual(cache.delete.call_count, 4)