Пример #1
0
class NotesApiTest(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('*****@*****.**', 'testuser')
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
        self.cell.put()
        for x in Note.all():
            x.delete()
        self.when = datetime.now()
        self.note = Note(msg='test msg', added_by=users.get_current_user(), cell=self.cell, added_on=self.when)
        self.note.put()

    def test_note_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note')
        self.assertEquals(200, rv.status_code)
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))
        n = js[0]
        self.assertEquals('test msg', n['msg'])
        self.assertEquals('test', n['author'])
        self.assertEquals(timestamp(self.when), n['date'])
        self.assertEquals(1, Note.all().count())

    def test_notes_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note', data='{"msg": "test"}')
        self.assertEquals(200, rv.status_code)
        self.assertEquals(2, Note.all().count())
        self.assertEquals(2, self.cell.note_set.count())
 def create(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_or_create(r, x, y, z)
     data = json.loads(request.data)
     if 'msg' not in data:
         abort(400)
     a = Note(msg=data['msg'], added_by=users.get_current_user(), cell=cell)
     a.save()
     return Response(a.as_json(), mimetype='application/json')
 def create(self, report_id, cell_pos):
     r = Report.get(Key(report_id))
     z, x, y = Cell.cell_id(cell_pos)
     cell = Cell.get_or_create(r, x, y, z)
     data = json.loads(request.data)
     if "msg" not in data:
         abort(400)
     a = Note(msg=data["msg"], added_by=users.get_current_user(), cell=cell)
     a.save()
     return Response(a.as_json(), mimetype="application/json")
Пример #4
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.login('*****@*****.**', 'testuser')
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0, y=0, z=2, report=self.r, ndfi_high=1.0, ndfi_low=0.0)
     self.cell.put()
     for x in Note.all():
         x.delete()
     self.when = datetime.now()
     self.note = Note(msg='test msg', added_by=users.get_current_user(), cell=self.cell, added_on=self.when)
     self.note.put()
Пример #5
0
 def test_notes_create(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                        '/cell/2_0_0/note',
                        data='{"msg": "test"}')
     self.assertEquals(200, rv.status_code)
     self.assertEquals(2, Note.all().count())
     self.assertEquals(2, self.cell.note_set.count())
Пример #6
0
 def test_note_list(self):
     rv = self.app.get('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note')
     self.assertEquals(200, rv.status_code)
     js = json.loads(rv.data)
     self.assertEquals(1, len(js))
     n = js[0]
     self.assertEquals('test msg', n['msg'])
     self.assertEquals('test', n['author'])
     self.assertEquals(timestamp(self.when), n['date'])
     self.assertEquals(1, Note.all().count())
Пример #7
0
class NotesApiTest(unittest.TestCase, GoogleAuthMixin):
    def setUp(self):
        app.config['TESTING'] = True
        self.app = app.test_client()
        self.login('*****@*****.**', 'testuser')
        r = Report(start=date.today(), finished=False)
        r.put()
        self.r = r
        self.cell = Cell(x=0,
                         y=0,
                         z=2,
                         report=self.r,
                         ndfi_high=1.0,
                         ndfi_low=0.0)
        self.cell.put()
        for x in Note.all():
            x.delete()
        self.when = datetime.now()
        self.note = Note(msg='test msg',
                         added_by=users.get_current_user(),
                         cell=self.cell,
                         added_on=self.when)
        self.note.put()

    def test_note_list(self):
        rv = self.app.get('/api/v0/report/' + str(self.r.key()) +
                          '/cell/2_0_0/note')
        self.assertEquals(200, rv.status_code)
        js = json.loads(rv.data)
        self.assertEquals(1, len(js))
        n = js[0]
        self.assertEquals('test msg', n['msg'])
        self.assertEquals('test', n['author'])
        self.assertEquals(timestamp(self.when), n['date'])
        self.assertEquals(1, Note.all().count())

    def test_notes_create(self):
        rv = self.app.post('/api/v0/report/' + str(self.r.key()) +
                           '/cell/2_0_0/note',
                           data='{"msg": "test"}')
        self.assertEquals(200, rv.status_code)
        self.assertEquals(2, Note.all().count())
        self.assertEquals(2, self.cell.note_set.count())
Пример #8
0
 def test_note_list(self):
     rv = self.app.get('/api/v0/report/' + str(self.r.key()) +
                       '/cell/2_0_0/note')
     self.assertEquals(200, rv.status_code)
     js = json.loads(rv.data)
     self.assertEquals(1, len(js))
     n = js[0]
     self.assertEquals('test msg', n['msg'])
     self.assertEquals('test', n['author'])
     self.assertEquals(timestamp(self.when), n['date'])
     self.assertEquals(1, Note.all().count())
Пример #9
0
 def setUp(self):
     app.config['TESTING'] = True
     self.app = app.test_client()
     self.login('*****@*****.**', 'testuser')
     r = Report(start=date.today(), finished=False)
     r.put()
     self.r = r
     self.cell = Cell(x=0,
                      y=0,
                      z=2,
                      report=self.r,
                      ndfi_high=1.0,
                      ndfi_low=0.0)
     self.cell.put()
     for x in Note.all():
         x.delete()
     self.when = datetime.now()
     self.note = Note(msg='test msg',
                      added_by=users.get_current_user(),
                      cell=self.cell,
                      added_on=self.when)
     self.note.put()
Пример #10
0
 def test_notes_create(self):
     rv = self.app.post('/api/v0/report/' + str(self.r.key()) + '/cell/2_0_0/note', data='{"msg": "test"}')
     self.assertEquals(200, rv.status_code)
     self.assertEquals(2, Note.all().count())
     self.assertEquals(2, self.cell.note_set.count())
Пример #11
0
from application import db
from application.models import Note
from application.models import User
# create the database and the database table
db.create_all()
# insert Note data
Note1 = Note(
    'Slow-Cooked Tacos',
    'Delicious chicken that has been simmering in taco seasoning and sauce.  Perfect with hard-shelled tortillas!'
)
Note2 = Note('Hamburgers', 'Classic dish elevated with pretzele buns.')
Note3 = Note('Grilled Chicken',
             'Grilled chicken served with pitas, hummus, and sauted veggies.')
db.session.add(Note1)
db.session.add(Note2)
db.session.add(Note3)
db.session.commit()

User1 = User('admin', 'admin')
db.session.add(User1)
db.session.commit()