Skip to content

Commit

Permalink
unittests refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
in-void committed Sep 12, 2013
1 parent 7f91a12 commit cfbdbb7
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 12 deletions.
10 changes: 10 additions & 0 deletions runtests.py
@@ -0,0 +1,10 @@
#!/usr/bin/env python

import os
import sys

from tests import run_tests

sys.path.insert(0, os.path.dirname(__file__))

run_tests()
1 change: 1 addition & 0 deletions setup.py
Expand Up @@ -37,4 +37,5 @@
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3.3',
),
test_suite='tests.suite'
)
58 changes: 57 additions & 1 deletion tests/__init__.py
Expand Up @@ -2,12 +2,17 @@

import sys
import unittest
import pkgutil

from smsapi.client import SmsAPI

# Your API username, and password
API_USERNAME = ''
API_PASSWORD = ''

PHONE_NUMBER = '123123123'
SEND_DELAY = 360


class SmsApiTestCase(unittest.TestCase):

Expand All @@ -26,4 +31,55 @@ def assertIsInstance(self, x, y):
assert isinstance(x, y), "%r is not instance of %r" % (x, y)

def assertIsNotNone(self, x):
assert x is not None, "%x is None" % x
assert x is not None, "%x is None" % x


def import_from_string(name):

if '.' in name:
module, pkg = name.rsplit(".", 1)
else:
return __import__(name)

return getattr(__import__(module, None, None, [pkg]), pkg)


def app_test_suites():

module = import_from_string(__name__)

path = getattr(module, '__path__', None)

if not path:
raise ValueError('%s is not a package' % module)

basename = module.__name__ + '.'

for importer, module_name, is_pkg in pkgutil.iter_modules(path):
mod = basename + module_name

module = import_from_string(mod)

if hasattr(module, 'suite'):
yield module.suite()


def suite():

suite = unittest.TestSuite()

for _suite in app_test_suites():
suite.addTest(_suite)

return suite


def run_tests():
try:
unittest.TextTestRunner(verbosity=2).run(suite())
except Exception as e:
print('Error: %s' % e)


if __name__ == '__main__':
run_tests()
3 changes: 1 addition & 2 deletions tests/client.py
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-

import unittest
from . import SmsApiTestCase
from tests import SmsApiTestCase
from smsapi.responses import ApiResponse


Expand Down Expand Up @@ -51,7 +51,6 @@ def test_edit_subuser(self):
self.assertEqual(response2.limit, 100)
self.assertTrue(response2.active)

@unittest.skip('no json response')
def test_subuser_details(self):

self.api.action('add_subuser', {
Expand Down
6 changes: 3 additions & 3 deletions tests/mms.py
Expand Up @@ -3,7 +3,7 @@
import os
import time
import unittest
from tests import SmsApiTestCase
from tests import SmsApiTestCase, PHONE_NUMBER, SEND_DELAY
from smsapi.responses import ApiResponse


Expand All @@ -15,9 +15,9 @@ def setUp(self):
self.api.service('mms')

self.message_params = {
'to': '111222333',
'to': PHONE_NUMBER,
'subject': 'subject',
'date': time.time() + 360
'date': time.time() + SEND_DELAY
}

dir_path = os.path.dirname(__file__)
Expand Down
6 changes: 3 additions & 3 deletions tests/sms.py
Expand Up @@ -2,7 +2,7 @@

import time
import unittest
from tests import SmsApiTestCase
from tests import SmsApiTestCase, PHONE_NUMBER, SEND_DELAY
from smsapi.responses import ApiResponse


Expand All @@ -15,8 +15,8 @@ def setUp(self):

self.message_params = {
'content': 'test message',
'to': '111222333',
'date': time.time() + 360
'to': PHONE_NUMBER,
'date': time.time() + SEND_DELAY
}

self.message_id = None
Expand Down
6 changes: 3 additions & 3 deletions tests/vms.py
Expand Up @@ -3,7 +3,7 @@
import os
import time
import unittest
from tests import SmsApiTestCase
from tests import SmsApiTestCase, PHONE_NUMBER, SEND_DELAY
from smsapi.responses import ApiResponse, ApiError


Expand All @@ -17,9 +17,9 @@ def setUp(self):
dir_path = os.path.dirname(__file__)

self.message_params = {
'to': '111222333',
'to': PHONE_NUMBER,
'content': '%s%s' % (dir_path, '/static/audio2.wav'),
'date': time.time() + 360
'date': time.time() + SEND_DELAY
}

self.message_id = None
Expand Down

0 comments on commit cfbdbb7

Please sign in to comment.