def test_relation(factory, index, expected): user_json = factory('user.json') user_json['relation'] = index user = User.from_json(None, user_json) assert user.relation == expected
def test_user(factory): user = User.from_json(None, factory('user.json')) assert user.id == 1 assert user.first_name == 'Павел' assert user.last_name == 'Дуров' assert not user.maiden_name assert user.sex == 'male' assert user.nickname == '' assert user.screen_name == 'durov' assert user.domain == 'durov' assert user.bdate == '10.10.1984' assert user.status == '道德經' assert not user.is_deactivated assert not user.is_deleted assert not user.is_banned assert user.is_verified assert user.last_seen == datetime.datetime.utcfromtimestamp(1535548834) assert user.platform == 'web (vk.com)' assert not user.is_trending assert user.facebook == '501012028' assert user.skype is None assert user.twitter == 'durov' assert user.livejournal is None assert user.instagram == 'durov' 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_not_relation(factory): user_json = factory('user.json') del user_json['relation'] user = User.from_json(None, user_json) assert user.relation is None
def test_if_not_field_site(factory): user_json = factory('user.json') del user_json['site'] user = User.from_json(None, user_json) assert user.site is None
def test_not_time_in_last_seen(factory): user_json = factory('user.json') del user_json['last_seen']['time'] user = User.from_json(None, user_json) assert user.last_seen is None
def test_without_last_seen(factory): user_json = factory('user.json') del user_json['last_seen'] user = User.from_json(None, user_json) assert user.last_seen is None
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
def test_maiden_name(factory): user_json = factory('user.json') assert 'maiden' not in user_json user_json['maiden_name'] = 'Maiden' user = User.from_json(None, user_json) assert user.maiden_name == 'Maiden'
def test_user_is_banned(factory): user_json = factory('user_is_deleted.json') user_json['deactivated'] = 'banned' user = User.from_json(None, user_json) assert user.is_deactivated assert not user.is_deleted assert user.is_banned
def test_without_status(factory): user_json = factory('user.json') assert 'status' in user_json del user_json['status'] user = User.from_json(None, user_json) assert user.status == ''
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')] assert user.get_career() == user_career
def test_relation_partner(factory): user_json = factory('user.json') user_json['relation_partner'] = { 'id': 100500, 'first_name': 'Abc', 'last_name': 'Def' } user = User.from_json(None, user_json) assert user.relation_partner == 100500
group = Group.from_json(None, factory('group_detail.json')) assert group.id == 1 assert group.name == "ВКонтакте API" assert group.screen_name == 'apiclub' assert group.is_closed == False assert group.type == 'group' assert group.is_trending == False @pytest.mark.parametrize("user", [ "100500", 100500.0, ]) def test_contains_fail(factory, user): group = Group.from_json(None, factory('group_detail.json')) with pytest.raises(TypeError, match="is not `User`"): user in group @pytest.mark.parametrize("user", [ User.from_json(None, {"id": 100500}), 100500, ]) def test_contains(factory, user): session = type("", (object,), {"fetch": lambda *args, **kw: True}) group = Group.from_json(session, factory('group_detail.json')) assert user in group
def test_can_write_private_message(factory, value, expected): user_json = factory('user.json') user_json['can_write_private_message'] = value user = User.from_json(None, user_json) assert user.can_write_private_message is expected
def test_get(mock, method, field, expected): user = User.from_json(None, {}) mock.return_value = [{field: expected}] assert getattr(user, method)() == expected
def test_platform(index, name, factory): user_json = factory('user.json') user_json['last_seen']['platform'] = index user = User.from_json(None, user_json) assert user.platform == name
def test_sex(index, name, factory): user_json = factory('user.json') user_json['sex'] = index user = User.from_json(None, user_json) assert user.sex == name
def test_user_is_deleted(factory): user = User.from_json(None, factory('user_is_deleted.json')) assert user.is_deactivated assert user.is_deleted assert not user.is_banned
def test_get_career_empty(mock, career, expected, factory): user = User.from_json(None, {}) mock.return_value = career assert user.get_career() == expected