示例#1
0
class TestGmail(object):
    def setup(self):
        self.cls = Gmail('*****@*****.**', '*****@*****.**', 'myuser', 'mypass')

    def test_init(self):
        cls = Gmail('t', 'f', 'u', 'p')
        assert cls.to_addr == 't'
        assert cls.from_addr == 'f'
        assert cls.username == 'u'
        assert cls.password == 'p'

    def test_send(self):
        dt = datetime(2015, 2, 13, 1, 2, 3, 123456)
        with patch('%s.Gmail._send_gmail' % pbm) as mock_send:
            self.cls.send(dt, 1, 0, 'pin1', 'state0')
        assert mock_send.mock_calls == [
            call('pin1 (1) changed to state0 (0) at 2015-02-13T01:02:03',
                 "2015-02-13T01:02:03\npin1 (1) changed state to state0 (0)")
        ]

    def test_send_gmail(self):
        msg = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: ' \
              '1.0\nContent-Transfer-Encoding: 7bit\nSubject: mysubj\nFrom: ' \
              '[email protected]\nTo: [email protected]\n\nmy\nbody'
        with patch('%s.smtplib.SMTP' % pbm, autospec=True) as mock_smtp:
            self.cls._send_gmail('mysubj', "my\nbody")
        assert mock_smtp.mock_calls == [
            call('smtp.gmail.com:587'),
            call().starttls(),
            call().login('myuser', 'mypass'),
            call().sendmail('*****@*****.**', ['*****@*****.**'], msg),
            call().quit()
        ]
示例#2
0
class TestGmail(object):

    def setup(self):
        self.cls = Gmail('*****@*****.**', '*****@*****.**', 'myuser', 'mypass')

    def test_init(self):
        cls = Gmail('t', 'f', 'u', 'p')
        assert cls.to_addr == 't'
        assert cls.from_addr == 'f'
        assert cls.username == 'u'
        assert cls.password == 'p'

    def test_send(self):
        dt = datetime(2015, 2, 13, 1, 2, 3, 123456)
        with patch('%s.Gmail._send_gmail' % pbm) as mock_send:
            self.cls.send(dt, 1, 0, 'pin1', 'state0')
        assert mock_send.mock_calls == [
            call(
                'pin1 (1) changed to state0 (0) at 2015-02-13T01:02:03',
                "2015-02-13T01:02:03\npin1 (1) changed state to state0 (0)"
            )
        ]

    def test_send_gmail(self):
        msg = 'Content-Type: text/plain; charset="us-ascii"\nMIME-Version: ' \
              '1.0\nContent-Transfer-Encoding: 7bit\nSubject: mysubj\nFrom: ' \
              '[email protected]\nTo: [email protected]\n\nmy\nbody'
        with patch('%s.smtplib.SMTP' % pbm, autospec=True) as mock_smtp:
            self.cls._send_gmail('mysubj', "my\nbody")
        assert mock_smtp.mock_calls == [
            call('smtp.gmail.com:587'),
            call().starttls(),
            call().login('myuser', 'mypass'),
            call().sendmail('*****@*****.**', ['*****@*****.**'], msg),
            call().quit()
        ]
示例#3
0
 def setup(self):
     self.cls = Gmail('*****@*****.**', '*****@*****.**', 'myuser', 'mypass')
示例#4
0
 def test_init(self):
     cls = Gmail('t', 'f', 'u', 'p')
     assert cls.to_addr == 't'
     assert cls.from_addr == 'f'
     assert cls.username == 'u'
     assert cls.password == 'p'
示例#5
0
 def setup(self):
     self.cls = Gmail('*****@*****.**', '*****@*****.**', 'myuser', 'mypass')