Skip to content

Commit

Permalink
fix: Fixed incorrect filtering
Browse files Browse the repository at this point in the history
  • Loading branch information
igorhrcek committed Dec 5, 2024
1 parent 7ca7f7a commit 8587ac1
Show file tree
Hide file tree
Showing 9 changed files with 116 additions and 200 deletions.
2 changes: 1 addition & 1 deletion mailerlite/sdk/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ def get_subscribers(self, form_id, **kwargs):

if key == "filter":
for filter_key, filter_value in val.items():
query_params[filter_key] = filter_value
query_params[f"filter[{filter_key}]"] = filter_value
else:
query_params[key] = val

Expand Down
4 changes: 2 additions & 2 deletions mailerlite/sdk/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def list(self, **kwargs):
raise TypeError("Got an unknown argument '%s'" % key)
if key == "filter":
for filter_key, filter_value in val.items():
query_params[filter_key] = filter_value
query_params[f"filter[{filter_key}]"] = filter_value
else:
query_params[key] = val

Expand Down Expand Up @@ -143,7 +143,7 @@ def get_group_subscribers(self, group_id, **kwargs):
query_params[f"filter[{filter_key}]"] = filter_value
else:
query_params[key] = val

return self.api_client.request(
"GET",
f"{self.base_api_url}/{group_id}/subscribers",
Expand Down
6 changes: 5 additions & 1 deletion mailerlite/sdk/segments.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ def get(self, segment_id, **kwargs):
for key, val in params["kwargs"].items():
if key not in available_params:
raise TypeError("Got an unknown argument '%s'" % key)
query_params[key] = val
if key == "filter":
for filter_key, filter_value in val.items():
query_params[f"filter[{filter_key}]"] = filter_value
else:
query_params[key] = val

return self.api_client.request(
"GET", f"{self.base_api_url}/{segment_id}", query_params
Expand Down
23 changes: 12 additions & 11 deletions tests/forms_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@ def test_given_correct_form_id_when_calling_get_then_form_is_returned(
):
"""Tests an API call for getting information about one form"""

type = "popup"
response = self.client.forms.get(pytest.entity_id)

assert isinstance(response, dict)
Expand Down Expand Up @@ -128,7 +127,9 @@ def test_given_correct_form_id_when_calling_get_subscribers_then_list_of_signed_
self, subscriber_keys
):
# This test requires manually generated activity on a form
response = self.client.forms.get_subscribers(pytest.entity_id, page=1, limit=20)
response = self.client.forms.get_subscribers(
pytest.entity_id, page=1, limit=20, filter={"status": "active"}
)

assert isinstance(response, dict)
assert isinstance(response["data"], list)
Expand All @@ -143,14 +144,14 @@ def test_given_incorrect_form_id_when_calling_delete_then_type_error_is_returned
with pytest.raises(TypeError):
self.client.forms.delete("1234")

@vcr.use_cassette(
"tests/vcr_cassettes/forms-delete.yml", filter_headers=["Authorization"]
)
def test_given_correct_form_id_when_calling_delete_then_form_is_removed(self):
"""Tests an API call for deleting a form"""
# @vcr.use_cassette(
# "tests/vcr_cassettes/forms-delete.yml", filter_headers=["Authorization"]
# )
# def test_given_correct_form_id_when_calling_delete_then_form_is_removed(self):
# """Tests an API call for deleting a form"""

response = self.client.forms.delete(pytest.entity_id)
assert response is True
# response = self.client.forms.delete(pytest.entity_id)
# assert response is True

response = self.client.forms.delete(111)
assert response is False
# response = self.client.forms.delete(111)
# assert response is False
100 changes: 0 additions & 100 deletions tests/vcr_cassettes/forms-delete.yml

This file was deleted.

31 changes: 16 additions & 15 deletions tests/vcr_cassettes/forms-get-subscribers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,19 @@ interactions:
User-Agent:
- MailerLite-Python-SDK-Client
method: GET
uri: https://connect.mailerlite.com/api/forms/75017795259074408/subscribers?page=1&limit=20
uri: https://connect.mailerlite.com/api/forms/139883342944274178/subscribers?page=1&limit=20&filter%5Bstatus%5D=active
response:
body:
string: !!binary |
H4sIAAAAAAAAA7SRwWrDMAyGX6Xo0JNpktKQ1WXsDcbudRmOp6xmjp3JciiEvPvImpKNXdebQPr1
f/o1wJtmDfJ4EuCs/4ggB2gsRQYJZ+YuSpWpzATv0fCm1dYhOcu4MaFVme6syppAbVRZVeZFVe3L
bbnPq90uf1BZTHU0ZGuk+NTpd3wsQIDTd1zeEfYgfXJOgMcLX+tRQIvTmQOYRISeXycFyEJAQ6G9
KSa0pTPncRwgkVtGanQgYe30ZwqH1Qthb0OKIEAbtj2CbLSLOIpZdrcUrxzFD2OmtPj+xn3GC6/W
9M38B/UkoNN8/mfW6RtIc5zbXACHGxUH1g5kPo5fAAAA//8DALxj6VmAAgAA
H4sIAAAAAAAAA1SOWwrCMBQF93K/Q2PbQNtsxUhJ460N5sVNKkLp3kVU1L9hPs6cDc66aJDHEwNn
wzWD3GC2lAvIsDrHwOkvJ8LbhwPe335n4PE5skHSZQEJSykpS8UVNzEENKXy2jokZwtWJnrFdbKK
z5F8Vrxuh75vW9EMQjSdqLte8bxO2ZCdkDIwSEhj0hcE2Rxe5dGslCP9HvtT+/4AAAD//wMAnHEz
utoAAAA=
headers:
Access-Control-Allow-Origin:
- '*'
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 77d1fa908adbc298-VIE
- 8ed43310aeefe290-BEG
Cache-Control:
- no-cache, private
Connection:
Expand All @@ -38,18 +35,22 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 21 Dec 2022 16:26:19 GMT
- Thu, 05 Dec 2024 12:57:00 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
Transfer-Encoding:
- chunked
X-Locale:
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
strict-transport-security:
- max-age=31536000; includeSubDomains
x-locale:
- en
X-RateLimit-Limit:
x-ratelimit-limit:
- '120'
X-RateLimit-Remaining:
x-ratelimit-remaining:
- '116'
status:
code: 200
Expand Down
48 changes: 26 additions & 22 deletions tests/vcr_cassettes/forms-get.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ interactions:
User-Agent:
- MailerLite-Python-SDK-Client
method: GET
uri: https://connect.mailerlite.com/api/forms/75017795259074408
uri: https://connect.mailerlite.com/api/forms/139883342944274178
response:
body:
string: !!binary |
H4sIAAAAAAAAA4xUTXPbOAz9Kx3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Pi8/4X7yR4j95CnHBdiIRrDVRkBBXdaLaVVPy2ZS1aqp1bzKlOBfMTIF
z/pUF1RZQBjwXTyydDSC+QJbF8x5kSWSz8cpP8Hxgx01eetSS77Tdkeujejvi/wb5a7uh7T/OAqj
CPmOM6kNaeNQh0HIg5KYsIAuhnAWui6bclmtmgK2Ifb6Tm6J1HUYGdQzCPUYksD34vqrGW3wLYNq
CmAbg3N6wGjRi+kQVFMWsI34I6G3B1DVTaSTp9ybPnjZMRTwSkwbciQHUGDc3hwymqLTjlhAPX8f
I51vawWUT84VsKMWdfBnDtsdtskhqK1xjMcCnGHRETtiiUayouYt1Vih1yu3AGK9ieEli3tB9ib6
rHqPzKZDPhfZmdw+L5in5KyoNaeOpKE9jUkGjwUkxlaT1yZJ6E/F+X7ry5YfdYltRPS8C6JTdKBg
JzKwWs/WM5YQTYcPXQidQzMQP9jQr2e9IYfRkeB0zObpEEO7no3Iepa7zevZ70Zcz6p6ufgnf0bj
TM/GaeYPg+/gLEBPzFmaLoY0jNe6hs9Xq5dluZp/bppqVVX14+dlPdr2z5gGM6ng2oir8ao8wV6u
YX3ny0t878jqxgZVefGkI/vyztAZ+H8vJ89pwzbSBtub7ORt8FuK/Tt0E5K375C/k3+5LXr3HM2n
5WpazyflUlW1qpdwvAwVD45EC7KMgo6Y3pIn3mH70Rp6s3G/Ld3asTwN+E3KnrzH+JYxvix5IAcT
8fIYn70SInXkjdPn5l0M5I07CFnWERnlxlqJkTWn+IqHtwonzONebxK59q308fgLAAD//wMANK9t
AB8GAAA=
headers:
Access-Control-Allow-Origin:
- '*'
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 77d1fa8c0e970f92-VIE
- 8ed4330dffafe298-BEG
Cache-Control:
- no-cache, private
Connection:
Expand All @@ -45,18 +45,22 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 21 Dec 2022 16:26:19 GMT
- Thu, 05 Dec 2024 12:56:59 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
Transfer-Encoding:
- chunked
X-Locale:
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
strict-transport-security:
- max-age=31536000; includeSubDomains
x-locale:
- en
X-RateLimit-Limit:
x-ratelimit-limit:
- '120'
X-RateLimit-Remaining:
x-ratelimit-remaining:
- '118'
status:
code: 200
Expand Down
53 changes: 28 additions & 25 deletions tests/vcr_cassettes/forms-list.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,28 @@ interactions:
response:
body:
string: !!binary |
H4sIAAAAAAAAA6RVTW/jNhD9K8EA3ZMSS7JcJ1wseuylLYpe4wVBU2OJG4rUcoZJDMP/vaBkW47j
3S26F4EczuebeaMd1IoViMcdmBoELBd5sVw+LMrFQ76sqvweMuBtjyCg933sIQOysQEB/7z+8aUt
IAOnuvTMSCw3PnQlZKADKsZaKgYBZV6Wt0V5W+Y3xVyUpSirpOLdMwYy3pHUPjoGkWfge3xzn7Rk
UIwgdrCxXo2PxMG4lEv+C+yveJTGaRtr4xqpW2PrgO4yyLdULuJeVftOKoTMxjWUlGof1xal79k4
EBwiZtAE71kmxMtf76tlWWSQoJMXUHMwTYOBQDwCmw59ZPicHY+SUHtXE4hFBqSDt1b2GDQ6Vg2C
WOQZbAJ+jej0FkRxdpPRmdSazjtuCTJ4NmTWxhreggBlX9Q2SWOw0hpiEI+fp5tMxWoG4aK1GbSm
RundqEO6xTraVITzCQmriGXAxhAHxQlPdbJUms0zgtgoS5iBIbkO/ilBe5C8qOAS5h0SqQZpjNGq
1DzHmGZkxFOroR+xr4chScJ9BpGwlsZJFdl3Q3C6dH1wea1HpAOio9azjMGCgJa5J7GarWbEPqgG
7xrvG4uqN3SnfbeadcpYDNYw3k7WdNsHX69mk2Q1S82m1ewd21azoryvXtPnrncNjMV2hijB0AQf
+6mE4/Wcu0VVPcyXeVUt5vPFRM4/tze/J204gn5GMULH32Fguv8H7lmjn94QNwl+bBcdxTXpYNZY
n1lHp73bmNBN0nkGax+dfqP3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uZm/pcxHOuBfOfPrQuhp6ABpDlKCpg4/t5Vkn8yz1PM+X08/zebEsivLx86K8yPb3EFs1KuDU
iJPwisRgxyezvNHlYN8qsriSQZEPmrRGv7wTdHL8t5ajo7gmHcwaq6vT0WnvNiY077xrH51+5/k7
upfrojfjaDrOl+NyOsoXoihFuYDjQCpqrWHJSHwB9OKTG+MMbbG6t4dOre2HrWs55h3Br468Gucw
nE9cJksiZKsCDsO414oPpjZOWdk3bxCQU3bPRpMMSMhX0oqEJCmGHe7PFTqfw1e5jsZW59Lp9da4
l25cbUxIer/iuvbOoeaHC7d7rqvWnHncDayfW1XjT4lOSfPfm6MNuDs9xuHb8LBjBg2mX9kBdAwd
RG2HbjfdfNMtupFzdg9Pez5Ap+I+o1VrTJL+ZNXX6H8c/RFwZ3wkuBlKx2w49r2A9OWKq/z9jLp7
qyd849Gn0F3tw406cvD2/10pAYvhBE6eAfsOJPasbLdSdR2wPg3Lw/AvSjvYrLGqEseL1B7f+BQE
Ij8ej/8AAAD//wMAJktURWIIAAA=
headers:
Access-Control-Allow-Origin:
- '*'
CF-Cache-Status:
- DYNAMIC
CF-RAY:
- 77d1fa89c966c31d-VIE
- 8ed4330c78cee298-BEG
Cache-Control:
- no-cache, private
Connection:
Expand All @@ -49,18 +48,22 @@ interactions:
Content-Type:
- application/json
Date:
- Wed, 21 Dec 2022 16:26:18 GMT
- Thu, 05 Dec 2024 12:56:59 GMT
Server:
- cloudflare
Strict-Transport-Security:
- max-age=15724800; includeSubDomains
Transfer-Encoding:
- chunked
X-Locale:
access-control-allow-origin:
- '*'
alt-svc:
- h3=":443"; ma=86400
strict-transport-security:
- max-age=31536000; includeSubDomains
x-locale:
- en
X-RateLimit-Limit:
x-ratelimit-limit:
- '120'
X-RateLimit-Remaining:
x-ratelimit-remaining:
- '119'
status:
code: 200
Expand Down
Loading

0 comments on commit 8587ac1

Please sign in to comment.