This repository has been archived by the owner on Dec 19, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
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
2 changed files
with
102 additions
and
51 deletions.
There are no files selected for viewing
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
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 |
---|---|---|
@@ -1,13 +1,68 @@ | ||
# coding: utf-8 | ||
import unittest | ||
import httpretty | ||
from urlparse import urljoin | ||
from datetime import datetime, timedelta | ||
from smsaero.api import SmsAero | ||
from smsaero.api import ( | ||
DateValueError, UnexpectedMessageFormat, UnexpectedResponse, InvalidUse | ||
) | ||
|
||
|
||
class TestApi(unittest.TestCase): | ||
def setUp(self): | ||
self.api = SmsAero('test', 'test') | ||
|
||
def test__check_response(self): | ||
try: | ||
self.api._check_response( | ||
"incorrect language in '' use the cyrillic or roman alphabet") | ||
self.assertTrue(False) | ||
except UnexpectedMessageFormat: | ||
pass | ||
|
||
try: | ||
self.api._check_response('some text') | ||
self.assertTrue(False) | ||
except UnexpectedResponse: | ||
pass | ||
|
||
try: | ||
self.api._check_response( | ||
'{"reason": "empty field", "result": "reject"}') | ||
self.assertTrue(False) | ||
except InvalidUse: | ||
pass | ||
|
||
@httpretty.activate | ||
def test_send(self): | ||
pass | ||
httpretty.register_uri( | ||
httpretty.POST, | ||
urljoin(SmsAero.URL_GATE, '/send/'), | ||
body='{"id": 33166386, "result": "accepted"}', | ||
status=200, | ||
content_type='text/json', | ||
) | ||
|
||
response = self.api.send('89111111111', 'message') | ||
self.assertEqual(response['result'], u'accepted') | ||
|
||
response = self.api.send( | ||
'89111111111', | ||
'message', | ||
date=datetime.now() + timedelta(1), | ||
) | ||
self.assertEqual(response['result'], u'accepted') | ||
|
||
try: | ||
response = self.api.send( | ||
'8911111111', | ||
'message', | ||
date='datetime.now() + timedelta(1)', | ||
) | ||
self.assertTrue(False) | ||
except DateValueError: | ||
pass | ||
|
||
if __name__ == '__main__': | ||
unittest.main() |