'@case: HRM001
@description: Create Volunteer Certificate
@TestDoc: https://docs.google.com/spreadsheet/ccc?key=0AmB3hMcgB-3idG1XNGhhRG9QWF81dUlKLXpJaFlCMFE
@Test Wiki: http://eden.sahanafoundation.org/wiki/DeveloperGuidelines/Testing'

def test_hrm001_create_volunteer_certificate(self):

    print '\n'
    if (not current.deployment_settings.get_hrm_use_certificates()):
        return
    if current.deployment_settings.get_hrm_use_skills():
        skill_table = current.s3db['hrm_skill']
        db = current.db
        query = (skill_table.id > 0)
        row = db(query).select(skill_table.name, limitby=(0, 1)).first()
        if row:
            name = row.name
        else:
            skill_table.insert(name='Test')
            db.commit()
            name = 'Test'
    self.login(account='admin', nexturl='vol/certificate/create')
    self.create('hrm_certificate', [('name', 'Advance    First    Aid    ATest'), ('organisation_id', 'Timor-Leste    Red    Cross    Society'), ('expiry', '12')])
    current_url = str(self.browser.current_url)
    current_form = str(current_url.split('/')[(-1)])
    if (current_form == 'certificate_skill'):
        add_btn = self.browser.find_elements_by_id('show-add-btn')
        if (len(add_btn) > 0):
            add_btn[0].click()
            self.create('hrm_certificate_skill', [('skill_id', name)])
