Commit cf30c87c434f691ebc7385072a59617788939f78
1 parent
fd82767f
Exists in
master
and in
4 other branches
Mocking urllib request on account tests
Showing
1 changed file
with
8 additions
and
2 deletions
Show diff stats
colab/accounts/tests/test_utils_validators.py
| 1 | +import urllib2 | ||
| 2 | +from mock import patch, Mock | ||
| 3 | + | ||
| 1 | from django.test import TestCase | 4 | from django.test import TestCase |
| 2 | 5 | ||
| 3 | from ..utils.validators import validate_social_account | 6 | from ..utils.validators import validate_social_account |
| @@ -5,9 +8,12 @@ from ..utils.validators import validate_social_account | @@ -5,9 +8,12 @@ from ..utils.validators import validate_social_account | ||
| 5 | 8 | ||
| 6 | class TestValidators(TestCase): | 9 | class TestValidators(TestCase): |
| 7 | 10 | ||
| 8 | - def test_validate_social_account_with_fake_account(self): | 11 | + @patch('urllib2.urlopen', |
| 12 | + side_effect=urllib2.HTTPError(500, "test", 1, 2, None)) | ||
| 13 | + def test_validate_social_account_with_fake_account(self, urlopen_mock): | ||
| 9 | self.assertFalse(validate_social_account('john-fake', | 14 | self.assertFalse(validate_social_account('john-fake', |
| 10 | 'http://twitter.com')) | 15 | 'http://twitter.com')) |
| 11 | 16 | ||
| 12 | - def test_validate_social_account(self): | 17 | + @patch('urllib2.urlopen', return_value=Mock(code=200)) |
| 18 | + def test_validate_social_account(self, urlopen_mock): | ||
| 13 | self.assertTrue(validate_social_account('john', 'http://twitter.com')) | 19 | self.assertTrue(validate_social_account('john', 'http://twitter.com')) |