Example #1
0
def test_webhook_error(header):
    try:
        wh = Webhooks(header)
    except ValueError:
        return

    with pytest.raises(OSError):
        wh.update(123456, "new_url", "new_event")
def test_webhook_crud(header):
    wh = Webhooks(header)
    all_wh = wh.all()

    assert len(all_wh) > 0
    assert len(all_wh) == wh.count()

    first_wh = all_wh[0]
    current_wh = wh.get(first_wh.id)

    # assert isinstance(current_wh, Webhook)
    for f in current_wh._fields:
        assert current_wh._asdict().get(f) == first_wh._asdict().get(f)
Example #3
0
    def __init__(self, api_key=None):
        """Initialize a new mailerlite.api object.

        Parameters
        ----------
        api_key : str
            Your mailerlite api_key.

        """
        api_key = api_key or os.environ.get("MAILERLITE_PYTHON_API_KEY", None)

        if not api_key or not isinstance(api_key, str):
            raise ValueError("Empty API_KEY. Please enter a valid API_KEY")

        self._headers = {
            'content-type': "application/json",
            "X-MailerLite-ApiDocs": "true",
            'x-mailerlite-apikey': api_key
        }

        self.campaigns = Campaigns(headers=self.headers)
        self.segments = Segments(headers=self.headers)
        self.subscribers = Subscribers(headers=self.headers)
        self.groups = Groups(headers=self.headers)
        self.fields = Fields(headers=self.headers)
        self.webhooks = Webhooks(headers=self.headers)
        self.account = Account(headers=self.headers)
def test_wrong_headers():
    headers_2 = {
        'content-type': "application/json",
        'x-mailerlite-apikey': 'FAKE_KEY'
    }
    headers_3 = {
        'content-type': "application/json",
    }
    headers_4 = {'x-mailerlite-apikey': 'FAKE_KEY'}

    with pytest.raises(OSError):
        wh = Webhooks(headers_2)
        wh.all()

    with pytest.raises(ValueError):
        wh = Webhooks(headers_3)

    with pytest.raises(ValueError):
        wh = Webhooks(headers_4)
Example #5
0
    def __init__(self, api_key):
        """Initialize a new mailerlite.api object.

        Parameters
        ----------
        api_key : str
            Your mailerlite api_key.

        """
        if not api_key or not isinstance(api_key, str):
            raise ValueError("Empty API_KEY. Please enter a valid API_KEY")

        self._headers = {
            'content-type': "application/json",
            'x-mailerlite-apikey': api_key
        }

        self.campaigns = Campaigns(headers=self.headers)
        self.segments = Segments(headers=self.headers)
        self.subscribers = Subscribers(headers=self.headers)
        self.groups = Groups(headers=self.headers)
        self.fields = Fields(headers=self.headers)
        self.webhooks = Webhooks(headers=self.headers)
        self.account = Account(headers=self.headers)
def test_webhook_error(header):
    wh = Webhooks(header)

    with pytest.raises(OSError):
        wh.update(123456, "new_url", "new_event")