-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
280 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
from kalyke.clients import __Client | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"use_sandbox, expect", | ||
[ | ||
(True, "https://api.sandbox.push.apple.com"), | ||
(False, "https://api.push.apple.com"), | ||
], | ||
) | ||
def test_base_url(use_sandbox, expect): | ||
client = __Client() | ||
client.use_sandbox = use_sandbox | ||
|
||
assert client._base_url == expect |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
import pytest | ||
|
||
from kalyke.clients import __Client | ||
from kalyke.exceptions import ( | ||
BadCertificate, | ||
BadCertificateEnvironment, | ||
BadCollapseId, | ||
BadDeviceToken, | ||
BadExpirationDate, | ||
BadMessageId, | ||
BadPath, | ||
BadPriority, | ||
BadTopic, | ||
DeviceTokenNotForTopic, | ||
DuplicateHeaders, | ||
ExpiredProviderToken, | ||
ExpiredToken, | ||
Forbidden, | ||
IdleTimeout, | ||
InternalServerError, | ||
InvalidProviderToken, | ||
InvalidPushType, | ||
MethodNotAllowed, | ||
MissingDeviceToken, | ||
MissingProviderToken, | ||
MissingTopic, | ||
PayloadEmpty, | ||
PayloadTooLarge, | ||
ServiceUnavailable, | ||
Shutdown, | ||
TooManyProviderTokenUpdates, | ||
TooManyRequests, | ||
TopicDisallowed, | ||
Unregistered, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"reason, expect", | ||
[ | ||
( | ||
"BadCollapseId", | ||
BadCollapseId, | ||
), | ||
( | ||
"BadDeviceToken", | ||
BadDeviceToken, | ||
), | ||
( | ||
"BadExpirationDate", | ||
BadExpirationDate, | ||
), | ||
( | ||
"BadMessageId", | ||
BadMessageId, | ||
), | ||
( | ||
"BadPriority", | ||
BadPriority, | ||
), | ||
( | ||
"BadTopic", | ||
BadTopic, | ||
), | ||
( | ||
"DeviceTokenNotForTopic", | ||
DeviceTokenNotForTopic, | ||
), | ||
( | ||
"DuplicateHeaders", | ||
DuplicateHeaders, | ||
), | ||
( | ||
"IdleTimeout", | ||
IdleTimeout, | ||
), | ||
( | ||
"InvalidPushType", | ||
InvalidPushType, | ||
), | ||
( | ||
"MissingDeviceToken", | ||
MissingDeviceToken, | ||
), | ||
( | ||
"MissingTopic", | ||
MissingTopic, | ||
), | ||
( | ||
"PayloadEmpty", | ||
PayloadEmpty, | ||
), | ||
( | ||
"TopicDisallowed", | ||
TopicDisallowed, | ||
), | ||
( | ||
"BadCertificate", | ||
BadCertificate, | ||
), | ||
( | ||
"BadCertificateEnvironment", | ||
BadCertificateEnvironment, | ||
), | ||
( | ||
"ExpiredProviderToken", | ||
ExpiredProviderToken, | ||
), | ||
( | ||
"Forbidden", | ||
Forbidden, | ||
), | ||
( | ||
"InvalidProviderToken", | ||
InvalidProviderToken, | ||
), | ||
( | ||
"MissingProviderToken", | ||
MissingProviderToken, | ||
), | ||
( | ||
"BadPath", | ||
BadPath, | ||
), | ||
( | ||
"MethodNotAllowed", | ||
MethodNotAllowed, | ||
), | ||
( | ||
"ExpiredToken", | ||
ExpiredToken, | ||
), | ||
( | ||
"Unregistered", | ||
Unregistered, | ||
), | ||
( | ||
"PayloadTooLarge", | ||
PayloadTooLarge, | ||
), | ||
( | ||
"TooManyProviderTokenUpdates", | ||
TooManyProviderTokenUpdates, | ||
), | ||
( | ||
"TooManyRequests", | ||
TooManyRequests, | ||
), | ||
( | ||
"InternalServerError", | ||
InternalServerError, | ||
), | ||
( | ||
"ServiceUnavailable", | ||
ServiceUnavailable, | ||
), | ||
( | ||
"Shutdown", | ||
Shutdown, | ||
), | ||
], | ||
) | ||
def test_handle_error(reason, expect): | ||
client = __Client() | ||
exception = client._handle_error(error_json={"reason": reason}) | ||
|
||
assert type(exception) == expect | ||
|
||
|
||
def test_attributed_error(): | ||
client = __Client() | ||
|
||
with pytest.raises(AttributeError) as e: | ||
_ = client._handle_error(error_json={"reason": "Unknown"}) | ||
|
||
assert str(e.value) == "module 'kalyke.exceptions' has no attribute 'Unknown'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import pytest | ||
|
||
from kalyke import ApnsConfig | ||
from kalyke.clients import __Client | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_not_implemented_error(): | ||
client = __Client() | ||
with pytest.raises(NotImplementedError) as e: | ||
_ = client._init_client( | ||
apns_config=ApnsConfig(topic="com.example.App"), | ||
) | ||
|
||
assert str(e.value) == "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import pytest | ||
|
||
from kalyke.clients import __Client | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"use_sandbox, expect", | ||
[ | ||
( | ||
True, | ||
"https://api.sandbox.push.apple.com/3/device/stub_device_token", | ||
), | ||
( | ||
False, | ||
"https://api.push.apple.com/3/device/stub_device_token", | ||
), | ||
], | ||
) | ||
def test_make_url(use_sandbox, expect): | ||
client = __Client() | ||
client.use_sandbox = use_sandbox | ||
url = client._make_url(device_token="stub_device_token") | ||
|
||
assert url == expect | ||
|
||
|
||
def test_attribute_error(): | ||
client = __Client() | ||
with pytest.raises(AttributeError) as e: | ||
_ = client._make_url(device_token="stub_device_token") | ||
|
||
assert str(e.value) == "'__Client' object has no attribute 'use_sandbox'" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import pytest | ||
|
||
from kalyke import ApnsConfig | ||
from kalyke.clients import __Client | ||
|
||
|
||
@pytest.mark.asyncio | ||
async def test_not_implemented_error(): | ||
client = __Client() | ||
with pytest.raises(NotImplementedError) as e: | ||
_ = await client.send_message( | ||
device_token="stub_device_token", | ||
payload={}, | ||
apns_config=ApnsConfig(topic="com.example.App"), | ||
) | ||
|
||
assert str(e.value) == "" |