Example #1
0
def wizard_by_id(wizard_id):
    service = WizardService(WizardRepository())
    wizard = service.get_wizard_by_id(wizard_id)

    return render_template('wizard/wizard.html',
                           wizard=wizard) if wizard else render_template(
                               'wizard/wizard_not_found.html')
Example #2
0
def delete_wizard():
    service = WizardService(WizardRepository())
    wizards = service.get_all_wizards()

    if request.method == 'POST':
        service.delete_wizard(request.form['wizards_id'])

        return render_template('wizard/wizards.html', wizards=wizards)

    return render_template('wizard/delete_wizard.html', wizards=wizards)
Example #3
0
 def test_wizard_is_created_with_right_parameters(self):
     w = Wizard(1, 'Harry', 17, 1)
     has_received_letter = 1
     wont_turn_into_dark_wizard = 0
     is_not_voldemort_friend = 0
     b = BaseWizardRepository()
     service = WizardService(b)
     create_wizard = service.create_wizard(w.name, w.age,
                                           has_received_letter,
                                           wont_turn_into_dark_wizard,
                                           is_not_voldemort_friend,
                                           w.house_id)
     self.assertTrue(create_wizard)
Example #4
0
 def test_cannot_register_if_is_friend_with_voldemort(self):
     w = Wizard(1, 'Harry', 15, 1)
     has_received_letter = 1
     wont_turn_into_dark_wizard = 0
     is_not_voldemort_friend = 1
     b = BaseWizardRepository()
     service = WizardService(b)
     create_wizard = service.create_wizard(w.name, w.age,
                                           has_received_letter,
                                           wont_turn_into_dark_wizard,
                                           is_not_voldemort_friend,
                                           w.house_id)
     self.assertFalse(create_wizard)
Example #5
0
def create_wizard():
    h_service = HouseService(HouseRepository())
    houses = h_service.get_all_houses()

    if request.method == 'POST':
        service = WizardService(WizardRepository())
        new_wizard = service.create_wizard(
            request.form['wizard_name'],
            request.form['wizard_age'],
            request.form['has_received_letter'],
            request.form['voldemort_friend'],
            request.form['dark_wizard'],
            request.form['house_options'],
        )

        if new_wizard:
            return render_template('wizard/wizard_success.html')
        return render_template('wizard/wizard_error.html')

    return render_template('wizard/new_wizard.html', houses=houses)
Example #6
0
def update_wizard(wizard_id):
    w_service = WizardService(WizardRepository())
    h_service = HouseService(HouseRepository())
    houses = h_service.get_all_houses()

    if request.method == 'POST':
        can_update_wizard = w_service.update_wizard(
            request.form['wizard_id'], request.form['wizard_name'],
            request.form['wizard_age'], request.form['wizard_house'])

        if not can_update_wizard:
            return render_template('wizard/wizard_error.html')

    wizard = w_service.get_wizard_by_id(wizard_id)
    current_house = h_service.get_house_by_id(wizard.house_id)

    if wizard is not None:
        return render_template('wizard/update_wizard.html',
                               wizard=wizard,
                               houses=houses,
                               current_house=current_house)
    else:
        return render_template('wizard/wizard_not_found.html')
Example #7
0
def wizards():
    service = WizardService(WizardRepository())
    wizards = service.get_all_wizards()

    return render_template('wizard/wizards.html', wizards=wizards)