def test_saving(self):
        w1 = Watch('codesprinters', 10, "go codesprinters")
        w1.save(self.connection)
        w2 = Watch('google', 10, "go google")
        w2.save(self.connection)

        w1loaded = Watch.load(w1.id, self.connection)
        w2loaded = Watch.load(w2.id, self.connection)

        self.compare_watches(w1, w1loaded)
        self.compare_watches(w2, w2loaded)
    def test_deleting(self):
        w1 = Watch('codesprinters', 10, "go codesprinters")
        w1.save(self.connection)
        w2 = Watch('google', 10, "go google")
        w2.save(self.connection)

        w2.delete(self.connection)

        w1loaded = Watch.load(w1.id, self.connection)
        w2loaded = Watch.load(w2.id, self.connection)

        self.compare_watches(w1, w1loaded)
        assert w2loaded is None
    def test_load_by_id(self):
        w1 = Watch('codesprinters', 10, "go codesprinters")
        w1.save(self.connection)
        w2 = Watch('google', 10, "go google")
        w2.save(self.connection)


        w2loaded = Watch.load(w2.id, self.connection)
        self.compare_watches(w2, w2loaded)

        w1loaded = Watch.load(w1.id, self.connection)
        self.compare_watches(w1, w1loaded)

        w3loaded = Watch.load(w1.id + w2.id, self.connection)
        assert w3loaded is None
Exemple #4
0
    def edit(self, **kwargs):
        connection = get_db_connection(self.config)

        try:
            watch = Watch.load(self.id, connection)
                
            if not watch:
                raise cherrypy.NotFound()

            if cherrypy.request.method == 'POST':
                valid_dict, errors = validate_twill_form(connection, kwargs, watch)
                if len(errors):
                    connection.rollback()
                else:
                    for k,v in valid_dict.iteritems():
                        setattr(watch, k, v)
                    watch.update(connection)
                    connection.commit()
                    self.worker_set.restart(self.id)
                    raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
            else:
                errors = []

            return self.render('edit.html', watch=watch, data=kwargs, errors=errors)
        except Exception:
            connection.rollback()
            raise
Exemple #5
0
 def restart(self):
     watch = Watch.load(self.id, get_db_connection(self.config))
     if not watch:
         raise cherrypy.NotFound()
     
     self.worker_set.restart(self.id)
     raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
Exemple #6
0
    def check_now(self):
        """ Force a check immediately """
        watch = Watch.load(self.id, get_db_connection(self.config))
        if not watch:
            raise cherrypy.NotFound()

        self.worker_set.check_now(self.id)
        raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)
    def test_updating(self):
        w1 = Watch('codesprinters', 10, "go codesprinters")
        w1.save(self.connection)
        w2 = Watch('google', 10, "go google")
        w2.save(self.connection)

        w1loaded = Watch.load(w1.id, self.connection)
        w2loaded = Watch.load(w2.id, self.connection)

        self.compare_watches(w1, w1loaded)
        self.compare_watches(w2, w2loaded)

        w1.script = "go http://codesprinters.com"
        w1.update(self.connection)
        w1loaded = Watch.load(w1.id, self.connection)
        w2loaded = Watch.load(w2.id, self.connection)

        self.compare_watches(w1, w1loaded)
        self.compare_watches(w2, w2loaded)
Exemple #8
0
    def status(self):
        watch = Watch.load(self.id, get_db_connection(self.config))
        if not watch:
            raise cherrypy.NotFound()

        data = watch.dict()
        data.update(self.worker_set.worker_status_dict(watch.id))

        cherrypy.response.headers['Content-Type'] = "application/json"
        return simplejson.dumps(data)
Exemple #9
0
    def delete(self):
        connection = get_db_connection(self.config)

        try:
            watch = Watch.load(self.id, connection)
            if not watch:
                raise cherrypy.NotFound()

            if cherrypy.request.method == 'POST':
                watch.delete(connection)
                self.worker_set.remove(self.id)
                connection.commit()
                raise cherrypy.HTTPRedirect(cherrypy.url('/'), status=303)

            return self.render('delete.html', watch=watch)
        except Exception:
            connection.rollback()
            raise