Commit cf30c87c434f691ebc7385072a59617788939f78

Authored by Matheus de Sousa Faria
1 parent fd82767f

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 4 from django.test import TestCase
2 5  
3 6 from ..utils.validators import validate_social_account
... ... @@ -5,9 +8,12 @@ from ..utils.validators import validate_social_account
5 8  
6 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 14 self.assertFalse(validate_social_account('john-fake',
10 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 19 self.assertTrue(validate_social_account('john', 'http://twitter.com'))
... ...