import pytest
import json
from ..giphy import gif_translate, gif_random
import responses

# Load JSON fixtures
@pytest.fixture(scope='module')
def load_json(request):
    load_file = request.param
    with open(load_file, 'rU') as json_file:
       return(json.load(json_file))

# Tests where giphy.gif_random get 200
@pytest.mark.usefixtures('load_json')
@pytest.mark.parametrize("load_json", ['./tests/fixtures/random_200.json'], indirect=True)
class TestRandomSuccess:
    # Sets up request fixture
    @pytest.fixture(autouse=True)
    def setUp(self, load_json):
        self.json = load_json
        # GET 200 setup
        responses.add(responses.GET,
            'http://api.giphy.com/v1/gifs/random?api_key=dc6zaTOxFJmzC&tag=american+psycho',
            json=json.dumps(self.json), status=200, match_querystring=True)

    @responses.activate
    def testExpectedResponse(self):
        resp = gif_random()
        expected = self.json
        # status is as expected
        assert resp.status_code == 200
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()

# Tests where giphy.gif_random get 403
@pytest.mark.usefixtures('load_json')
@pytest.mark.parametrize("load_json", ['./tests/fixtures/random_403.json'], indirect=True)
class TestRandomFail:
    # Sets up request fixture
    @pytest.fixture(autouse=True)
    def setUp(self, load_json):
        self.json = load_json
        # GET 403 setup
        # Might want a more comprehensive regex to capture wrong api key
        responses.add(responses.GET,
            'http://api.giphy.com/v1/gifs/random?api_key=abc&tag=american+psycho',
            json=self.json, status=403, match_querystring=True)

    @responses.activate
    def testExpectedResponse(self):
        resp = gif_random(api_key='abc')
        expected = self.json
        # status code
        assert resp.status_code == 403
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()


# Tests where giphy.gif_translate get 200
@pytest.mark.usefixtures('load_json')
@pytest.mark.parametrize("load_json", ['./tests/fixtures/translate_200.json'], indirect=True)
class TestTranslateSuccess:
    # Sets up request fixture
    @pytest.fixture(autouse=True)
    def setUp(self, load_json):
        self.json = load_json
        # GET 403 setup
        # Might want a more comprehensive regex to capture wrong api key
        responses.add(responses.GET,
            'http://api.giphy.com/v1/gifs/translate?api_key=dc6zaTOxFJmzC&s=leeroy',
            json=self.json, status=200, match_querystring=True)

    @responses.activate
    def testExpectedResponse(self):
        resp = gif_translate()
        expected = self.json
        # status code
        assert resp.status_code == 200
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()


# Tests where giphy.gif_translate get 403
@pytest.mark.usefixtures('load_json')
@pytest.mark.parametrize("load_json", ['./tests/fixtures/translate_403.json'], indirect=True)
class TestTranslateFail:
    # Sets up request fixture
    @pytest.fixture(autouse=True)
    def setUp(self, load_json):
        self.json = load_json
        # GET 403 setup
        # Might want a more comprehensive regex to capture wrong api key
        responses.add(responses.GET,
            'http://api.giphy.com/v1/gifs/translate?api_key=abc&s=leeroy',
            json=self.json, status=403, match_querystring=True)

    @responses.activate
    def testExpectedResponse(self):
        resp = gif_translate(api_key='abc')
        expected = self.json
        # status code
        assert resp.status_code == 403
        # json is the same between fixture and request
        for item in expected:
            assert item in resp.json()

@@ -1,12 +1,25 @@
+import json%0A%0A
 import pytes
@@ -27,20 +27,26 @@
 %0Aimport 
-json
+responses%0A
 %0Afrom ..
@@ -66,46 +66,30 @@
 gif_
-t
 ran
-slate
+dom
 , gif_
-random%0Aimport responses
+translate%0A
 %0A%0A# 
@@ -249,14 +249,16 @@
     
+ 
 return
+ 
 (jso
@@ -277,16 +277,17 @@
 file))%0A%0A
+%0A
 # Tests 
@@ -662,32 +662,42 @@
 ET,%0A            
+          
 'http://api.giph
@@ -753,32 +753,42 @@
 erican+psycho',%0A
+          
             json
@@ -1161,16 +1161,17 @@
 json()%0A%0A
+%0A
 # Tests 
@@ -1616,32 +1616,42 @@
 ET,%0A            
+          
 'http://api.giph
@@ -1697,32 +1697,42 @@
 erican+psycho',%0A
+          
             json
@@ -2563,32 +2563,42 @@
 ET,%0A            
+          
 'http://api.giph
@@ -2646,32 +2646,42 @@
 JmzC&s=leeroy',%0A
+          
             json
@@ -3499,32 +3499,42 @@
 ET,%0A            
+          
 'http://api.giph
@@ -3572,32 +3572,42 @@
 =abc&s=leeroy',%0A
+          
             json

Fix code style issues