Ejemplo n.º 1
0
 def test_delete_prop(self):
     db.session.add(models.User('User 1', '*****@*****.**'))
     db.session.add(models.Property('prop 1', 'val 1', 1))
     db.session.commit()
     rv = self.app.delete('/contacts/1/properties/1')
     self.assertEqual(rv.status_code, 200)
     user = models.User.query.filter_by(name='User 1').first()
     self.assertEqual([], user.properties)
Ejemplo n.º 2
0
 def test_edit_prop(self):
     user = models.User('User 1', '*****@*****.**')
     db.session.add(user)
     db.session.add(models.Property('prop 1', 'val 1', 1))
     db.session.commit()
     rv = self.app.put('/contacts/1/properties/1', data='{"key":"prop 2", "value":"val 2"}')
     self.assertEqual(rv.status_code, 200)
     user = models.User.query.filter_by(name='User 1').first()
     prop = user.properties[0]
     self.assertEqual('prop 2', prop.key)
     self.assertEqual('val 2', prop.value)
def add_property(user_id):
    user = models.Contact.query.filter_by(id=user_id).first_or_404()
    if user not in current_user.contacts:
        return make_response('', 403)

    data = json.JSONDecoder().decode(request.data)
    if 'key' not in data or 'value' not in data:
        return make_response('', 400)

    prop = models.Property(data['key'], data['value'], user_id)
    db.session.add(prop)
    db.session.commit()
    return make_response(json.dumps(prop.dict()), 201)
Ejemplo n.º 4
0
 def test_show_prop(self):
     db.session.add(models.User('User 1', '*****@*****.**'))
     db.session.add(models.Property('prop 1', 'val 1', 1))
     db.session.commit()
     rv = self.app.get('/contacts/1/properties/1')
     self.assertEqual(rv.status_code, 200)
from bootstrap import db
from um import models

# Contact 1
u1 = models.Contact('Contact 1', '*****@*****.**')
db.session.add(u1)
db.session.commit()

# Contact 1 properties
p = models.Property('first_name', 'Peter', u1.id)
p1 = models.Property('last_name', 'Wanowan', u1.id)
p2 = models.Property('email', '*****@*****.**', u1.id)
p3 = models.Property('fon', '+1 555 101', u1.id)

db.session.add(p)
db.session.add(p1)
db.session.add(p2)
db.session.add(p3)
db.session.commit()

# Contact 2
u2 = models.Contact('Contact 2', '*****@*****.**')
db.session.add(u2)
db.session.commit()

# Contact 2 properties
p = models.Property('first_name', 'John', u2.id)
p1 = models.Property('last_name', 'Twootwo', u2.id)
p2 = models.Property('email', '*****@*****.**', u2.id)
p3 = models.Property('fon', '+1 555 202', u2.id)