MCPcopy
hub / github.com/liangliangyy/DjangoBlog / test_image

Method test_image

blog/tests.py:162–183  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

160 self.assertEqual(response.status_code, 200)
161
162 def test_image(self):
163 import requests
164 rsp = requests.get(
165 'https://www.python.org/static/img/python-logo.png')
166 imagepath = os.path.join(settings.BASE_DIR, 'python.png')
167 with open(imagepath, 'wb') as file:
168 file.write(rsp.content)
169 rsp = self.client.post('/upload')
170 self.assertEqual(rsp.status_code, 403)
171 sign = get_sha256(get_sha256(settings.SECRET_KEY))
172 with open(imagepath, 'rb') as file:
173 imgfile = SimpleUploadedFile(
174 'python.png', file.read(), content_type='image/jpg')
175 form_data = {'python.png': imgfile}
176 rsp = self.client.post(
177 '/upload?sign=' + sign, form_data, follow=True)
178 self.assertEqual(rsp.status_code, 200)
179 os.remove(imagepath)
180 from djangoblog.utils import save_user_avatar, send_email
181 send_email(['qq@qq.com'], 'testTitle', 'testContent')
182 save_user_avatar(
183 'https://www.python.org/static/img/python-logo.png')
184
185 def test_errorpage(self):
186 rsp = self.client.get('/eee')

Callers

nothing calls this directly

Calls 6

get_sha256Function · 0.90
send_emailFunction · 0.90
save_user_avatarFunction · 0.90
postMethod · 0.80
getMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected