Пример #1
0
 def register_groups(self, count):
     groups = []
     for i in range(count):
         g = baas.Group(self.masterService, "group" + str(i))
         res = g.upsert()
         groups.append(res["name"])
     return groups
Пример #2
0
def remove_all_groups():
    s = create_service(True)

    groups = baas.Group.query(s)
    for g in groups:
        print(g)
        group = baas.Group(s, g["name"])
        group.remove()
Пример #3
0
    def test_remove(self):
        """
        グループ削除
        """
        g = baas.Group(self.masterService, "group1")
        g.upsert()

        # get
        g.remove()
Пример #4
0
    def test_get(self):
        """
        グループ取得
        """
        g = baas.Group(self.masterService, "group1")
        g.upsert()

        # get
        res = g.get()

        assert res["users"] == []
        assert res["groups"] == []
        assert "ACL" in res
Пример #5
0
    def test_upsert(self):
        """
        グループ登録・更新テスト(upsert)
        - 正常登録・更新できること
        """
        g = baas.Group(self.masterService, "group1")

        # create
        create_res = g.upsert()
        assert create_res["users"] == []
        assert create_res["groups"] == []
        assert "ACL" in create_res

        # update
        update_res = g.upsert()
        assert create_res["users"] == []
        assert create_res["groups"] == []
        assert create_res["etag"] != update_res["etag"]
Пример #6
0
    def test_add_remove_member(self, member_num):
        """
        メンバ追加・削除
        """
        user_ids = self.register_users(member_num)
        groups = self.register_groups(member_num + 1)

        g = baas.Group(self.masterService, groups[0])

        # add members
        users = user_ids
        del groups[0]
        res = g.add_members(users=users, groups=groups)

        assert set(res["users"]) == set(users)
        assert set(res["groups"]) == set(groups)

        # remove members
        res = g.remove_members(users=users, groups=groups)

        assert res["users"] == []
        assert res["groups"] == []
Пример #7
0
    def test_upsert_with_option(self):
        """
        グループ登録・更新テスト(upsert)
        - 正常登録・更新できること
        - Etagが不一致の場合はエラーになること
        """
        user_ids = self.register_users(3)
        self.register_groups(3)
        g = baas.Group(self.masterService, "group3")

        # create
        users = [user_ids[0], user_ids[2]]
        groups = ["group1"]
        acl = {"u": ["g:authenticated"]}

        create_res = g.upsert(users=users, groups=groups, acl=acl)
        assert set(create_res["users"]) == set(users)
        assert set(create_res["groups"]) == set(groups)
        assert create_res["ACL"]["u"] == ["g:authenticated"]

        # update
        users = [user_ids[1]]
        groups = ["group0", "group2"]
        acl = {"u": ["g:anonymous"]}
        etag = create_res["etag"]

        update_res = g.upsert(users=users, groups=groups, acl=acl, etag=etag)
        assert set(update_res["users"]) == set(users)
        assert set(update_res["groups"]) == set(groups)
        assert update_res["ACL"]["u"] == ["g:anonymous"]
        assert etag != update_res["etag"]

        # update(etag mismatch)
        with pytest.raises(HTTPError) as ei:
            g.upsert(etag=etag)
        status_code = ei.value.response.status_code
        assert status_code == 409
Пример #8
0
 def get_group(self, expected_result):
     service = mock_service_json_resp(expected_result)
     group = baas.Group(service, "group1")
     return service, group