Fixed bug aspect deletion, initial development for contacts
authorMarek Marecki <triviuss@gmail.com>
Sun, 26 May 2013 16:01:54 +0000 (18:01 +0200)
committerMarek Marecki <triviuss@gmail.com>
Sun, 26 May 2013 16:01:54 +0000 (18:01 +0200)
diaspy/models.py
diaspy/people.py
diaspy/streams.py
tests.py

index bedd1ee2207485f44957f6e40fbe123ff444299a..b5a7d50853bd10c7fc075151add9492bec2d130b 100644 (file)
@@ -1,7 +1,7 @@
 #!/usr/bin/env python3
 
 
-class Post:
+class Post():
     """This class represents a post.
 
     .. note::
index 1c33ee6015e6d2ea7732a3daf2d11e1803d1ef68..8e0199dff9d7f1e8b2353fc2390f57cdc84ffa42 100644 (file)
@@ -16,8 +16,8 @@ class User:
     When creating new User() one can pass either guid or handle as 
     an optional parameter. GUID takes precedence over handle.
     """
-    self.data = {}
-    self.stream = []
+    data = {}
+    stream = []
 
     def __init__(self, connection, guid='', handle=''):
         self._connection = connection
@@ -80,3 +80,22 @@ class User:
         """
         request = self._connection.get('people/{0}.json'.format(guid))
         self._postproc(request)
+
+
+class Contacts():
+    """This class represents user's list of contacts.
+    """
+    def __init__(self, connection):
+        self._connection = connection
+
+    def get_only_sharing(self):
+        """Returns contacts who are only sharing with you.
+
+        :returns: list
+        """
+        params = {'set':'only_sharing'}
+        request = self._connection.get('contacts.json', params=params)
+        if request.status_code != 200:
+            raise Exception('status code {0}: cannot get contacts'.format(request.status_code))
+        contacts = [User(user['guid']) for user in request.json()]
+        return contacts
index 50d7b6f347caabd2717690ca21cc82c11f2d9943..770afc61f11395f7e1b03cceecee58e8ee43f790 100644 (file)
@@ -283,11 +283,11 @@ class Aspects(Generic):
         :type name: str
         """
         if aspect_id == -1 and name: aspect_id = self.getAspectID(name)
-        data = {'authenticity_token': self._connection.get_token()}
-        request = self._connection.delete('aspects/{}'.format(aspect_id),
-                                          data=data)
-        if request.status_code not in [404, 500]:
-            raise Exception('wrong status code: {0}'.format(request.status_code))
+        data = {'_method':'delete',
+                'authenticity_token': self._connection.get_token()}
+        request = self._connection.post('aspects/{0}'.format(aspect_id), data=data)
+        if request.status_code not in [200, 302, 500]:
+            raise Exception('wrong status code: {0}: cannot remove aspect'.format(request.status_code))
 
 
 class Commented(Generic):
index 6e1184bdd705cf521d1694c3a2bd30edbb2a89ab..d3b16e4b696f137e1657e1016eeff9d3993af7c1 100644 (file)
--- a/tests.py
+++ b/tests.py
@@ -174,6 +174,14 @@ class UserTests(unittest.TestCase):
         self.assertEqual(type(user.stream), diaspy.streams.Outer)
 
 
+class ContactsTest(unittest.TestCase):
+    def testGetOnlySharing(self):
+        contacts = diaspy.people.Contacts(test_connection)
+        only_sharing = contacts.get_only_sharing()
+        for i in only_sharing:
+            self.assertEqual(diaspy.people.User, type(i))
+
+
 class PostTests(unittest.TestCase):
     def testStringConversion(self):
         s = diaspy.streams.Stream(test_connection)