Two tests added
authorMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 11:12:29 +0000 (12:12 +0100)
committerMarek Marecki <triviuss@gmail.com>
Fri, 29 Mar 2013 11:12:29 +0000 (12:12 +0100)
diaspy/client.py
test.sh [new file with mode: 0755]
testconf.py [new file with mode: 0644]
tests.py

index 37691c2c19cfc2c53f05ed5b4086ee8ef52289cf..556935931d12a8e4ecc88bb9d575e41588408150 100644 (file)
@@ -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 (executable)
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 (file)
index 0000000..8ad0abf
--- /dev/null
@@ -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__ = ''
index 72be51d0ae3ffb1daad97da17b681eb0757428b4..070c6dac5c602ab22e1acc3e641ba81308bb1331 100644 (file)
--- 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()