Style fixes and small adjustments in regular expressions used in
[diaspy.git] / tests.py
index 5e0adfa06c444d0972846c03d18167d849ad45a7..60ddd5e7084f95f81b196bd3b78581faa8dd81cc 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -40,6 +40,15 @@ test_connection = diaspy.connection.Connection(pod=__pod__, username=__username_
 test_connection.login()
 print('[ CONNECTED ]\n')
 
+# Setup test aspects
+print('Adding test aspects...\t', end='')
+diaspy.streams.Aspects(test_connection).add(testconf.test_aspect_name_fake)
+testconf.test_aspect_id = diaspy.streams.Aspects(test_connection).add(testconf.test_aspect_name).id
+print('OK')
+
+print([i['name'] for i in test_connection.getUserInfo()['aspects']])
+
+
 post_text = '#diaspy test no. {0}'.format(test_count)
 
 
@@ -47,31 +56,43 @@ post_text = '#diaspy test no. {0}'.format(test_count)
 ####        TEST SUITE CODE        ####
 #######################################
 class ConnectionTest(unittest.TestCase):
-    def testLoginWithoutUsername(self):
-        connection = diaspy.connection.Connection(pod=__pod__)
-        self.assertRaises(diaspy.connection.LoginError, connection.login, password='foo')
-
-    def testLoginWithoutPassword(self):
-        connection = diaspy.connection.Connection(pod=__pod__)
-        self.assertRaises(diaspy.connection.LoginError, connection.login, username='user')
-
     def testGettingUserInfo(self):
         info = test_connection.getUserInfo()
         self.assertEqual(dict, type(info))
 
 
-class ClientTests(unittest.TestCase):
-    def testGettingTag(self):
-        client = dclient.Client(test_connection)
-        tag = client.get_tag('foo')
-        self.assertEqual(diaspy.streams.Generic, type(tag))
-        if tag: self.assertEqual(diaspy.models.Post, type(tag[0]))
-
+class MessagesTests(unittest.TestCase):
     def testGettingMailbox(self):
-        client = dclient.Client(test_connection)
-        mailbox = client.get_mailbox()
-        self.assertEqual(list, type(mailbox))
-        self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
+        mailbox = diaspy.messages.Mailbox(test_connection)
+        if mailbox: 
+            for i in range(len(mailbox)):
+                self.assertEqual(diaspy.models.Conversation, type(mailbox[i]))
+
+
+class AspectsTests(unittest.TestCase):
+    def testAspectsGettingID(self):
+        aspects = diaspy.streams.Aspects(test_connection)
+        id = aspects.getAspectID(testconf.test_aspect_name)
+        self.assertEqual(testconf.test_aspect_id, id)
+
+    def testAspectsRemoveById(self):
+        aspects = diaspy.streams.Aspects(test_connection)
+        for i in test_connection.getUserInfo()['aspects']:
+            if i['name'] == testconf.test_aspect_name:
+                print(i['id'], end=' ')
+                aspects.remove(id=i['id'])
+                break
+        names = [i['name'] for i in test_connection.getUserInfo()['aspects']]
+        print(names)
+        self.assertNotIn(testconf.test_aspect_name, names)
+
+    def testAspectsRemoveByName(self):
+        aspects = diaspy.streams.Aspects(test_connection)
+        print(testconf.test_aspect_name_fake, end=' ')
+        aspects.remove(name=testconf.test_aspect_name_fake)
+        names = [i['name'] for i in test_connection.getUserInfo()['aspects']]
+        print(names)
+        self.assertNotIn(testconf.test_aspect_name_fake, names)
 
 
 class StreamTest(unittest.TestCase):
@@ -113,26 +134,6 @@ class StreamTest(unittest.TestCase):
         ft = diaspy.streams.FollowedTags(test_connection)
         ft.add('test')
 
-    def testAspectsAdd(self):
-        aspects = diaspy.streams.Aspects(test_connection)
-        aspects.add(testconf.test_aspect_name_fake)
-        testconf.test_aspect_id = aspects.add(testconf.test_aspect_name).id
-
-    def testAspectsGettingID(self):
-        aspects = diaspy.streams.Aspects(test_connection)
-        id = aspects.getAspectID(testconf.test_aspect_name)
-        self.assertEqual(testconf.test_aspect_id, id)
-
-    def testAspectsRemoveById(self):
-        aspects = diaspy.streams.Aspects(test_connection)
-        aspects.remove(testconf.test_aspect_id)
-        self.assertEqual(-1, aspects.getAspectID(testconf.test_aspect_name))
-
-    def testAspectsRemoveByName(self):
-        aspects = diaspy.streams.Aspects(test_connection)
-        aspects.remove(name=testconf.test_aspect_name_fake)
-        self.assertEqual(-1, aspects.getAspectID(testconf.test_aspect_name_fake))
-
     def testActivity(self):
         activity = diaspy.streams.Activity(test_connection)
 
@@ -208,7 +209,7 @@ class PostTests(unittest.TestCase):
 
 
 class NotificationsTests(unittest.TestCase):
-    def testMarkgingRead(self):
+    def testMarkingRead(self):
         notifications = diaspy.notifications.Notifications(test_connection)
         notif = None
         for n in notifications:
@@ -222,9 +223,37 @@ class NotificationsTests(unittest.TestCase):
 
 
 class SettingsTests(unittest.TestCase):
+    profile = diaspy.settings.Profile(test_connection)
+    account = diaspy.settings.Account(test_connection)
+
+    def testGettingName(self):
+        self.assertEqual(testconf.user_names_tuple, self.profile.getName())
+
+    def testGettingLocation(self):
+        self.assertEqual(testconf.user_location_string, self.profile.getLocation())
+
+    def testGettingGender(self):
+        self.assertEqual(testconf.user_gender_string, self.profile.getGender())
+
+    def testGettingBirthDate(self):
+        self.assertEqual(testconf.user_date_of_birth, self.profile.getBirthDate(named_month=False))
+        self.assertEqual(testconf.user_date_of_birth_named, self.profile.getBirthDate(named_month=True))
+
+    def testGettingInfoIfProfileIsSearchable(self):
+        self.assertEqual(testconf.user_is_searchable, self.profile.isSearchable())
+
+    def testGettingInfoIfProfileIsNSFW(self):
+        self.assertEqual(testconf.user_is_nsfw, self.profile.isNSFW())
+
+    def testGettingTags(self):
+        self.assertEqual(sorted(testconf.user_tags), sorted(self.profile.getTags()))
+
     def testGettingLanguages(self):
-        settings = diaspy.settings.Settings(test_connection)
-        self.assertIn(('English', 'en'), settings.getLanguages())
+        self.assertIn(('English', 'en'), self.account.getLanguages())
+
+    def testGettingEmail(self):
+        self.assertEqual(testconf.user_email, self.account.getEmail())
+
 
 if __name__ == '__main__': 
     print('Hello World!')