From fab8b7368b35ad8dde0adb3f5ab180b6a8af8dd3 Mon Sep 17 00:00:00 2001 From: Marek Marecki Date: Fri, 29 Mar 2013 12:12:29 +0100 Subject: [PATCH] Two tests added --- diaspy/client.py | 4 +--- test.sh | 3 +++ testconf.py | 17 +++++++++++++++++ tests.py | 33 ++++++++++++++++++++------------- 4 files changed, 41 insertions(+), 16 deletions(-) create mode 100755 test.sh create mode 100644 testconf.py diff --git a/diaspy/client.py b/diaspy/client.py index 37691c2..5569359 100644 --- a/diaspy/client.py +++ b/diaspy/client.py @@ -34,7 +34,6 @@ class Client: :param string: URL to get without the pod's URL and slash eg. 'stream'. :type string: str """ - data = return self.session.get('{0}/{1}'.format(self.pod, string)) def get_token(self): @@ -278,10 +277,9 @@ class Client: """This functions returns a list of messages found in the conversation. :returns: list -- list of Conversation objects. - """ - data = {'authenticity_token': self.get_token()} + #r = self.session.get('{0}/conversations.json'.format(self.pod)) r = self.session.get('{0}/conversations.json'.format(self.pod)) if r.status_code != 200: diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..9152bc8 --- /dev/null +++ b/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/bash + +python -m unittest --verbose --catch --failfast tests.py diff --git a/testconf.py b/testconf.py new file mode 100644 index 0000000..8ad0abf --- /dev/null +++ b/testconf.py @@ -0,0 +1,17 @@ +## Configuration file for diapsy's +## test suite (./tests.py) +## +## It is essential that a developer/tester fills +## the variables because thay are supplied empty +## by default - after first commit the `testconf.py` +## was added to .gitignore to avoid posting personal +## data of developer/tester. + + +# You have to set the varaiables yourself. +# Their values have to be valid. + +# __pod__ = 'https://pod.example.com' +__pod__ = '' +__username__ = '' +__passwd__ = '' diff --git a/tests.py b/tests.py index 72be51d..070c6da 100644 --- a/tests.py +++ b/tests.py @@ -11,27 +11,34 @@ import diaspy #### test suite configuration variables: can be adjusted to your liking -# pod used by tests (has to be valid) -__pod__ = 'http://pod.orkz.net' -__username__ = 'testuser' -__passwd__ = 'testpassword' +import testconf +__pod__ = testconf.__pod__ +__username__ = testconf.__username__ +__passwd__ = testconf.__passwd__ class ClientTests(unittest.TestCase): def testInitialization(self): - """This test checks initialization of Client() instance. - """ client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) self.assertEqual(__pod__, client.pod) self.assertEqual(__username__, client._username) self.assertEqual(__passwd__, client._password) - self.assertEqual(None, client._post_data) + self.assertEqual({}, client._post_data) self.assertEqual(client._token_regex, re.compile(r'content="(.*?)"\s+name="csrf-token')) - self.assertEqual(client._login_data['user[username]'], 'testuser') - self.assertEqual(client._login_data['user[password]'], 'testpassword') + self.assertEqual(client._login_data['user[username]'], __username__) + self.assertEqual(client._login_data['user[password]'], __passwd__) self.assertEqual(client._login_data['authenticity_token'], client.get_token()) -if __name__ == '__main__': - __passwd__ = getpass.getpass(prompt='Password used for testing: ') - if __passwd__ == '': __passwd__ = 'testpassword' - unittest.main() + def testGettingTag(self): + client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) + tag = client.get_tag('foo') + self.assertEqual(list, type(tag)) + if tag: self.assertEqual(diaspy.models.Post, type(tag[0])) + + def testGettingMailbox(self): + client = diaspy.client.Client(pod=__pod__, username=__username__, password=__passwd__) + mailbox = client.get_mailbox() + self.assertEqual(list, type(mailbox)) + self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0])) + +if __name__ == '__main__': unittest.main() -- 2.25.1