Ejemplo n.º 1
0
def test_segments_error(header):
    try:
        segm = Segments(header)
    except ValueError:
        return

    with pytest.raises(OSError):
        segm.all(order='upper')
Ejemplo n.º 2
0
def test_wrong_headers(header):
    # test valid first
    try:
        _ = Segments(header)
    except ValueError:
        return

    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):
        segm = Segments(headers_2)
        segm.count()

    with pytest.raises(ValueError):
        segm = Segments(headers_3)

    with pytest.raises(ValueError):
        segm = Segments(headers_4)
Ejemplo n.º 3
0
def test_segments_crud(header):
    segm = Segments(header)
    all_segm, meta = segm.all()

    assert len(all_segm) == meta.pagination.count
    assert len(all_segm) == segm.count()

    all_segm, meta = segm.all(as_json=True)

    assert len(all_segm)
    assert 'pagination' in meta.keys()
Ejemplo n.º 4
0
def test_segments_crud(header):
    try:
        segm = Segments(header)
    except ValueError:
        return

    all_segm, meta = segm.all()

    assert len(all_segm) == meta.pagination.count
    assert len(all_segm) == segm.count()

    all_segm, meta = segm.all(as_json=True)

    assert len(all_segm)
    assert 'pagination' in meta.keys()
Ejemplo n.º 5
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)
Ejemplo n.º 6
0
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):
        segm = Segments(headers_2)
        segm.count()

    with pytest.raises(ValueError):
        segm = Segments(headers_3)

    with pytest.raises(ValueError):
        segm = Segments(headers_4)
Ejemplo n.º 7
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)
Ejemplo n.º 8
0
def test_segments_error(header):
    segm = Segments(header)

    with pytest.raises(OSError):
        segm.all(order='upper')