コード例 #1
0
 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))
コード例 #2
0
 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"])])
コード例 #3
0
 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])
コード例 #4
0
 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])
コード例 #5
0
 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])
コード例 #6
0
 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])
コード例 #7
0
 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)])
コード例 #8
0
 def test_init_should_validate_args(self):
     with self.assertRaises(ValueError):
         Vk("")
コード例 #9
0
 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")