def test_get_list(self): user_1 = models.User(name="aaa", surname="bbb") self.db_session.add(user_1) user_2 = models.User(name="aaa", surname="bbb") self.db_session.add(user_2) self.db_session.commit() response = self.app.get('/api/users/') result = self._to_json(response.data) self.assertTrue(len(result) == 2)
def test_delete(self): user = models.User(name="aaa", surname="bbb") self.db_session.add(user) self.db_session.commit() put_id = user.id response = self.app.delete('/api/users/' + str(put_id), ) self.assertEqual(response.status_code, 204)
def test_get(self): expected_result = {"name": "aaa", "surname": "bbb"} user = models.User(name="aaa", surname="bbb") self.db_session.add(user) self.db_session.commit() put_id = user.id response = self.app.get('/api/users/' + str(put_id), ) result = self._to_json(response.data) result.pop('id') self.assertDictEqual(result, expected_result)
def test_put(self): user = models.User(name="aaa", surname="bbb") self.db_session.add(user) self.db_session.commit() put_id = user.id body = {"name": "2", "surname": "3"} response = self.app.put('/api/users/' + str(put_id), data=json.dumps(body), content_type='application/json') result = self._to_json(response.data) result.pop('id') self.assertDictEqual(result, body)
def test_put_400(self): user = models.User(name="aaa", surname="bbb") self.db_session.add(user) self.db_session.commit() put_id = user.id body = { "name": "2", } response = self.app.put('/api/users/' + str(put_id), data=json.dumps(body), content_type='application/json') self.assertEqual(response.status_code, 400)