Last active
October 17, 2016 01:39
-
-
Save jorgemdnt/c0031ee7d7d6d51a7e36c9b9695b490a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding=utf-8 | |
import unittest | |
import requests | |
import mock | |
from star_wars.starwars_gateway_swapi import StarWarsGatewaySWAPI | |
class StarWarsGatewaySWAPITests(unittest.TestCase): | |
def setUp(self): | |
self.client = mock.Mock(spec=requests) # 1 | |
self.dados_star_wars_gateway = StarWarsGatewaySWAPI(self.client) | |
def test_obtem_resposta_do_servidor(self): | |
self.client.get.return_value = mock.Mock(status_code=200) # 2 | |
resposta = self.dados_star_wars_gateway.buscar_dados() | |
self.assertEqual(200, resposta.status_code) | |
def test_obtem_personagem(self): | |
retorno_json = { # 3 | |
'count': 1, | |
'results': [ | |
{'name': 'Anakin Skywalker'} | |
] | |
} | |
mock_response = mock.Mock(status_code=200) # 4 | |
mock_response.json.return_value = retorno_json | |
self.client.get.return_value = mock_response | |
resposta = self.dados_star_wars_gateway.buscar_personagem(nome='Anakin') | |
conteudo = resposta.json() | |
self.assertEqual('Anakin Skywalker', conteudo['results'][0]['name']) | |
# 5 | |
self.client.get.assert_called_with('http://swapi.co/api/people/?search=Anakin') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment