Tests updated for new lang-fetching
[diaspy.git] / tests.py
index b7f500ff4a764e8d01837ef4aff735d81747a0cd..156f405131e24dbb5841a620ddd5f0a9d85f845f 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -10,6 +10,7 @@ import requests
 import warnings
 #   actual diaspy code
 import diaspy
+from diaspy import client as dclient
 
 
 ####    SETUP STUFF
@@ -39,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)
 
 
@@ -46,42 +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 testGettingStream(self):
-        client = diaspy.client.Client(test_connection)
-        stream = client.get_stream()
-        if len(stream): self.assertEqual(diaspy.models.Post, type(stream[0]))
+class MessagesTests(unittest.TestCase):
+    def testGettingMailbox(self):
+        mailbox = diaspy.messages.Mailbox(test_connection)
+        if mailbox: 
+            for i in range(len(mailbox)):
+                self.assertEqual(diaspy.models.Conversation, type(mailbox[i]))
 
-    def testGettingNotifications(self):
-        client = diaspy.client.Client(test_connection)
-        notifications = client.get_notifications()
-        self.assertEqual(diaspy.notifications.Notifications, type(notifications))
-        if notifications: self.assertEqual(diaspy.models.Notification, type(notifications[0]))
 
-    def testGettingTag(self):
-        client = diaspy.client.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 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 testGettingMailbox(self):
-        client = diaspy.client.Client(test_connection)
-        mailbox = client.get_mailbox()
-        self.assertEqual(list, type(mailbox))
-        self.assertEqual(diaspy.conversations.Conversation, type(mailbox[0]))
+    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):
@@ -114,7 +125,7 @@ class StreamTest(unittest.TestCase):
         stream = diaspy.streams.Stream(test_connection)
         try:
             stream.post(text=post_text, photo='test-image.png')
-        except (StreamError) as e:
+        except (diaspy.errors.StreamError) as e:
             warnings.warn('{0}')
         finally:
             pass
@@ -123,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)
 
@@ -218,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:
@@ -230,6 +221,40 @@ class NotificationsTests(unittest.TestCase):
         else:
             warnings.warn('test not sufficient: no unread notifications were found')
 
+
+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):
+        self.assertIn(('en', 'English'), self.account.getLanguages())
+
+    def testGettingEmail(self):
+        self.assertEqual(testconf.user_email, self.account.getEmail())
+
+
 if __name__ == '__main__': 
     print('Hello World!')
     print('It\'s testing time!')