def test_get_group_managers_oneshot_should_call_api(self, mocked): mocked.return_value = {"items": []} Vk("token").get_group_managers_oneshot("gid", offset=10) mocked.assert_called_with("groups.getMembers", filter="managers", group_id="gid", offset=str(10))
def test_get_users_should_call_oneshot_method_with_chunking(self, mocked): mocked.side_effect = [[], []] Vk("token").get_users(["id1", "id2", "id3", "id4", "id5"], chunk_size=3) mocked.assert_has_calls( [mock.call(["id1", "id2", "id3"]), mock.call(["id4", "id5"])])
def test_get_users_should_return_users(self, mocked): mocked.side_effect = [[ VkUser("id1", first_name="first1", last_name="last1") ], [VkUser("id2", first_name="first2", last_name="last2")]] users = Vk("token").get_users(["id1", "id2"], chunk_size=1) expected = [ VkUser("id1", first_name="first1", last_name="last1"), VkUser("id2", first_name="first2", last_name="last2") ] self.assertEqual([vars(u) for u in users], [vars(e) for e in expected])
def test_get_group_managers_should_return_managers(self, mocked): mocked.side_effect = [[ VkGroupManager("id1", "role1"), VkGroupManager("id2", "role2") ], [VkGroupManager("id3", "role3")], []] managers = Vk("token").get_group_managers("gid") expected = [ VkGroupManager("id1", "role1"), VkGroupManager("id2", "role2"), VkGroupManager("id3", "role3") ] self.assertEqual([vars(m) for m in managers], [vars(e) for e in expected])
def test_get_users_oneshot_should_return_users(self, mocked): mocked.return_value = [{ "id": "id1", "first_name": "first1", "last_name": "last1" }, { "id": "id2", "first_name": "first2", "last_name": "last2" }] users = Vk("token").get_users_oneshot("id1,id2") expected = [ VkUser("id1", first_name="first1", last_name="last1"), VkUser("id2", first_name="first2", last_name="last2") ] self.assertEqual([vars(m) for m in users], [vars(e) for e in expected])
def test_get_group_managers_oneshot_should_return_managers(self, mocked): mocked.return_value = { "items": [{ "id": "id1", "role": "role1" }, { "id": "id2", "role": "role2" }] } managers = Vk("token").get_group_managers_oneshot("gid") expected = [ VkGroupManager("id1", "role1"), VkGroupManager("id2", "role2") ] self.assertEqual([vars(m) for m in managers], [vars(e) for e in expected])
def test_get_group_managers_should_call_oneshot_method_with_pagination( self, mocked): mocked.side_effect = [[VkGroupManager("id", "role")], []] Vk("token").get_group_managers("gid") mocked.assert_has_calls([mock.call("gid", 0), mock.call("gid", 1)])
def test_init_should_validate_args(self): with self.assertRaises(ValueError): Vk("")
def test_get_users_oneshot_should_call_api(self, mocked): mocked.return_value = [] Vk("token").get_users_oneshot(["id1", "id2"]) mocked.assert_called_with("users.get", user_ids="id1,id2")