def test_add_attr_wrong_input(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.post('/contacts/1/attributes', data='{}') self.assertEqual(rv.status_code, 400) user = models.User.query.filter_by(name='User 1').first() self.assertEqual([], user.attributes)
def test_delete_user(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.delete('/contacts/1') self.assertEqual(rv.status_code, 200) user = models.User.query.filter_by(name='User 1').first() self.assertIsNone(user)
def test_add_prop(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.post('/contacts/1/properties', data='{"key":"prop 1", "value":"val 1"}') self.assertEqual(rv.status_code, 201) user = models.User.query.filter_by(name='User 1').first() prop = user.properties[0] self.assertIsNotNone(prop)
def test_delete_attr(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.add(models.Attribute('attr 1', 1)) db.session.commit() rv = self.app.delete('/contacts/1/attributes/1') self.assertEqual(rv.status_code, 200) user = models.User.query.filter_by(name='User 1').first() self.assertEqual([], user.attributes)
def test_add_attr(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.post('/contacts/1/attributes', data='{"name":"attr 1"}') self.assertEqual(rv.status_code, 201) user = models.User.query.filter_by(name='User 1').first() attr = user.attributes[0] self.assertIsNotNone(attr)
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)
def test_edit_user(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.put('/contacts/1', data='{"name":"modUser 1", "email":"*****@*****.**", "secret_key":"key"}') self.assertEqual(rv.status_code, 200) user = models.User.query.filter_by(name='modUser 1').first() self.assertIsNotNone(user) user = models.User.query.filter_by(email='*****@*****.**').first() self.assertIsNotNone(user)
def test_edit_attr_wrong_input(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.add(models.Attribute('attr 1', 1)) db.session.commit() rv = self.app.put('/contacts/1/attributes/1', data='{}') self.assertEqual(rv.status_code, 400) user = models.User.query.filter_by(name='User 1').first() attr = user.attributes[0] self.assertEqual('attr 1', attr.name)
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 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)
def test_list_props(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.get('/contacts/1/properties') self.assertEqual(rv.status_code, 200) assert '[]' in rv.data
def test_edit_user_wrong_input(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.put('/contacts/1', data='{}') self.assertEqual(rv.status_code, 400)
def test_show_user(self): db.session.add(models.User('User 1', '*****@*****.**')) db.session.commit() rv = self.app.get('/contacts/1') self.assertEqual(rv.status_code, 200)