Ejemplo n.º 1
0
    def test_update_basket_task_without_token(self, basket_mock,
                                              lookup_token_mock, request_mock):
        lookup_token_mock.return_value = "basket_token"

        user = UserFactory.create(userprofile={
            'is_vouched': True,
            'country': 'gr',
            'city': 'athens'
        })
        group = GroupFactory.create(name='Web Development',
                                    steward=user.userprofile)
        GroupFactory.create(name='Marketing', steward=user.userprofile)
        group.members.add(user.userprofile)
        data = {
            'country': 'gr',
            'city': 'athens',
            'WEB_DEVELOPMENT': 'Y',
            'MARKETING': 'N'
        }

        basket_mock.subscribe.return_value = {}

        update_basket_task(user.userprofile.id)

        basket_mock.subscribe.assert_called_with(user.email,
                                                 'newsletter',
                                                 trigger_welcome='N')
        request_mock.assert_called_with('post',
                                        'custom_update_phonebook',
                                        token='basket_token',
                                        data=data)
        ok_(
            UserProfile.objects.filter(basket_token='basket_token',
                                       id=user.userprofile.id).exists())
Ejemplo n.º 2
0
    def test_update_basket_task_with_token(self):
        user = UserFactory.create(
            userprofile={
                'is_vouched': True,
                'country': 'gr',
                'city': 'athens',
                'basket_token': 'token'
            })
        group = GroupFactory.create(name='Web Development',
                                    steward=user.userprofile)
        GroupFactory.create(name='Marketing', steward=user.userprofile)
        group.members.add(user.userprofile)
        data = {
            'country': 'gr',
            'city': 'athens',
            'WEB_DEVELOPMENT': 'Y',
            'MARKETING': 'N'
        }

        with nested(patch('mozillians.users.tasks.basket.subscribe'),
                    patch('mozillians.users.tasks.request')) \
                as (subscribe_mock, request_mock):
            update_basket_task(user.userprofile.id)

        ok_(not subscribe_mock.called)
        request_mock.assert_called_with('post',
                                        'custom_update_phonebook',
                                        token='token',
                                        data=data)
Ejemplo n.º 3
0
    def test_update_basket_task_without_token(self, basket_mock, lookup_token_mock, request_mock):
        lookup_token_mock.return_value = "basket_token"

        user = UserFactory.create(userprofile={'is_vouched': True,
                                               'country': 'gr',
                                               'city': 'athens'})
        group = GroupFactory.create(
            name='Web Development', steward=user.userprofile)
        GroupFactory.create(name='Marketing', steward=user.userprofile)
        group.members.add(user.userprofile)
        data = {'country': 'gr',
                'city': 'athens',
                'WEB_DEVELOPMENT': 'Y',
                'MARKETING': 'N'}

        basket_mock.subscribe.return_value = {}

        update_basket_task(user.userprofile.id)

        basket_mock.subscribe.assert_called_with(
            user.email, 'newsletter', trigger_welcome='N')
        request_mock.assert_called_with(
            'post', 'custom_update_phonebook', token='basket_token', data=data)
        ok_(UserProfile.objects.filter(
            basket_token='basket_token', id=user.userprofile.id).exists())
Ejemplo n.º 4
0
 def test_subscribe_no_newsletters(self, basket_mock,
                                   switch_is_active_mock):
     switch_is_active_mock.return_value = True
     user = UserFactory.create(vouched=False)
     update_basket_task(user.userprofile.pk)
     eq_(basket_mock.subscribe.call_count, 0)
     eq_(basket_mock.unsubscribe.call_count, 0)
Ejemplo n.º 5
0
    def test_update_basket_task_without_token(self, basket_mock, lookup_token_mock, request_mock):
        lookup_token_mock.return_value = "basket_token"

        user = UserFactory.create(userprofile={"is_vouched": True, "country": "gr", "city": "athens"})
        group = GroupFactory.create(name="Web Development", curator=user.userprofile)
        GroupFactory.create(name="Marketing", curator=user.userprofile)
        group.add_member(user.userprofile)
        data = {"country": "gr", "city": "athens", "WEB_DEVELOPMENT": "Y", "MARKETING": "N"}

        basket_mock.subscribe.return_value = {}

        update_basket_task(user.userprofile.id)

        basket_mock.subscribe.assert_called_with(user.email, "newsletter", trigger_welcome="N")
        request_mock.assert_called_with("post", "custom_update_phonebook", token="basket_token", data=data)
        ok_(UserProfile.objects.filter(basket_token="basket_token", id=user.userprofile.id).exists())
Ejemplo n.º 6
0
    def test_update_basket_task_with_token(self):
        user = UserFactory.create(
            userprofile={"is_vouched": True, "country": "gr", "city": "athens", "basket_token": "token"}
        )
        group = GroupFactory.create(name="Web Development", curator=user.userprofile)
        GroupFactory.create(name="Marketing", curator=user.userprofile)
        group.add_member(user.userprofile)
        data = {"country": "gr", "city": "athens", "WEB_DEVELOPMENT": "Y", "MARKETING": "N"}

        with nested(patch("mozillians.users.tasks.basket.subscribe"), patch("mozillians.users.tasks.request")) as (
            subscribe_mock,
            request_mock,
        ):
            update_basket_task(user.userprofile.id)

        ok_(not subscribe_mock.called)
        request_mock.assert_called_with("post", "custom_update_phonebook", token="token", data=data)
Ejemplo n.º 7
0
    def test_update_basket_task_with_token(self):
        user = UserFactory.create(userprofile={'country': 'gr',
                                               'city': 'athens',
                                               'basket_token': 'token'})
        group = GroupFactory.create(name='Web Development',
                                    curator=user.userprofile)
        GroupFactory.create(name='Marketing', curator=user.userprofile)
        group.add_member(user.userprofile)
        data = {'country': 'gr',
                'city': 'athens',
                'WEB_DEVELOPMENT': 'Y',
                'MARKETING': 'N'}

        with nested(patch('mozillians.users.tasks.basket.subscribe'),
                    patch('mozillians.users.tasks.request')) \
                as (subscribe_mock, request_mock):
            update_basket_task(user.userprofile.id)

        ok_(not subscribe_mock.called)
        request_mock.assert_called_with(
            'post', 'custom_update_phonebook', token='token', data=data)
Ejemplo n.º 8
0
 def test_subscribe_no_newsletters(self, basket_mock, switch_is_active_mock):
     switch_is_active_mock.return_value = True
     user = UserFactory.create(vouched=False)
     update_basket_task(user.userprofile.pk)
     eq_(basket_mock.subscribe.call_count, 0)
     eq_(basket_mock.unsubscribe.call_count, 0)