Repository: sgaynetdinov/py-vkontakte

Issue:
Пользователь. Опциональные поля (is_friend, can_write_private_message)
Подскажите, пожалуйста, как можно получить опциональные поля пользователя?

- [x] `is_friend`
- [x] `can_write_private_message`

https://vk.com/dev/objects/user

Discussion:

Patch:
diff --git a/README.md b/README.md
index 9ebcf61..b16d2b6 100644
--- a/README.md
+++ b/README.md
@@ -23,13 +23,6 @@
 pip install py-vkontakte
 ```
 
-### Run tests
-
-```
-pip install -r requirements-dev.txt
-pytest
-```
-
 ### First start
 
 ```python
@@ -75,6 +68,7 @@ pytest
 >>> user.is_deleted  # False
 >>> user.is_banned  # False
 >>> user.can_write_private_message  # False
+>>> user.is_friend  # False
 
 >>> user.get_about()
 >>> user.get_activities()
@@ -116,3 +110,10 @@ pytest
 >>> group = api.get_group('telegram')
 >>> user in group  # or 100500 in group
 ```
+
+### Run tests
+
+```
+pip install -r requirements-dev.txt
+pytest
+```
diff --git a/vk/users.py b/vk/users.py
index d52d705..f3b6b2c 100644
--- a/vk/users.py
+++ b/vk/users.py
@@ -24,6 +24,7 @@ class User(VKBase):
         'trending',
         'site',
         'relation',
+        'is_friend'
     )
 
     @classmethod
@@ -40,6 +41,7 @@ class User(VKBase):
         user.site = json_obj.get('site')
         user.relation = cls._relation(json_obj)
         user.relation_partner = cls._relation_partner(json_obj)
+        user.is_friend = bool(json_obj.get('is_friend'))
 
         user.facebook = json_obj.get('facebook')
         user.skype = json_obj.get('skype')


Test patch:
diff --git a/tests/test_user.py b/tests/test_user.py
index 58fb1d6..0417cb0 100644
--- a/tests/test_user.py
+++ b/tests/test_user.py
@@ -34,6 +34,7 @@ def test_user(factory):
     assert user.site == 'http://t.me/durov'
     assert user.relation is None
     assert user.relation_partner is None
+    assert user.is_friend is False
 
 
 def test_user_is_deleted(factory):
@@ -43,6 +44,7 @@ def test_user_is_deleted(factory):
     assert user.is_deleted
     assert not user.is_banned
 
+
 def test_user_is_banned(factory):
     user_json = factory('user_is_deleted.json')
     user_json['deactivated'] = 'banned'
@@ -52,6 +54,7 @@ def test_user_is_banned(factory):
     assert not user.is_deleted
     assert user.is_banned
 
+
 @pytest.mark.parametrize('index, name', [
     (1, 'female'),
     (2, 'male'),
@@ -77,11 +80,12 @@ def test_sex(index, name, factory):
 ])
 def test_platform(index, name, factory):
     user_json = factory('user.json')
-    user_json['last_seen']['platform'] = index 
+    user_json['last_seen']['platform'] = index
     user = User.from_json(None, user_json)
 
     assert user.platform == name
 
+
 @pytest.mark.parametrize('value, expected', [
     (0, False),
     (1, True),
@@ -93,6 +97,7 @@ def test_can_write_private_message(factory, value, expected):
 
     assert user.can_write_private_message is expected
 
+
 def test_without_status(factory):
     user_json = factory('user.json')
     assert 'status' in user_json
@@ -109,9 +114,10 @@ def test_maiden_name(factory):
 
     user_json['maiden_name'] = 'Maiden'
     user = User.from_json(None, user_json)
-    
+
     assert user.maiden_name == 'Maiden'
 
+
 def test_without_last_seen(factory):
     user_json = factory('user.json')
     del user_json['last_seen']
@@ -143,7 +149,7 @@ def test_if_not_field_site(factory):
 @pytest.mark.parametrize('method, field, expected', [
     ('get_activities', 'activities', 'Activities'),
     ('get_activities', 'activities', ''),
-    
+
     ('get_about', 'about', 'About'),
     ('get_about', 'about', ''),
 
@@ -169,7 +175,7 @@ def test_get(mock, method, field, expected):
     user = User.from_json(None, {})
     mock.return_value = [{field: expected}]
 
-    assert getattr(user, method)() == expected 
+    assert getattr(user, method)() == expected
 
 
 def test_not_relation(factory):
@@ -215,7 +221,7 @@ def test_relation_partner(factory):
 def test_get_career(mock, factory):
     user = User.from_json(None, {})
     user_career = [UserCareer.from_json(None, career) for career in factory('user_career.json')['career']]
-    mock.return_value = [factory('user_career.json') ]
+    mock.return_value = [factory('user_career.json')]
 
     assert user.get_career() == user_career
 
@@ -227,6 +233,19 @@ def test_get_career(mock, factory):
 ])
 def test_get_career_empty(mock, career, expected, factory):
     user = User.from_json(None, {})
-    mock.return_value = career 
+    mock.return_value = career
 
     assert user.get_career() == expected
+
+
+@pytest.mark.parametrize('value, expected', [
+    (0, False),
+    (1, True),
+])
+def test_is_friend(factory, value, expected):
+    user_json = factory('user.json')
+    user_json['is_friend'] = value
+
+    user = User.from_json(None, user_json)
+
+    assert user.is_friend is expected