"""Tests for the uploader module"""

from __future__ import unicode_literals
from __future__ import print_function
from __future__ import division
from __future__ import absolute_import
from future import standard_library
from requests_mock import Adapter

standard_library.install_aliases()


from json import dumps
from requests_mock import Mocker
from datapackage import DataPackage
import responses

from gobble.user import User
from gobble.uploader import Uploader
from gobble.configuration import config
# noinspection PyUnresolvedReferences
from tests.fixtures import (get_mock_request,
                            ROOT_DIR,
                            PACKAGE_FILE,
                            UPLOADER_PAYLOAD)

REAL_HTTP = not config.MOCK_REQUESTS


def test_sending_payload_info_returns_mock_upload_url2():
    with Mocker(real_http=REAL_HTTP) as mock:
        endpoints = ('authenticate', 'get-permissions', 'request-upload')
        for endpoints in endpoints:
            method, url, status, json = get_mock_request(endpoints)
            getattr(mock, method.lower())(url, text=dumps(json))

        user = User()
        package = DataPackage(PACKAGE_FILE)
        uploader = Uploader(user, package)

        assert uploader.request_upload().status_code == 200


@responses.activate
def test_sending_payload_info_returns_mock_upload_url():
    for request_id in ('authenticate', 'get-permissions', 'request-upload'):
        verb, url, status, json = get_mock_request(request_id)
        responses.add(verb, url, status=status, json=json)

    user = User()
    package = DataPackage(PACKAGE_FILE)
    uploader = Uploader(user, package)

    assert uploader.request_upload().status_code == 200

@@ -218,42 +218,8 @@
 rary
-%0Afrom requests_mock import Adapter
 %0A%0Ast
@@ -469,16 +469,46 @@
  config%0A
+from gobble.logger import log%0A
 # noinsp
@@ -747,17 +747,120 @@
 EQUESTS%0A
-%0A
+log.debug('Mock all tests requests: %25s', config.MOCK_REQUESTS)%0A%0A%0A@Mocker(real_http=REAL_HTTP, kw='mock')
 %0Adef tes
@@ -911,61 +911,20 @@
 rl2(
-):%0A    with Mocker(real_http=REAL_HTTP) as mock:%0A    
+mock=None):%0A
     
@@ -989,20 +989,17 @@
 pload')%0A
-    
+%0A
     for 
@@ -1030,20 +1030,16 @@
         
-  
-  
 method, 
@@ -1086,20 +1086,16 @@
 points)%0A
-    
         
@@ -1148,20 +1148,16 @@
 json))%0A%0A
-    
     user
@@ -1170,20 +1170,16 @@
 r()%0A    
- 
-   
 package 
@@ -1210,20 +1210,16 @@
 LE)%0A    
-   
- 
 uploader
@@ -1246,20 +1246,16 @@
 ckage)%0A%0A
-    
     asse

Replace the mock_requests context-manager with the decorator.