/usr/lib/python3/dist-packages/social/tests/test_storage.py is in python3-social-auth 1:0.2.21+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | import six
import random
import unittest2 as unittest
from social.strategies.base import BaseStrategy
from social.storage.base import UserMixin, NonceMixin, AssociationMixin, \
CodeMixin, BaseStorage
from social.tests.models import User
NOT_IMPLEMENTED_MSG = 'Implement in subclass'
class BrokenUser(UserMixin):
pass
class BrokenAssociation(AssociationMixin):
pass
class BrokenNonce(NonceMixin):
pass
class BrokenCode(CodeMixin):
pass
class BrokenStrategy(BaseStrategy):
pass
class BrokenStrategyWithSettings(BrokenStrategy):
def get_setting(self, name):
raise AttributeError()
class BrokenStorage(BaseStorage):
pass
class BrokenUserTests(unittest.TestCase):
def setUp(self):
self.user = BrokenUser
def tearDown(self):
self.user = None
def test_get_username(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_username(User('foobar'))
def test_user_model(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.user_model()
def test_username_max_length(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.username_max_length()
def test_get_user(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_user(1)
def test_get_social_auth(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_social_auth('foo', 1)
def test_get_social_auth_for_user(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.get_social_auth_for_user(User('foobar'))
def test_create_social_auth(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.create_social_auth(User('foobar'), 1, 'foo')
def test_disconnect(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.user.disconnect(BrokenUser())
class BrokenAssociationTests(unittest.TestCase):
def setUp(self):
self.association = BrokenAssociation
def tearDown(self):
self.association = None
def test_store(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.store('http://foobar.com', BrokenAssociation())
def test_get(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.get()
def test_remove(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.association.remove([1, 2, 3])
class BrokenNonceTests(unittest.TestCase):
def setUp(self):
self.nonce = BrokenNonce
def tearDown(self):
self.nonce = None
def test_use(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.nonce.use('http://foobar.com', 1364951922, 'foobar123')
class BrokenCodeTest(unittest.TestCase):
def setUp(self):
self.code = BrokenCode
def tearDown(self):
self.code = None
def test_get_code(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.code.get_code('foobar')
class BrokenStrategyTests(unittest.TestCase):
def setUp(self):
self.strategy = BrokenStrategy(storage=BrokenStorage)
def tearDown(self):
self.strategy = None
def test_redirect(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.redirect('http://foobar.com')
def test_get_setting(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.get_setting('foobar')
def test_html(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.html('<p>foobar</p>')
def test_request_data(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.request_data()
def test_request_host(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.request_host()
def test_session_get(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_get('foobar')
def test_session_set(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_set('foobar', 123)
def test_session_pop(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.session_pop('foobar')
def test_build_absolute_uri(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.build_absolute_uri('/foobar')
def test_render_html_with_tpl(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.render_html('foobar.html', context={})
def test_render_html_with_html(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.render_html(html='<p>foobar</p>', context={})
def test_render_html_with_none(self):
with self.assertRaisesRegexp(ValueError,
'Missing template or html parameters'):
self.strategy.render_html()
def test_is_integrity_error(self):
with self.assertRaisesRegexp(NotImplementedError, NOT_IMPLEMENTED_MSG):
self.strategy.storage.is_integrity_error(None)
def test_random_string(self):
self.assertTrue(isinstance(self.strategy.random_string(),
six.string_types))
def test_random_string_without_systemrandom(self):
def SystemRandom():
raise NotImplementedError()
orig_random = getattr(random, 'SystemRandom', None)
random.SystemRandom = SystemRandom
strategy = BrokenStrategyWithSettings(storage=BrokenStorage)
self.assertTrue(isinstance(strategy.random_string(), six.string_types))
random.SystemRandom = orig_random
|