<commit_before>#encoding: utf-8

require 'spec_helper'

describe 'usergroup' do

  context 'when not exists' do
    it "should be integer id" do
      usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
      expect(usergroupid).to be_kind_of(Integer)
    end
  end

  context 'when exists' do
    before do
      @usergroup = gen_name 'usergroup'
      @usergroupid = zbx.usergroups.create(:name => @usergroup)
      @user = gen_name 'user'
      @userid = zbx.users.create(
        :alias => @user,
        :name => @user,
        :surname => @user,
        :passwd => <PASSWORD>,
        :usrgrps => [@usergroupid]
      )

      @user2 = gen_name 'user'

      @userid2 = zbx.users.create(
        :alias => @user2,
        :name => @user2,
        :surname => @user2,
        :passwd => <PASSWORD>,
        :usrgrps => [zbx.usergroups.create(:name => gen_name('usergroup'))]
      )
    end

    describe 'get_or_create' do
      it "should return id" do
        expect(zbx.usergroups.get_or_create(:name => @usergroup)).to eq @usergroupid
      end
    end

    describe 'add_user' do
      it "should return id" do
        expect(zbx.usergroups.add_user(
            :usrgrpids => [@usergroupid],
            :userids => [@userid2]
        )).to eq @usergroupid
      end
    end

    describe 'update_users' do
      it "should return id" do
        expect(zbx.usergroups.update_users(
            :usrgrpids => [@usergroupid],
            :userids => [@userid2]
        )).to eq @usergroupid
      end
    end

    describe 'set_perms' do
      it "should return id" do
        expect(zbx.usergroups.set_perms(
          :usrgrpid => @usergroupid,
          :hostgroupids => zbx.hostgroups.all.values,
          :permission => 3
        )).to eq @usergroupid
      end
    end

    describe 'delete' do
      it "should raise error when has users with only one group" do
        expect { zbx.usergroups.delete(@usergroupid) }.to raise_error(ZabbixApi::ApiError)
      end

      it "should return id of deleted group" do
        usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))

        expect(zbx.usergroups.delete(usergroupid)).to eq usergroupid
      end
    end
  end
end
<commit_msg>Fail - usergroup when exists update_users should return id<commit_after>#encoding: utf-8

require 'spec_helper'

describe 'usergroup' do

  context 'when not exists' do
    it "should be integer id" do
      usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))
      expect(usergroupid).to be_kind_of(Integer)
    end
  end

  context 'when exists' do
    before do
      @usergroup = gen_name 'usergroup'
      @usergroupid = zbx.usergroups.create(:name => @usergroup)
      @user = gen_name 'user'
      @userid = zbx.users.create(
        :alias => @user,
        :name => @user,
        :surname => @user,
        :passwd => <PASSWORD>,
        :usrgrps => [@usergroupid]
      )

      @usergroup2 = gen_name 'usergroup'
      @usergroupid2 = zbx.usergroups.create(:name => @usergroup2)
      @user2 = gen_name 'user'
      @userid2 = zbx.users.create(
        :alias => @user2,
        :name => @user2,
        :surname => @user2,
        :passwd => <PASSWORD>,
        :usrgrps => [@usergroupid2]
      )
    end

    describe 'get_or_create' do
      it "should return id" do
        expect(zbx.usergroups.get_or_create(:name => @usergroup)).to eq @usergroupid
      end
    end

    describe 'add_user' do
      it "should return id" do
        expect(zbx.usergroups.add_user(
            :usrgrpids => [@usergroupid],
            :userids => [@userid2]
        )).to eq @usergroupid
      end
    end

    describe 'update_users' do
      it "should return id" do
        expect(zbx.usergroups.update_users(
            :usrgrpids => [@usergroupid2],
            :userids => [@userid2]
        )).to eq @usergroupid2
      end
    end

    describe 'set_perms' do
      it "should return id" do
        expect(zbx.usergroups.set_perms(
          :usrgrpid => @usergroupid,
          :hostgroupids => zbx.hostgroups.all.values,
          :permission => 3
        )).to eq @usergroupid
      end
    end

    describe 'delete' do
      it "should raise error when has users with only one group" do
        expect { zbx.usergroups.delete(@usergroupid) }.to raise_error(ZabbixApi::ApiError)
      end

      it "should return id of deleted group" do
        usergroupid = zbx.usergroups.create(:name => gen_name('usergroup'))

        expect(zbx.usergroups.delete(usergroupid)).to eq usergroupid
      end
    end
  end
end

{'fraction_non_alphanumeric': 0.1151409220013109, 'fraction_numerical': 0.005243609351103343, 'mean_word_length': 2.2422096317280453, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 51, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1828311', 'n_tokens_mistral': 1527, 'n_tokens_neox': 1469, 'n_words': 366}