예제 #1
0
파일: tests.py 프로젝트: gudniola/mgsub
 def test_env_list_url(self):
     with patch.dict('os.environ', {'MGSUB_DEFAULT_MAILINGLIST':
                                    '*****@*****.**'}, clear=True):
         mailinglist = MailgunList()
         url = mailinglist.get_list_url()
         exp = 'https://api.mailgun.net/v2/lists/[email protected]/members'
         self.assertEquals(url, exp)
예제 #2
0
 def test_env_list_url(self):
     with patch.dict('os.environ',
                     {'MGSUB_DEFAULT_MAILINGLIST': '*****@*****.**'},
                     clear=True):
         mailinglist = MailgunList()
         url = mailinglist.get_list_url()
         exp = 'https://api.mailgun.net/v2/lists/[email protected]/members'
         self.assertEquals(url, exp)
예제 #3
0
파일: tests.py 프로젝트: gudniola/mgsub
    def test_subscribe_duplicate(self):
        resp = \
            '''{
                 "message": "Address already exists"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST, url,
                      resp, content_type='application/json',
                      status=400,
                      adding_headers={'content-length': str(len(resp))})

        mailinglist = MailgunList()
        result = mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #4
0
파일: tests.py 프로젝트: gudniola/mgsub
    def test_subscribe_400(self):
        resp = \
            '''{
                 "message": "Bad request"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST, url,
                      resp, content_type='application/json',
                      status=400,
                      adding_headers={'content-length': str(len(resp))})

        mailinglist = MailgunList()
        with self.assertRaises(MailgunError) as cm:
            mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEqual(400, cm.exception.code)
        self.assertEqual('Bad request', cm.exception.json['message'])
예제 #5
0
파일: tests.py 프로젝트: gudniola/mgsub
    def test_unsubscribe_success(self):
        resp = \
            '''{
                 "member":
                   {
                     "address": "*****@*****.**"
                   },
                   "message": "Mailing list member has been deleted"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members/[email protected]'
        responses.add(responses.DELETE, url,
                      resp, content_type='application/json')

        mailinglist = MailgunList()
        result = mailinglist.unsubscribe('*****@*****.**')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #6
0
파일: forms.py 프로젝트: gudniola/mgsub
class SignupForm(forms.Form):
    email = forms.EmailField()

    def __init__(self, list_email=None, *args, **kwargs):
        self.mailinglist = MailgunList(list_email)
        super(SignupForm, self).__init__(*args, **kwargs)

    def is_valid(self):
        if not super(SignupForm, self).is_valid():
            return False

        if not self.subscribe():
            self.add_error(None, 'There was a failure adding you to the mailing list')
            return False

        if getattr(settings, 'MGSUB_SEND_WELCOME', True):
            return self.send_welcome()

        return True

    def subscribe(self):
        try:
            return self.mailinglist.subscribe(self.cleaned_data['email'])
        except Exception, e:
            logger.error(e)
            return False
예제 #7
0
    def test_subscribe_duplicate(self):
        resp = \
            '''{
                 "message": "Address already exists"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST,
                      url,
                      resp,
                      content_type='application/json',
                      status=400,
                      adding_headers={'content-length': str(len(resp))})

        mailinglist = MailgunList()
        result = mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #8
0
class SignupForm(forms.Form):
    email = forms.EmailField()

    def __init__(self, list_email=None, *args, **kwargs):
        self.mailinglist = MailgunList(list_email)
        super(SignupForm, self).__init__(*args, **kwargs)

    def is_valid(self):
        if not super(SignupForm, self).is_valid():
            return False

        if not self.subscribe():
            self.add_error(
                None, 'There was a failure adding you to the mailing list')
            return False

        if getattr(settings, 'MGSUB_SEND_WELCOME', True):
            return self.send_welcome()

        return True

    def subscribe(self):
        try:
            return self.mailinglist.subscribe(self.cleaned_data['email'])
        except Exception, e:
            logger.error(e)
            return False
