示例#1
0
 def setUp(self):
     self.client = GuerrillaMailClient(base_url='http://test-host')
示例#2
0
class GuerrillaMailClientTest(TestCase):
    def setUp(self):
        self.client = GuerrillaMailClient(base_url='http://test-host')

    @httpretty.activate
    def test_get_email_address_should_send_query_params(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.get_email_address()
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['get_email_address'],
            'ip': ['127.0.0.1'],
        })

    @httpretty.activate
    def test_get_email_address_should_include_session_id_query_param_when_present(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.get_email_address(session_id=1)
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['get_email_address'],
            'ip': ['127.0.0.1'],
            'sid_token': ['1'],
        })

    @httpretty.activate
    def test_get_email_address_should_returned_deserialized_json(self):
        response_body = '{"email_addr":"*****@*****.**"}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        response = self.client.get_email_address()
        expect(response).to.equal({'email_addr': '*****@*****.**'})

    @httpretty.activate
    def test_get_email_address_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php', status=500)
        expect(self.client.get_email_address).when.called_with().should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_set_email_address_should_send_query_params(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.set_email_address('newaddr')
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['set_email_user'],
            'ip': ['127.0.0.1'],
            'email_user': ['newaddr'],
        })

    @httpretty.activate
    def test_set_email_address_should_include_session_id_query_param_when_present(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.set_email_address('newaddr', session_id=1)
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['set_email_user'],
            'ip': ['127.0.0.1'],
            'email_user': ['newaddr'],
            'sid_token': ['1'],
        })

    @httpretty.activate
    def test_set_email_address_should_returned_deserialized_json(self):
        response_body = '{"email_addr":"*****@*****.**"}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        response = self.client.set_email_address('newaddr')
        expect(response).to.equal({'email_addr': '*****@*****.**'})

    @httpretty.activate
    def test_set_email_address_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php', status=500)
        expect(self.client.set_email_address).when.called_with('newaddr').should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_list_should_send_query_params(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.get_email_list(session_id=1)
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['get_email_list'],
            'ip': ['127.0.0.1'],
            'offset': ['0'],
            'sid_token': ['1'],
        })

    def test_get_email_list_should_not_allow_session_id_to_be_none(self):
        expect(self.client.get_email_list).when.called_with(session_id=None).to.throw(ValueError)

    @httpretty.activate
    def test_get_email_list_should_return_deserialized_json(self):
        response_body = '{"list":[{"subject":"Hello"}]}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        email_list = self.client.get_email_list(session_id=1)
        expect(email_list).to.equal({'list':[{'subject': 'Hello'}]})

    @httpretty.activate
    def test_get_email_list_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php', status=500)
        expect(self.client.get_email_list).when.called_with(session_id=1).should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_should_send_query_params(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.get_email(email_id=123)
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['fetch_email'],
            'ip': ['127.0.0.1'],
            'email_id': ['123'],
        })

    @httpretty.activate
    def test_get_email_should_send_session_id_query_param_when_present(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        self.client.get_email(email_id=123, session_id=1)
        expect(httpretty.last_request()).to.have.property('querystring').being.equal({
            'f': ['fetch_email'],
            'ip': ['127.0.0.1'],
            'email_id': ['123'],
            'sid_token': ['1'],
        })

    @httpretty.activate
    def test_get_email_should_return_deserialized_json(self):
        response_body = '{"subject":"Hello"}'
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php',
                               body=response_body, match_querystring=True)
        email = self.client.get_email(email_id=123)
        expect(email).to.equal({'subject': 'Hello'})

    @httpretty.activate
    def test_get_email_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php', status=500)
        expect(self.client.get_email).when.called_with(email_id=123).should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_should_raise_exception_when_message_not_found(self):
        httpretty.register_uri(httpretty.GET, 'http://test-host/ajax.php', status=200, body='false')
        expect(self.client.get_email).when.called_with(email_id=123).should.throw(GuerrillaMailException)
