From cf30c87c434f691ebc7385072a59617788939f78 Mon Sep 17 00:00:00 2001 From: Matheus Faria Date: Mon, 30 Nov 2015 16:01:03 -0200 Subject: [PATCH] Mocking urllib request on account tests --- colab/accounts/tests/test_utils_validators.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/colab/accounts/tests/test_utils_validators.py b/colab/accounts/tests/test_utils_validators.py index 9204806..756a882 100644 --- a/colab/accounts/tests/test_utils_validators.py +++ b/colab/accounts/tests/test_utils_validators.py @@ -1,3 +1,6 @@ +import urllib2 +from mock import patch, Mock + from django.test import TestCase from ..utils.validators import validate_social_account @@ -5,9 +8,12 @@ from ..utils.validators import validate_social_account class TestValidators(TestCase): - def test_validate_social_account_with_fake_account(self): + @patch('urllib2.urlopen', + side_effect=urllib2.HTTPError(500, "test", 1, 2, None)) + def test_validate_social_account_with_fake_account(self, urlopen_mock): self.assertFalse(validate_social_account('john-fake', 'http://twitter.com')) - def test_validate_social_account(self): + @patch('urllib2.urlopen', return_value=Mock(code=200)) + def test_validate_social_account(self, urlopen_mock): self.assertTrue(validate_social_account('john', 'http://twitter.com')) -- libgit2 0.21.2