Esempio n. 1
0
    def test_load_by_name(self):
        w1 = Watch('codesprinters', 10, "go codesprinters")
        w1.save(self.connection)
        w2 = Watch('google', 10, "go google")
        w2.save(self.connection)

        w2loaded = Watch.load_by_name('google', self.connection)
        self.compare_watches(w2, w2loaded)

        w1loaded = Watch.load_by_name('codesprinters', self.connection)
        self.compare_watches(w1, w1loaded)
Esempio n. 2
0
def validate_twill_form(connection, data, watch=None):
    """ Checks if data (dictionary) contains valid watch definition.
        Returns a tuple (valid_dict, list of errors),
        where valid_dict contains the successfully validated values
    """
    # no need for any fancy form handling library for this single form
    valid_dict = {}
    errors = []

    name = data.get('name', '')
    if not name:
        errors.append(u"Watch name is missing")
    else:
        other_watch = Watch.load_by_name(name, connection)
        if other_watch is not None and other_watch.id != watch.id:
            errors.append(u"Watch with this name already exists")
        else:
            valid_dict['name'] = name

    interval = data.get('interval', None)
    if not interval:
        errors.append(u"Interval is missing")
    else:
        try:
            valid_dict['interval'] = int(interval)
        except ValueError:
            errors.append(u"Invalid number (interval)")

    reminder_interval = data.get('reminder_interval', '').strip()
    if reminder_interval:
        try:
            valid_dict['reminder_interval'] = int(reminder_interval)
        except ValueError:
            errors.append(u"Invalid number (reminder interval)")
    else:
        valid_dict['reminder_interval'] = None

    script = data.get('script', None)
    if not script or script.isspace():
        errors.append(u"Script is missing")
    else:
        valid_dict['script'] = script

    valid_dict['emails'] = data.get('emails', '')

    return valid_dict, errors