示例#3
0
class GuerrillaMailClientTest(TestCase):
    def setUp(self):
        self.client = GuerrillaMailClient(base_url='http://test-host')

    @httpretty.activate
    def test_get_email_address_should_send_query_params(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.get_email_address()
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['get_email_address'],
                'ip': ['127.0.0.1'],
            })

    @httpretty.activate
    def test_get_email_address_should_include_session_id_query_param_when_present(
            self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.get_email_address(session_id=1)
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['get_email_address'],
                'ip': ['127.0.0.1'],
                'sid_token': ['1'],
            })

    @httpretty.activate
    def test_get_email_address_should_returned_deserialized_json(self):
        response_body = '{"email_addr":"*****@*****.**"}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        response = self.client.get_email_address()
        expect(response).to.equal({'email_addr': '*****@*****.**'})

    @httpretty.activate
    def test_get_email_address_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               status=500)
        expect(self.client.get_email_address).when.called_with().should.throw(
            GuerrillaMailException)

    @httpretty.activate
    def test_set_email_address_should_send_query_params(self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.set_email_address('newaddr')
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['set_email_user'],
                'ip': ['127.0.0.1'],
                'email_user': ['newaddr'],
            })

    @httpretty.activate
    def test_set_email_address_should_include_session_id_query_param_when_present(
            self):
        response_body = '{"email_addr":""}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.set_email_address('newaddr', session_id=1)
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['set_email_user'],
                'ip': ['127.0.0.1'],
                'email_user': ['newaddr'],
                'sid_token': ['1'],
            })

    @httpretty.activate
    def test_set_email_address_should_returned_deserialized_json(self):
        response_body = '{"email_addr":"*****@*****.**"}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        response = self.client.set_email_address('newaddr')
        expect(response).to.equal({'email_addr': '*****@*****.**'})

    @httpretty.activate
    def test_set_email_address_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               status=500)
        expect(self.client.set_email_address).when.called_with(
            'newaddr').should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_list_should_send_query_params(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.get_email_list(session_id=1)
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['get_email_list'],
                'ip': ['127.0.0.1'],
                'offset': ['0'],
                'sid_token': ['1'],
            })

    def test_get_email_list_should_not_allow_session_id_to_be_none(self):
        expect(self.client.get_email_list).when.called_with(
            session_id=None).to.throw(ValueError)

    @httpretty.activate
    def test_get_email_list_should_return_deserialized_json(self):
        response_body = '{"list":[{"subject":"Hello"}]}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        email_list = self.client.get_email_list(session_id=1)
        expect(email_list).to.equal({'list': [{'subject': 'Hello'}]})

    @httpretty.activate
    def test_get_email_list_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               status=500)
        expect(self.client.get_email_list).when.called_with(
            session_id=1).should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_should_send_query_params(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.get_email(email_id=123)
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['fetch_email'],
                'ip': ['127.0.0.1'],
                'email_id': ['123'],
            })

    @httpretty.activate
    def test_get_email_should_send_session_id_query_param_when_present(self):
        response_body = '{"list":[]}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        self.client.get_email(email_id=123, session_id=1)
        expect(httpretty.last_request()).to.have.property(
            'querystring').being.equal({
                'f': ['fetch_email'],
                'ip': ['127.0.0.1'],
                'email_id': ['123'],
                'sid_token': ['1'],
            })

    @httpretty.activate
    def test_get_email_should_return_deserialized_json(self):
        response_body = '{"subject":"Hello"}'
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               body=response_body,
                               match_querystring=True)
        email = self.client.get_email(email_id=123)
        expect(email).to.equal({'subject': 'Hello'})

    @httpretty.activate
    def test_get_email_should_raise_exception_on_failed_request(self):
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               status=500)
        expect(self.client.get_email).when.called_with(
            email_id=123).should.throw(GuerrillaMailException)

    @httpretty.activate
    def test_get_email_should_raise_exception_when_message_not_found(self):
        httpretty.register_uri(httpretty.GET,
                               'http://test-host/ajax.php',
                               status=200,
                               body='false')
        expect(self.client.get_email).when.called_with(
            email_id=123).should.throw(GuerrillaMailException)
示例#4
0
 def setUp(self):
     self.client = GuerrillaMailClient(base_url='http://test-host')
示例#5
0
from guerrillamail import GuerrillaMailSession, GuerrillaMailClient

session = GuerrillaMailSession()
print session.get_session_state()['email_address']
print session.get_email_list()[0].guid
print session.get_email(1).guid

client = GuerrillaMailClient()
email_data = client.get_email(1)
print email_data.get('mail_from')