예제 #1
0
    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
예제 #2
0
 def test_get_method_return_json_data_when_response_is_200(self, request_mock):
     request_mock.get.return_value = mock.Mock(status_code=200,
                                               text=json.dumps({'message': 'ok'}))
     response = Facebook.get('http://localhost/')
     self.assertEqual('ok', response['message'])
예제 #3
0
    def test_invalid_facebook_id_raises_exception(self, facebook_mock):
        facebook_mock.return_value = None

        with self.assertRaises(UserNotFound):
            Facebook.get_user_data('123')
예제 #4
0
 def test_get_method_return_none_when_response_is_404(self, request_mock):
     request_mock.get.return_value = mock.Mock(status_code=404)
     self.assertEqual(None, Facebook.get('http://localhost/'))