def test_put_user_settings_email_subscriptions_bad_key(self):
     self.login_default_user()
     subs = animalify(get_default_email_subscriptions())
     subs['badKey'] = False
     resp = self.app.put("/api/v1/users/{}/settings".format(self.user.id),
                         data=json.dumps({'emailSubscriptions': subs}),
                         content_type='application/json')
     self.assert400(resp)
 def test_validate_email_subscriptions(self):
     test = get_default_email_subscriptions()
     # no Exception
     validate_email_subscriptions(test)
     # cause ValidationException
     test['incorrect_key'] = True
     with pytest.raises(ValidationException) as e_info:
         validate_email_subscriptions(test)
 def test_put_user_settings_email_subscriptions(self):
     self.login_default_user()
     subs = animalify(get_default_email_subscriptions())
     subs['myCommentReply'] = False
     resp = self.app.put("/api/v1/users/{}/settings".format(self.user.id),
                         data=json.dumps({'emailSubscriptions': subs}),
                         content_type='application/json')
     self.assert200(resp)
     self.assertIsNotNone(resp.json['emailSubscriptions'])
     self.maxDiff = None
     self.assertEquals(resp.json['emailSubscriptions'], subs)
import pytest
from grant.email.subscription_settings import (email_subscriptions_to_bits,
                                               email_subscriptions_to_dict,
                                               get_default_email_subscriptions,
                                               validate_email_subscriptions,
                                               is_subscribed,
                                               EmailSubscription)
from grant.utils.exceptions import ValidationException

from ..config import BaseTestConfig

test_dict = get_default_email_subscriptions()

# set all False
for k in test_dict:
    test_dict[k] = False

# turn on a couple
test_dict[EmailSubscription.MY_COMMENT_REPLY.value['key']] = True
test_dict[EmailSubscription.FUNDED_PROPOSAL_UPDATE.value['key']] = True
test_dict[EmailSubscription.FUNDED_PROPOSAL_PAYOUT_REQUEST.value['key']] = True

# calculate number
test_bits = \
    2 ** EmailSubscription.MY_COMMENT_REPLY.value['bit'] + \
    2 ** EmailSubscription.FUNDED_PROPOSAL_UPDATE.value['bit'] + \
    2 ** EmailSubscription.FUNDED_PROPOSAL_PAYOUT_REQUEST.value['bit']


class TestEmailSubscriptionSettings(BaseTestConfig):
    def test_email_subscriptions_to_bits(self):
Ejemplo n.º 5
0
 def __init__(self, user_id):
     self.email_subscriptions = get_default_email_subscriptions()
     self.user_id = user_id