def test_save_person_add_person_in_db(self): data = {'facebook_id': '123', 'username': '******', 'name': 'name_test', 'gender': 'male'} self.assertEqual(0, Person.query.count()) Person.save_person(**data) self.assertEqual(1, Person.query.count())
def delete(self, facebook_id): try: Person.delete_person(facebook_id=facebook_id) logger.info('DELETE /person/{} - Successul deleted'.format(facebook_id)) except UserNotFound: logger.error('DELETE /person/{} - Invalid facebook_id'.format(facebook_id)) return {'error': 'Invalid facebook_id.'}, 404 return {}, 204
def test_save_person_twice_should_raises_exception(self): data = {'facebook_id': '123', 'username': '******', 'name': 'name_test', 'gender': 'male'} Person.save_person(**data) self.assertEqual(1, Person.query.count()) with self.assertRaises(UserFound): Person.save_person(**data) self.assertEqual(1, Person.query.count())
def post(self, facebook_id): try: user_data = Facebook.get_user_data(facebook_id=facebook_id) except UserNotFound: logger.error('POST /person/ facebook_id={} - Invalid facebook_id'.format(facebook_id)) return {'error': 'Invalid facebook_id.'}, 404 try: Person.save_person(**user_data) logger.info('POST /person/ facebook_id={} - Successul inserted'.format(facebook_id)) except UserFound: logger.error('POST /person/ facebook_id={} - Already inserted'.format(facebook_id)) return {'error': 'User already inserted.'}, 400 return {'message': 'ok'}, 201
def test_person_list_should_return_all_persons(self): self.create_persons(3) persons_list = Person.persons_list() response = self.client.get('/person/') data = json.loads(response.data) self.assertEqual(persons_list, data['persons'])
def test_person_list_return_all_persons(self): persons = self.create_persons() expected_list = [] for person in persons: expected_list.append({ 'username': person.username, 'facebook_id': person.facebook_id, 'name': person.name, 'gender': person.gender }) persons_list = Person.persons_list() self.assertEqual(expected_list, persons_list)
def get(self): limit = request.args.get('limit', 0) persons_list = Person.persons_list(limit) return {'persons': persons_list, 'limit': limit}
def test_delete_person_should_remove_person_from_db(self): persons = self.create_persons(1) self.assertEqual(1, Person.query.count()) Person.delete_person(persons[0].facebook_id) self.assertEqual(0, Person.query.count())
def test_person_list_with_limit_return_only_2_persons(self): self.create_persons(3) persons_list = Person.persons_list(limit=2) self.assertEqual(2, len(persons_list))