예제 #9
0
    def test_subscribe_400(self):
        resp = \
            '''{
                 "message": "Bad request"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST,
                      url,
                      resp,
                      content_type='application/json',
                      status=400,
                      adding_headers={'content-length': str(len(resp))})

        mailinglist = MailgunList()
        with self.assertRaises(MailgunError) as cm:
            mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEqual(400, cm.exception.code)
        self.assertEqual('Bad request', cm.exception.json['message'])
예제 #10
0
    def test_unsubscribe_success(self):
        resp = \
            '''{
                 "member":
                   {
                     "address": "*****@*****.**"
                   },
                   "message": "Mailing list member has been deleted"
               }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members/[email protected]'
        responses.add(responses.DELETE,
                      url,
                      resp,
                      content_type='application/json')

        mailinglist = MailgunList()
        result = mailinglist.unsubscribe('*****@*****.**')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #11
0
파일: tests.py 프로젝트: gudniola/mgsub
    def test_subscribe_success(self):
        resp = \
            '''{
                 "member": {
                   "vars": {
                     "age": 26
                   },
                   "name": "Bob Bar",
                   "subscribed": true,
                   "address": "*****@*****.**"
                 },
                 "message": "Mailing list member has been created"
            }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST, url,
                      resp, content_type='application/json')

        mailinglist = MailgunList()
        result = mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #12
0
    def test_subscribe_success(self):
        resp = \
            '''{
                 "member": {
                   "vars": {
                     "age": 26
                   },
                   "name": "Bob Bar",
                   "subscribed": true,
                   "address": "*****@*****.**"
                 },
                 "message": "Mailing list member has been created"
            }'''
        url = 'https://api.mailgun.net/v2/lists/[email protected]/members'
        responses.add(responses.POST,
                      url,
                      resp,
                      content_type='application/json')

        mailinglist = MailgunList()
        result = mailinglist.subscribe('*****@*****.**', 'Bob Bar')
        self.assertEquals(result['member']['address'], '*****@*****.**')
예제 #13
0
 def test_list_url(self):
     mailinglist = MailgunList()
     url = mailinglist.get_list_url()
     exp = 'https://api.mailgun.net/v2/lists/[email protected]/members'
     self.assertEquals(url, exp)
예제 #14
0
파일: forms.py 프로젝트: gudniola/mgsub
 def __init__(self, list_email=None, *args, **kwargs):
     self.mailinglist = MailgunList(list_email)
     super(SignupForm, self).__init__(*args, **kwargs)
예제 #15
0
 def test_api_environ(self):
     with patch.dict('os.environ', {'MAILGUN_API_KEY': 'env'}):
         mailinglist = MailgunList()
         self.assertEqual(mailinglist.api_key, 'env')
예제 #16
0
 def test_api_key(self):
     with patch.dict('os.environ', {}, clear=True):
         mailinglist = MailgunList()
         self.assertIsNone(mailinglist.api_key)
예제 #17
0
 def test_api_settings(self):
     mailinglist = MailgunList()
     self.assertEqual(mailinglist.api_key, 'settings')
예제 #18
0
파일: tests.py 프로젝트: gudniola/mgsub
 def test_member_url(self):
     mailinglist = MailgunList()
     url = mailinglist.get_member_url('*****@*****.**')
     self.assertIn('[email protected]/members/[email protected]', url)
예제 #19
0
 def test_member_url(self):
     mailinglist = MailgunList()
     url = mailinglist.get_member_url('*****@*****.**')
     self.assertIn('[email protected]/members/[email protected]', url)
예제 #20
0
파일: tests.py 프로젝트: gudniola/mgsub
 def test_list_url(self):
     mailinglist = MailgunList()
     url = mailinglist.get_list_url()
     exp = 'https://api.mailgun.net/v2/lists/[email protected]/members'
     self.assertEquals(url, exp)
예제 #21
0
 def __init__(self, list_email=None, *args, **kwargs):
     self.mailinglist = MailgunList(list_email)
     super(SignupForm, self).__init__(*args, **kwargs)