PageRenderTime 54ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 1ms

/tests/regressiontests/admin_views/tests.py

https://code.google.com/p/mango-py/
Python | 2965 lines | 2815 code | 74 blank | 76 comment | 22 complexity | 5e7b4ee6ace0b61c905cd2fad1686963 MD5 | raw file
Possible License(s): BSD-3-Clause

Large files files are truncated, but you can click here to view the full file

  1. # coding: utf-8
  2. import re
  3. import datetime
  4. import urlparse
  5. from django.conf import settings
  6. from django.core import mail
  7. from django.core.exceptions import SuspiciousOperation
  8. from django.core.files import temp as tempfile
  9. from django.core.urlresolvers import reverse
  10. # Register auth models with the admin.
  11. from django.contrib.auth import REDIRECT_FIELD_NAME, admin
  12. from django.contrib.auth.models import User, Permission, UNUSABLE_PASSWORD
  13. from django.contrib.contenttypes.models import ContentType
  14. from django.contrib.admin.models import LogEntry, DELETION
  15. from django.contrib.admin.sites import LOGIN_FORM_KEY
  16. from django.contrib.admin.util import quote
  17. from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
  18. from django.contrib.admin.views.main import IS_POPUP_VAR
  19. from django.forms.util import ErrorList
  20. import django.template.context
  21. from django.test import TestCase
  22. from django.utils import formats
  23. from django.utils.cache import get_max_age
  24. from django.utils.encoding import iri_to_uri
  25. from django.utils.html import escape
  26. from django.utils.http import urlencode
  27. from django.utils.translation import activate, deactivate
  28. from django.utils import unittest
  29. # local test models
  30. from models import (Article, BarAccount, CustomArticle, EmptyModel,
  31. FooAccount, Gallery, ModelWithStringPrimaryKey,
  32. Person, Persona, Picture, Podcast, Section, Subscriber, Vodcast,
  33. Language, Collector, Widget, Grommet, DooHickey, FancyDoodad, Whatsit,
  34. Category, Post, Plot, FunkyTag, Chapter, Book, Promo, WorkHour, Employee,
  35. Question, Answer, Inquisition, Actor, FoodDelivery,
  36. RowLevelChangePermissionModel, Paper, CoverLetter, Story, OtherStory)
  37. class AdminViewBasicTest(TestCase):
  38. fixtures = ['admin-views-users.xml', 'admin-views-colors.xml',
  39. 'admin-views-fabrics.xml', 'admin-views-books.xml']
  40. # Store the bit of the URL where the admin is registered as a class
  41. # variable. That way we can test a second AdminSite just by subclassing
  42. # this test case and changing urlbit.
  43. urlbit = 'admin'
  44. def setUp(self):
  45. self.old_USE_I18N = settings.USE_I18N
  46. self.old_USE_L10N = settings.USE_L10N
  47. self.old_LANGUAGE_CODE = settings.LANGUAGE_CODE
  48. self.client.login(username='super', password='secret')
  49. settings.USE_I18N = True
  50. def tearDown(self):
  51. settings.USE_I18N = self.old_USE_I18N
  52. settings.USE_L10N = self.old_USE_L10N
  53. settings.LANGUAGE_CODE = self.old_LANGUAGE_CODE
  54. self.client.logout()
  55. formats.reset_format_cache()
  56. def testTrailingSlashRequired(self):
  57. """
  58. If you leave off the trailing slash, app should redirect and add it.
  59. """
  60. request = self.client.get('/test_admin/%s/admin_views/article/add' % self.urlbit)
  61. self.assertRedirects(request,
  62. '/test_admin/%s/admin_views/article/add/' % self.urlbit, status_code=301
  63. )
  64. def testBasicAddGet(self):
  65. """
  66. A smoke test to ensure GET on the add_view works.
  67. """
  68. response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit)
  69. self.assertEqual(response.status_code, 200)
  70. def testAddWithGETArgs(self):
  71. response = self.client.get('/test_admin/%s/admin_views/section/add/' % self.urlbit, {'name': 'My Section'})
  72. self.assertEqual(response.status_code, 200)
  73. self.assertTrue(
  74. 'value="My Section"' in response.content,
  75. "Couldn't find an input with the right value in the response."
  76. )
  77. def testBasicEditGet(self):
  78. """
  79. A smoke test to ensure GET on the change_view works.
  80. """
  81. response = self.client.get('/test_admin/%s/admin_views/section/1/' % self.urlbit)
  82. self.assertEqual(response.status_code, 200)
  83. def testBasicEditGetStringPK(self):
  84. """
  85. A smoke test to ensure GET on the change_view works (returns an HTTP
  86. 404 error, see #11191) when passing a string as the PK argument for a
  87. model with an integer PK field.
  88. """
  89. response = self.client.get('/test_admin/%s/admin_views/section/abc/' % self.urlbit)
  90. self.assertEqual(response.status_code, 404)
  91. def testBasicAddPost(self):
  92. """
  93. A smoke test to ensure POST on add_view works.
  94. """
  95. post_data = {
  96. "name": u"Another Section",
  97. # inline data
  98. "article_set-TOTAL_FORMS": u"3",
  99. "article_set-INITIAL_FORMS": u"0",
  100. "article_set-MAX_NUM_FORMS": u"0",
  101. }
  102. response = self.client.post('/test_admin/%s/admin_views/section/add/' % self.urlbit, post_data)
  103. self.assertEqual(response.status_code, 302) # redirect somewhere
  104. def testPopupAddPost(self):
  105. """
  106. Ensure http response from a popup is properly escaped.
  107. """
  108. post_data = {
  109. '_popup': u'1',
  110. 'title': u'title with a new\nline',
  111. 'content': u'some content',
  112. 'date_0': u'2010-09-10',
  113. 'date_1': u'14:55:39',
  114. }
  115. response = self.client.post('/test_admin/%s/admin_views/article/add/' % self.urlbit, post_data)
  116. self.failUnlessEqual(response.status_code, 200)
  117. self.assertContains(response, 'dismissAddAnotherPopup')
  118. self.assertContains(response, 'title with a new\u000Aline')
  119. # Post data for edit inline
  120. inline_post_data = {
  121. "name": u"Test section",
  122. # inline data
  123. "article_set-TOTAL_FORMS": u"6",
  124. "article_set-INITIAL_FORMS": u"3",
  125. "article_set-MAX_NUM_FORMS": u"0",
  126. "article_set-0-id": u"1",
  127. # there is no title in database, give one here or formset will fail.
  128. "article_set-0-title": u"Norske bostaver ćřĺ skaper problemer",
  129. "article_set-0-content": u"<p>Middle content</p>",
  130. "article_set-0-date_0": u"2008-03-18",
  131. "article_set-0-date_1": u"11:54:58",
  132. "article_set-0-section": u"1",
  133. "article_set-1-id": u"2",
  134. "article_set-1-title": u"Need a title.",
  135. "article_set-1-content": u"<p>Oldest content</p>",
  136. "article_set-1-date_0": u"2000-03-18",
  137. "article_set-1-date_1": u"11:54:58",
  138. "article_set-2-id": u"3",
  139. "article_set-2-title": u"Need a title.",
  140. "article_set-2-content": u"<p>Newest content</p>",
  141. "article_set-2-date_0": u"2009-03-18",
  142. "article_set-2-date_1": u"11:54:58",
  143. "article_set-3-id": u"",
  144. "article_set-3-title": u"",
  145. "article_set-3-content": u"",
  146. "article_set-3-date_0": u"",
  147. "article_set-3-date_1": u"",
  148. "article_set-4-id": u"",
  149. "article_set-4-title": u"",
  150. "article_set-4-content": u"",
  151. "article_set-4-date_0": u"",
  152. "article_set-4-date_1": u"",
  153. "article_set-5-id": u"",
  154. "article_set-5-title": u"",
  155. "article_set-5-content": u"",
  156. "article_set-5-date_0": u"",
  157. "article_set-5-date_1": u"",
  158. }
  159. def testBasicEditPost(self):
  160. """
  161. A smoke test to ensure POST on edit_view works.
  162. """
  163. response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, self.inline_post_data)
  164. self.assertEqual(response.status_code, 302) # redirect somewhere
  165. def testEditSaveAs(self):
  166. """
  167. Test "save as".
  168. """
  169. post_data = self.inline_post_data.copy()
  170. post_data.update({
  171. '_saveasnew': u'Save+as+new',
  172. "article_set-1-section": u"1",
  173. "article_set-2-section": u"1",
  174. "article_set-3-section": u"1",
  175. "article_set-4-section": u"1",
  176. "article_set-5-section": u"1",
  177. })
  178. response = self.client.post('/test_admin/%s/admin_views/section/1/' % self.urlbit, post_data)
  179. self.assertEqual(response.status_code, 302) # redirect somewhere
  180. def testChangeListSortingCallable(self):
  181. """
  182. Ensure we can sort on a list_display field that is a callable
  183. (column 2 is callable_year in ArticleAdmin)
  184. """
  185. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'asc', 'o': 2})
  186. self.assertEqual(response.status_code, 200)
  187. self.assertTrue(
  188. response.content.index('Oldest content') < response.content.index('Middle content') and
  189. response.content.index('Middle content') < response.content.index('Newest content'),
  190. "Results of sorting on callable are out of order."
  191. )
  192. def testChangeListSortingModel(self):
  193. """
  194. Ensure we can sort on a list_display field that is a Model method
  195. (colunn 3 is 'model_year' in ArticleAdmin)
  196. """
  197. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'dsc', 'o': 3})
  198. self.assertEqual(response.status_code, 200)
  199. self.assertTrue(
  200. response.content.index('Newest content') < response.content.index('Middle content') and
  201. response.content.index('Middle content') < response.content.index('Oldest content'),
  202. "Results of sorting on Model method are out of order."
  203. )
  204. def testChangeListSortingModelAdmin(self):
  205. """
  206. Ensure we can sort on a list_display field that is a ModelAdmin method
  207. (colunn 4 is 'modeladmin_year' in ArticleAdmin)
  208. """
  209. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'ot': 'asc', 'o': 4})
  210. self.assertEqual(response.status_code, 200)
  211. self.assertTrue(
  212. response.content.index('Oldest content') < response.content.index('Middle content') and
  213. response.content.index('Middle content') < response.content.index('Newest content'),
  214. "Results of sorting on ModelAdmin method are out of order."
  215. )
  216. def testLimitedFilter(self):
  217. """Ensure admin changelist filters do not contain objects excluded via limit_choices_to.
  218. This also tests relation-spanning filters (e.g. 'color__value').
  219. """
  220. response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit)
  221. self.assertEqual(response.status_code, 200)
  222. self.assertTrue(
  223. '<div id="changelist-filter">' in response.content,
  224. "Expected filter not found in changelist view."
  225. )
  226. self.assertFalse(
  227. '<a href="?color__id__exact=3">Blue</a>' in response.content,
  228. "Changelist filter not correctly limited by limit_choices_to."
  229. )
  230. def testRelationSpanningFilters(self):
  231. response = self.client.get('/test_admin/%s/admin_views/chapterxtra1/' %
  232. self.urlbit)
  233. self.assertEqual(response.status_code, 200)
  234. self.assertContains(response, '<div id="changelist-filter">')
  235. filters = {
  236. 'chap__id__exact': dict(
  237. values=[c.id for c in Chapter.objects.all()],
  238. test=lambda obj, value: obj.chap.id == value),
  239. 'chap__title': dict(
  240. values=[c.title for c in Chapter.objects.all()],
  241. test=lambda obj, value: obj.chap.title == value),
  242. 'chap__book__id__exact': dict(
  243. values=[b.id for b in Book.objects.all()],
  244. test=lambda obj, value: obj.chap.book.id == value),
  245. 'chap__book__name': dict(
  246. values=[b.name for b in Book.objects.all()],
  247. test=lambda obj, value: obj.chap.book.name == value),
  248. 'chap__book__promo__id__exact': dict(
  249. values=[p.id for p in Promo.objects.all()],
  250. test=lambda obj, value:
  251. obj.chap.book.promo_set.filter(id=value).exists()),
  252. 'chap__book__promo__name': dict(
  253. values=[p.name for p in Promo.objects.all()],
  254. test=lambda obj, value:
  255. obj.chap.book.promo_set.filter(name=value).exists()),
  256. }
  257. for filter_path, params in filters.items():
  258. for value in params['values']:
  259. query_string = urlencode({filter_path: value})
  260. # ensure filter link exists
  261. self.assertContains(response, '<a href="?%s">' % query_string)
  262. # ensure link works
  263. filtered_response = self.client.get(
  264. '/test_admin/%s/admin_views/chapterxtra1/?%s' % (
  265. self.urlbit, query_string))
  266. self.assertEqual(filtered_response.status_code, 200)
  267. # ensure changelist contains only valid objects
  268. for obj in filtered_response.context['cl'].query_set.all():
  269. self.assertTrue(params['test'](obj, value))
  270. def testIncorrectLookupParameters(self):
  271. """Ensure incorrect lookup parameters are handled gracefully."""
  272. response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'notarealfield': '5'})
  273. self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
  274. response = self.client.get('/test_admin/%s/admin_views/thing/' % self.urlbit, {'color__id__exact': 'StringNotInteger!'})
  275. self.assertRedirects(response, '/test_admin/%s/admin_views/thing/?e=1' % self.urlbit)
  276. def testIsNullLookups(self):
  277. """Ensure is_null is handled correctly."""
  278. Article.objects.create(title="I Could Go Anywhere", content="Versatile", date=datetime.datetime.now())
  279. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
  280. self.assertTrue('4 articles' in response.content, '"4 articles" missing from response')
  281. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'section__isnull': 'false'})
  282. self.assertTrue('3 articles' in response.content, '"3 articles" missing from response')
  283. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit, {'section__isnull': 'true'})
  284. self.assertTrue('1 article' in response.content, '"1 article" missing from response')
  285. def testLogoutAndPasswordChangeURLs(self):
  286. response = self.client.get('/test_admin/%s/admin_views/article/' % self.urlbit)
  287. self.assertFalse('<a href="/test_admin/%s/logout/">' % self.urlbit not in response.content)
  288. self.assertFalse('<a href="/test_admin/%s/password_change/">' % self.urlbit not in response.content)
  289. def testNamedGroupFieldChoicesChangeList(self):
  290. """
  291. Ensures the admin changelist shows correct values in the relevant column
  292. for rows corresponding to instances of a model in which a named group
  293. has been used in the choices option of a field.
  294. """
  295. response = self.client.get('/test_admin/%s/admin_views/fabric/' % self.urlbit)
  296. self.assertEqual(response.status_code, 200)
  297. self.assertTrue(
  298. '<a href="1/">Horizontal</a>' in response.content and
  299. '<a href="2/">Vertical</a>' in response.content,
  300. "Changelist table isn't showing the right human-readable values set by a model field 'choices' option named group."
  301. )
  302. def testNamedGroupFieldChoicesFilter(self):
  303. """
  304. Ensures the filter UI shows correctly when at least one named group has
  305. been used in the choices option of a model field.
  306. """
  307. response = self.client.get('/test_admin/%s/admin_views/fabric/' % self.urlbit)
  308. self.assertEqual(response.status_code, 200)
  309. self.assertTrue(
  310. '<div id="changelist-filter">' in response.content,
  311. "Expected filter not found in changelist view."
  312. )
  313. self.assertTrue(
  314. '<a href="?surface__exact=x">Horizontal</a>' in response.content and
  315. '<a href="?surface__exact=y">Vertical</a>' in response.content,
  316. "Changelist filter isn't showing options contained inside a model field 'choices' option named group."
  317. )
  318. def testChangeListNullBooleanDisplay(self):
  319. Post.objects.create(public=None)
  320. # This hard-codes the URl because it'll fail if it runs
  321. # against the 'admin2' custom admin (which doesn't have the
  322. # Post model).
  323. response = self.client.get("/test_admin/admin/admin_views/post/")
  324. self.assertTrue('icon-unknown.gif' in response.content)
  325. def testI18NLanguageNonEnglishDefault(self):
  326. """
  327. Check if the Javascript i18n view returns an empty language catalog
  328. if the default language is non-English but the selected language
  329. is English. See #13388 and #3594 for more details.
  330. """
  331. try:
  332. settings.LANGUAGE_CODE = 'fr'
  333. activate('en-us')
  334. response = self.client.get('/test_admin/admin/jsi18n/')
  335. self.assertNotContains(response, 'Choisir une heure')
  336. finally:
  337. deactivate()
  338. def testI18NLanguageNonEnglishFallback(self):
  339. """
  340. Makes sure that the fallback language is still working properly
  341. in cases where the selected language cannot be found.
  342. """
  343. try:
  344. settings.LANGUAGE_CODE = 'fr'
  345. activate('none')
  346. response = self.client.get('/test_admin/admin/jsi18n/')
  347. self.assertContains(response, 'Choisir une heure')
  348. finally:
  349. deactivate()
  350. def testL10NDeactivated(self):
  351. """
  352. Check if L10N is deactivated, the Javascript i18n view doesn't
  353. return localized date/time formats. Refs #14824.
  354. """
  355. try:
  356. settings.LANGUAGE_CODE = 'ru'
  357. settings.USE_L10N = False
  358. activate('ru')
  359. response = self.client.get('/test_admin/admin/jsi18n/')
  360. self.assertNotContains(response, '%d.%m.%Y %H:%M:%S')
  361. self.assertContains(response, '%Y-%m-%d %H:%M:%S')
  362. finally:
  363. deactivate()
  364. def test_disallowed_filtering(self):
  365. self.assertRaises(SuspiciousOperation,
  366. self.client.get, "/test_admin/admin/admin_views/album/?owner__email__startswith=fuzzy"
  367. )
  368. try:
  369. self.client.get("/test_admin/admin/admin_views/thing/?color__value__startswith=red")
  370. self.client.get("/test_admin/admin/admin_views/thing/?color__value=red")
  371. except SuspiciousOperation:
  372. self.fail("Filters are allowed if explicitly included in list_filter")
  373. try:
  374. self.client.get("/test_admin/admin/admin_views/person/?age__gt=30")
  375. except SuspiciousOperation:
  376. self.fail("Filters should be allowed if they involve a local field without the need to whitelist them in list_filter or date_hierarchy.")
  377. e1 = Employee.objects.create(name='Anonymous', gender=1, age=22, alive=True, code='123')
  378. e2 = Employee.objects.create(name='Visitor', gender=2, age=19, alive=True, code='124')
  379. WorkHour.objects.create(datum=datetime.datetime.now(), employee=e1)
  380. WorkHour.objects.create(datum=datetime.datetime.now(), employee=e2)
  381. response = self.client.get("/test_admin/admin/admin_views/workhour/")
  382. self.assertEqual(response.status_code, 200)
  383. self.assertContains(response, 'employee__person_ptr__exact')
  384. response = self.client.get("/test_admin/admin/admin_views/workhour/?employee__person_ptr__exact=%d" % e1.pk)
  385. self.assertEqual(response.status_code, 200)
  386. def test_allowed_filtering_15103(self):
  387. """
  388. Regressions test for ticket 15103 - filtering on fields defined in a
  389. ForeignKey 'limit_choices_to' should be allowed, otherwise raw_id_fields
  390. can break.
  391. """
  392. try:
  393. self.client.get("/test_admin/admin/admin_views/inquisition/?leader__name=Palin&leader__age=27")
  394. except SuspiciousOperation:
  395. self.fail("Filters should be allowed if they are defined on a ForeignKey pointing to this model")
  396. class AdminJavaScriptTest(AdminViewBasicTest):
  397. def testSingleWidgetFirsFieldFocus(self):
  398. """
  399. JavaScript-assisted auto-focus on first field.
  400. """
  401. response = self.client.get('/test_admin/%s/admin_views/picture/add/' % self.urlbit)
  402. self.assertContains(
  403. response,
  404. '<script type="text/javascript">document.getElementById("id_name").focus();</script>'
  405. )
  406. def testMultiWidgetFirsFieldFocus(self):
  407. """
  408. JavaScript-assisted auto-focus should work if a model/ModelAdmin setup
  409. is such that the first form field has a MultiWidget.
  410. """
  411. response = self.client.get('/test_admin/%s/admin_views/reservation/add/' % self.urlbit)
  412. self.assertContains(
  413. response,
  414. '<script type="text/javascript">document.getElementById("id_start_date_0").focus();</script>'
  415. )
  416. class SaveAsTests(TestCase):
  417. fixtures = ['admin-views-users.xml','admin-views-person.xml']
  418. def setUp(self):
  419. self.client.login(username='super', password='secret')
  420. def tearDown(self):
  421. self.client.logout()
  422. def test_save_as_duplication(self):
  423. """Ensure save as actually creates a new person"""
  424. post_data = {'_saveasnew':'', 'name':'John M', 'gender':1, 'age': 42}
  425. response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
  426. self.assertEqual(len(Person.objects.filter(name='John M')), 1)
  427. self.assertEqual(len(Person.objects.filter(id=1)), 1)
  428. def test_save_as_display(self):
  429. """
  430. Ensure that 'save as' is displayed when activated and after submitting
  431. invalid data aside save_as_new will not show us a form to overwrite the
  432. initial model.
  433. """
  434. response = self.client.get('/test_admin/admin/admin_views/person/1/')
  435. self.assertTrue(response.context['save_as'])
  436. post_data = {'_saveasnew':'', 'name':'John M', 'gender':3, 'alive':'checked'}
  437. response = self.client.post('/test_admin/admin/admin_views/person/1/', post_data)
  438. self.assertEqual(response.context['form_url'], '../add/')
  439. class CustomModelAdminTest(AdminViewBasicTest):
  440. urlbit = "admin2"
  441. def testCustomAdminSiteLoginForm(self):
  442. self.client.logout()
  443. request = self.client.get('/test_admin/admin2/')
  444. self.assertEqual(request.status_code, 200)
  445. login = self.client.post('/test_admin/admin2/', {
  446. REDIRECT_FIELD_NAME: '/test_admin/admin2/',
  447. LOGIN_FORM_KEY: 1,
  448. 'username': 'customform',
  449. 'password': 'secret',
  450. })
  451. self.assertEqual(login.status_code, 200)
  452. self.assertContains(login, 'custom form error')
  453. def testCustomAdminSiteLoginTemplate(self):
  454. self.client.logout()
  455. request = self.client.get('/test_admin/admin2/')
  456. self.assertTemplateUsed(request, 'custom_admin/login.html')
  457. self.assertTrue('Hello from a custom login template' in request.content)
  458. def testCustomAdminSiteLogoutTemplate(self):
  459. request = self.client.get('/test_admin/admin2/logout/')
  460. self.assertTemplateUsed(request, 'custom_admin/logout.html')
  461. self.assertTrue('Hello from a custom logout template' in request.content)
  462. def testCustomAdminSiteIndexViewAndTemplate(self):
  463. request = self.client.get('/test_admin/admin2/')
  464. self.assertTemplateUsed(request, 'custom_admin/index.html')
  465. self.assertTrue('Hello from a custom index template *bar*' in request.content)
  466. def testCustomAdminSitePasswordChangeTemplate(self):
  467. request = self.client.get('/test_admin/admin2/password_change/')
  468. self.assertTemplateUsed(request, 'custom_admin/password_change_form.html')
  469. self.assertTrue('Hello from a custom password change form template' in request.content)
  470. def testCustomAdminSitePasswordChangeDoneTemplate(self):
  471. request = self.client.get('/test_admin/admin2/password_change/done/')
  472. self.assertTemplateUsed(request, 'custom_admin/password_change_done.html')
  473. self.assertTrue('Hello from a custom password change done template' in request.content)
  474. def testCustomAdminSiteView(self):
  475. self.client.login(username='super', password='secret')
  476. response = self.client.get('/test_admin/%s/my_view/' % self.urlbit)
  477. self.assertTrue(response.content == "Django is a magical pony!", response.content)
  478. def get_perm(Model, perm):
  479. """Return the permission object, for the Model"""
  480. ct = ContentType.objects.get_for_model(Model)
  481. return Permission.objects.get(content_type=ct, codename=perm)
  482. class AdminViewPermissionsTest(TestCase):
  483. """Tests for Admin Views Permissions."""
  484. fixtures = ['admin-views-users.xml']
  485. def setUp(self):
  486. """Test setup."""
  487. # Setup permissions, for our users who can add, change, and delete.
  488. # We can't put this into the fixture, because the content type id
  489. # and the permission id could be different on each run of the test.
  490. opts = Article._meta
  491. # User who can add Articles
  492. add_user = User.objects.get(username='adduser')
  493. add_user.user_permissions.add(get_perm(Article,
  494. opts.get_add_permission()))
  495. # User who can change Articles
  496. change_user = User.objects.get(username='changeuser')
  497. change_user.user_permissions.add(get_perm(Article,
  498. opts.get_change_permission()))
  499. # User who can delete Articles
  500. delete_user = User.objects.get(username='deleteuser')
  501. delete_user.user_permissions.add(get_perm(Article,
  502. opts.get_delete_permission()))
  503. delete_user.user_permissions.add(get_perm(Section,
  504. Section._meta.get_delete_permission()))
  505. # login POST dicts
  506. self.super_login = {
  507. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  508. LOGIN_FORM_KEY: 1,
  509. 'username': 'super',
  510. 'password': 'secret',
  511. }
  512. self.super_email_login = {
  513. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  514. LOGIN_FORM_KEY: 1,
  515. 'username': 'super@example.com',
  516. 'password': 'secret',
  517. }
  518. self.super_email_bad_login = {
  519. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  520. LOGIN_FORM_KEY: 1,
  521. 'username': 'super@example.com',
  522. 'password': 'notsecret',
  523. }
  524. self.adduser_login = {
  525. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  526. LOGIN_FORM_KEY: 1,
  527. 'username': 'adduser',
  528. 'password': 'secret',
  529. }
  530. self.changeuser_login = {
  531. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  532. LOGIN_FORM_KEY: 1,
  533. 'username': 'changeuser',
  534. 'password': 'secret',
  535. }
  536. self.deleteuser_login = {
  537. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  538. LOGIN_FORM_KEY: 1,
  539. 'username': 'deleteuser',
  540. 'password': 'secret',
  541. }
  542. self.joepublic_login = {
  543. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  544. LOGIN_FORM_KEY: 1,
  545. 'username': 'joepublic',
  546. 'password': 'secret',
  547. }
  548. self.no_username_login = {
  549. REDIRECT_FIELD_NAME: '/test_admin/admin/',
  550. LOGIN_FORM_KEY: 1,
  551. 'password': 'secret',
  552. }
  553. def testLogin(self):
  554. """
  555. Make sure only staff members can log in.
  556. Successful posts to the login page will redirect to the orignal url.
  557. Unsuccessfull attempts will continue to render the login page with
  558. a 200 status code.
  559. """
  560. # Super User
  561. request = self.client.get('/test_admin/admin/')
  562. self.assertEqual(request.status_code, 200)
  563. login = self.client.post('/test_admin/admin/', self.super_login)
  564. self.assertRedirects(login, '/test_admin/admin/')
  565. self.assertFalse(login.context)
  566. self.client.get('/test_admin/admin/logout/')
  567. # Test if user enters e-mail address
  568. request = self.client.get('/test_admin/admin/')
  569. self.assertEqual(request.status_code, 200)
  570. login = self.client.post('/test_admin/admin/', self.super_email_login)
  571. self.assertContains(login, "Your e-mail address is not your username")
  572. # only correct passwords get a username hint
  573. login = self.client.post('/test_admin/admin/', self.super_email_bad_login)
  574. self.assertContains(login, "Please enter a correct username and password.")
  575. new_user = User(username='jondoe', password='secret', email='super@example.com')
  576. new_user.save()
  577. # check to ensure if there are multiple e-mail addresses a user doesn't get a 500
  578. login = self.client.post('/test_admin/admin/', self.super_email_login)
  579. self.assertContains(login, "Please enter a correct username and password.")
  580. # Add User
  581. request = self.client.get('/test_admin/admin/')
  582. self.assertEqual(request.status_code, 200)
  583. login = self.client.post('/test_admin/admin/', self.adduser_login)
  584. self.assertRedirects(login, '/test_admin/admin/')
  585. self.assertFalse(login.context)
  586. self.client.get('/test_admin/admin/logout/')
  587. # Change User
  588. request = self.client.get('/test_admin/admin/')
  589. self.assertEqual(request.status_code, 200)
  590. login = self.client.post('/test_admin/admin/', self.changeuser_login)
  591. self.assertRedirects(login, '/test_admin/admin/')
  592. self.assertFalse(login.context)
  593. self.client.get('/test_admin/admin/logout/')
  594. # Delete User
  595. request = self.client.get('/test_admin/admin/')
  596. self.assertEqual(request.status_code, 200)
  597. login = self.client.post('/test_admin/admin/', self.deleteuser_login)
  598. self.assertRedirects(login, '/test_admin/admin/')
  599. self.assertFalse(login.context)
  600. self.client.get('/test_admin/admin/logout/')
  601. # Regular User should not be able to login.
  602. request = self.client.get('/test_admin/admin/')
  603. self.assertEqual(request.status_code, 200)
  604. login = self.client.post('/test_admin/admin/', self.joepublic_login)
  605. self.assertEqual(login.status_code, 200)
  606. self.assertContains(login, "Please enter a correct username and password.")
  607. # Requests without username should not return 500 errors.
  608. request = self.client.get('/test_admin/admin/')
  609. self.assertEqual(request.status_code, 200)
  610. login = self.client.post('/test_admin/admin/', self.no_username_login)
  611. self.assertEqual(login.status_code, 200)
  612. form = login.context[0].get('form')
  613. self.assertEqual(form.errors['username'][0], 'This field is required.')
  614. def testLoginSuccessfullyRedirectsToOriginalUrl(self):
  615. request = self.client.get('/test_admin/admin/')
  616. self.assertEqual(request.status_code, 200)
  617. query_string = 'the-answer=42'
  618. redirect_url = '/test_admin/admin/?%s' % query_string
  619. new_next = {REDIRECT_FIELD_NAME: redirect_url}
  620. login = self.client.post('/test_admin/admin/', dict(self.super_login, **new_next), QUERY_STRING=query_string)
  621. self.assertRedirects(login, redirect_url)
  622. def testAddView(self):
  623. """Test add view restricts access and actually adds items."""
  624. add_dict = {'title' : 'Dřm ikke',
  625. 'content': '<p>great article</p>',
  626. 'date_0': '2008-03-18', 'date_1': '10:54:39',
  627. 'section': 1}
  628. # Change User should not have access to add articles
  629. self.client.get('/test_admin/admin/')
  630. self.client.post('/test_admin/admin/', self.changeuser_login)
  631. # make sure the view removes test cookie
  632. self.assertEqual(self.client.session.test_cookie_worked(), False)
  633. request = self.client.get('/test_admin/admin/admin_views/article/add/')
  634. self.assertEqual(request.status_code, 403)
  635. # Try POST just to make sure
  636. post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
  637. self.assertEqual(post.status_code, 403)
  638. self.assertEqual(Article.objects.all().count(), 3)
  639. self.client.get('/test_admin/admin/logout/')
  640. # Add user may login and POST to add view, then redirect to admin root
  641. self.client.get('/test_admin/admin/')
  642. self.client.post('/test_admin/admin/', self.adduser_login)
  643. addpage = self.client.get('/test_admin/admin/admin_views/article/add/')
  644. self.assertEqual(addpage.status_code, 200)
  645. change_list_link = '<a href="../">Articles</a> &rsaquo;'
  646. self.assertFalse(change_list_link in addpage.content,
  647. 'User restricted to add permission is given link to change list view in breadcrumbs.')
  648. post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
  649. self.assertRedirects(post, '/test_admin/admin/')
  650. self.assertEqual(Article.objects.all().count(), 4)
  651. self.assertEqual(len(mail.outbox), 1)
  652. self.assertEqual(mail.outbox[0].subject, 'Greetings from a created object')
  653. self.client.get('/test_admin/admin/logout/')
  654. # Super can add too, but is redirected to the change list view
  655. self.client.get('/test_admin/admin/')
  656. self.client.post('/test_admin/admin/', self.super_login)
  657. addpage = self.client.get('/test_admin/admin/admin_views/article/add/')
  658. self.assertEqual(addpage.status_code, 200)
  659. self.assertFalse(change_list_link not in addpage.content,
  660. 'Unrestricted user is not given link to change list view in breadcrumbs.')
  661. post = self.client.post('/test_admin/admin/admin_views/article/add/', add_dict)
  662. self.assertRedirects(post, '/test_admin/admin/admin_views/article/')
  663. self.assertEqual(Article.objects.all().count(), 5)
  664. self.client.get('/test_admin/admin/logout/')
  665. # 8509 - if a normal user is already logged in, it is possible
  666. # to change user into the superuser without error
  667. login = self.client.login(username='joepublic', password='secret')
  668. # Check and make sure that if user expires, data still persists
  669. self.client.get('/test_admin/admin/')
  670. self.client.post('/test_admin/admin/', self.super_login)
  671. # make sure the view removes test cookie
  672. self.assertEqual(self.client.session.test_cookie_worked(), False)
  673. def testChangeView(self):
  674. """Change view should restrict access and allow users to edit items."""
  675. change_dict = {'title' : 'Ikke fordřmt',
  676. 'content': '<p>edited article</p>',
  677. 'date_0': '2008-03-18', 'date_1': '10:54:39',
  678. 'section': 1}
  679. # add user shoud not be able to view the list of article or change any of them
  680. self.client.get('/test_admin/admin/')
  681. self.client.post('/test_admin/admin/', self.adduser_login)
  682. request = self.client.get('/test_admin/admin/admin_views/article/')
  683. self.assertEqual(request.status_code, 403)
  684. request = self.client.get('/test_admin/admin/admin_views/article/1/')
  685. self.assertEqual(request.status_code, 403)
  686. post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict)
  687. self.assertEqual(post.status_code, 403)
  688. self.client.get('/test_admin/admin/logout/')
  689. # change user can view all items and edit them
  690. self.client.get('/test_admin/admin/')
  691. self.client.post('/test_admin/admin/', self.changeuser_login)
  692. request = self.client.get('/test_admin/admin/admin_views/article/')
  693. self.assertEqual(request.status_code, 200)
  694. request = self.client.get('/test_admin/admin/admin_views/article/1/')
  695. self.assertEqual(request.status_code, 200)
  696. post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict)
  697. self.assertRedirects(post, '/test_admin/admin/admin_views/article/')
  698. self.assertEqual(Article.objects.get(pk=1).content, '<p>edited article</p>')
  699. # one error in form should produce singular error message, multiple errors plural
  700. change_dict['title'] = ''
  701. post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict)
  702. self.assertEqual(request.status_code, 200)
  703. self.assertTrue('Please correct the error below.' in post.content,
  704. 'Singular error message not found in response to post with one error.')
  705. change_dict['content'] = ''
  706. post = self.client.post('/test_admin/admin/admin_views/article/1/', change_dict)
  707. self.assertEqual(request.status_code, 200)
  708. self.assertTrue('Please correct the errors below.' in post.content,
  709. 'Plural error message not found in response to post with multiple errors.')
  710. self.client.get('/test_admin/admin/logout/')
  711. # Test redirection when using row-level change permissions. Refs #11513.
  712. RowLevelChangePermissionModel.objects.create(id=1, name="odd id")
  713. RowLevelChangePermissionModel.objects.create(id=2, name="even id")
  714. for login_dict in [self.super_login, self.changeuser_login, self.adduser_login, self.deleteuser_login]:
  715. self.client.post('/test_admin/admin/', login_dict)
  716. request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/')
  717. self.assertEqual(request.status_code, 403)
  718. request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {'name': 'changed'})
  719. self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
  720. self.assertEqual(request.status_code, 403)
  721. request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/')
  722. self.assertEqual(request.status_code, 200)
  723. request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {'name': 'changed'})
  724. self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
  725. self.assertRedirects(request, '/test_admin/admin/')
  726. self.client.get('/test_admin/admin/logout/')
  727. for login_dict in [self.joepublic_login, self.no_username_login]:
  728. self.client.post('/test_admin/admin/', login_dict)
  729. request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/')
  730. self.assertEqual(request.status_code, 200)
  731. self.assertContains(request, 'login-form')
  732. request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/1/', {'name': 'changed'})
  733. self.assertEqual(RowLevelChangePermissionModel.objects.get(id=1).name, 'odd id')
  734. self.assertEqual(request.status_code, 200)
  735. self.assertContains(request, 'login-form')
  736. request = self.client.get('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/')
  737. self.assertEqual(request.status_code, 200)
  738. self.assertContains(request, 'login-form')
  739. request = self.client.post('/test_admin/admin/admin_views/rowlevelchangepermissionmodel/2/', {'name': 'changed again'})
  740. self.assertEqual(RowLevelChangePermissionModel.objects.get(id=2).name, 'changed')
  741. self.assertEqual(request.status_code, 200)
  742. self.assertContains(request, 'login-form')
  743. self.client.get('/test_admin/admin/logout/')
  744. def testConditionallyShowAddSectionLink(self):
  745. """
  746. The foreign key widget should only show the "add related" button if the
  747. user has permission to add that related item.
  748. """
  749. # Set up and log in user.
  750. url = '/test_admin/admin/admin_views/article/add/'
  751. add_link_text = ' class="add-another"'
  752. self.client.get('/test_admin/admin/')
  753. self.client.post('/test_admin/admin/', self.adduser_login)
  754. # The add user can't add sections yet, so they shouldn't see the "add
  755. # section" link.
  756. response = self.client.get(url)
  757. self.assertNotContains(response, add_link_text)
  758. # Allow the add user to add sections too. Now they can see the "add
  759. # section" link.
  760. add_user = User.objects.get(username='adduser')
  761. perm = get_perm(Section, Section._meta.get_add_permission())
  762. add_user.user_permissions.add(perm)
  763. response = self.client.get(url)
  764. self.assertContains(response, add_link_text)
  765. def testCustomModelAdminTemplates(self):
  766. self.client.get('/test_admin/admin/')
  767. self.client.post('/test_admin/admin/', self.super_login)
  768. # Test custom change list template with custom extra context
  769. request = self.client.get('/test_admin/admin/admin_views/customarticle/')
  770. self.assertEqual(request.status_code, 200)
  771. self.assertTrue("var hello = 'Hello!';" in request.content)
  772. self.assertTemplateUsed(request, 'custom_admin/change_list.html')
  773. # Test custom add form template
  774. request = self.client.get('/test_admin/admin/admin_views/customarticle/add/')
  775. self.assertTemplateUsed(request, 'custom_admin/add_form.html')
  776. # Add an article so we can test delete, change, and history views
  777. post = self.client.post('/test_admin/admin/admin_views/customarticle/add/', {
  778. 'content': '<p>great article</p>',
  779. 'date_0': '2008-03-18',
  780. 'date_1': '10:54:39'
  781. })
  782. self.assertRedirects(post, '/test_admin/admin/admin_views/customarticle/')
  783. self.assertEqual(CustomArticle.objects.all().count(), 1)
  784. article_pk = CustomArticle.objects.all()[0].pk
  785. # Test custom delete, change, and object history templates
  786. # Test custom change form template
  787. request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/' % article_pk)
  788. self.assertTemplateUsed(request, 'custom_admin/change_form.html')
  789. request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/delete/' % article_pk)
  790. self.assertTemplateUsed(request, 'custom_admin/delete_confirmation.html')
  791. request = self.client.post('/test_admin/admin/admin_views/customarticle/', data={
  792. 'index': 0,
  793. 'action': ['delete_selected'],
  794. '_selected_action': ['1'],
  795. })
  796. self.assertTemplateUsed(request, 'custom_admin/delete_selected_confirmation.html')
  797. request = self.client.get('/test_admin/admin/admin_views/customarticle/%d/history/' % article_pk)
  798. self.assertTemplateUsed(request, 'custom_admin/object_history.html')
  799. self.client.get('/test_admin/admin/logout/')
  800. def testDeleteView(self):
  801. """Delete view should restrict access and actually delete items."""
  802. delete_dict = {'post': 'yes'}
  803. # add user shoud not be able to delete articles
  804. self.client.get('/test_admin/admin/')
  805. self.client.post('/test_admin/admin/', self.adduser_login)
  806. request = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
  807. self.assertEqual(request.status_code, 403)
  808. post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict)
  809. self.assertEqual(post.status_code, 403)
  810. self.assertEqual(Article.objects.all().count(), 3)
  811. self.client.get('/test_admin/admin/logout/')
  812. # Delete user can delete
  813. self.client.get('/test_admin/admin/')
  814. self.client.post('/test_admin/admin/', self.deleteuser_login)
  815. response = self.client.get('/test_admin/admin/admin_views/section/1/delete/')
  816. # test response contains link to related Article
  817. self.assertContains(response, "admin_views/article/1/")
  818. response = self.client.get('/test_admin/admin/admin_views/article/1/delete/')
  819. self.assertEqual(response.status_code, 200)
  820. post = self.client.post('/test_admin/admin/admin_views/article/1/delete/', delete_dict)
  821. self.assertRedirects(post, '/test_admin/admin/')
  822. self.assertEqual(Article.objects.all().count(), 2)
  823. self.assertEqual(len(mail.outbox), 1)
  824. self.assertEqual(mail.outbox[0].subject, 'Greetings from a deleted object')
  825. article_ct = ContentType.objects.get_for_model(Article)
  826. logged = LogEntry.objects.get(content_type=article_ct, action_flag=DELETION)
  827. self.assertEqual(logged.object_id, u'1')
  828. self.client.get('/test_admin/admin/logout/')
  829. def testDisabledPermissionsWhenLoggedIn(self):
  830. self.client.login(username='super', password='secret')
  831. superuser = User.objects.get(username='super')
  832. superuser.is_active = False
  833. superuser.save()
  834. response = self.client.get('/test_admin/admin/')
  835. self.assertContains(response, 'id="login-form"')
  836. self.assertNotContains(response, 'Log out')
  837. response = self.client.get('/test_admin/admin/secure-view/')
  838. self.assertContains(response, 'id="login-form"')
  839. class AdminViewDeletedObjectsTest(TestCase):
  840. fixtures = ['admin-views-users.xml', 'deleted-objects.xml']
  841. def setUp(self):
  842. self.client.login(username='super', password='secret')
  843. def tearDown(self):
  844. self.client.logout()
  845. def test_nesting(self):
  846. """
  847. Objects should be nested to display the relationships that
  848. cause them to be scheduled for deletion.
  849. """
  850. pattern = re.compile(r"""<li>Plot: <a href=".+/admin_views/plot/1/">World Domination</a>\s*<ul>\s*<li>Plot details: <a href=".+/admin_views/plotdetails/1/">almost finished</a>""")
  851. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(1))
  852. self.assertTrue(pattern.search(response.content))
  853. def test_cyclic(self):
  854. """
  855. Cyclic relationships should still cause each object to only be
  856. listed once.
  857. """
  858. one = """<li>Cyclic one: <a href="/test_admin/admin/admin_views/cyclicone/1/">I am recursive</a>"""
  859. two = """<li>Cyclic two: <a href="/test_admin/admin/admin_views/cyclictwo/1/">I am recursive too</a>"""
  860. response = self.client.get('/test_admin/admin/admin_views/cyclicone/%s/delete/' % quote(1))
  861. self.assertContains(response, one, 1)
  862. self.assertContains(response, two, 1)
  863. def test_perms_needed(self):
  864. self.client.logout()
  865. delete_user = User.objects.get(username='deleteuser')
  866. delete_user.user_permissions.add(get_perm(Plot,
  867. Plot._meta.get_delete_permission()))
  868. self.assertTrue(self.client.login(username='deleteuser',
  869. password='secret'))
  870. response = self.client.get('/test_admin/admin/admin_views/plot/%s/delete/' % quote(1))
  871. self.assertContains(response, "your account doesn't have permission to delete the following types of objects")
  872. self.assertContains(response, "<li>plot details</li>")
  873. def test_protected(self):
  874. q = Question.objects.create(question="Why?")
  875. a1 = Answer.objects.create(question=q, answer="Because.")
  876. a2 = Answer.objects.create(question=q, answer="Yes.")
  877. response = self.client.get("/test_admin/admin/admin_views/question/%s/delete/" % quote(q.pk))
  878. self.assertContains(response, "would require deleting the following protected related objects")
  879. self.assertContains(response, '<li>Answer: <a href="/test_admin/admin/admin_views/answer/%s/">Because.</a></li>' % a1.pk)
  880. self.assertContains(response, '<li>Answer: <a href="/test_admin/admin/admin_views/answer/%s/">Yes.</a></li>' % a2.pk)
  881. def test_not_registered(self):
  882. should_contain = """<li>Secret hideout: underground bunker"""
  883. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(1))
  884. self.assertContains(response, should_contain, 1)
  885. def test_multiple_fkeys_to_same_model(self):
  886. """
  887. If a deleted object has two relationships from another model,
  888. both of those should be followed in looking for related
  889. objects to delete.
  890. """
  891. should_contain = """<li>Plot: <a href="/test_admin/admin/admin_views/plot/1/">World Domination</a>"""
  892. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(1))
  893. self.assertContains(response, should_contain)
  894. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(2))
  895. self.assertContains(response, should_contain)
  896. def test_multiple_fkeys_to_same_instance(self):
  897. """
  898. If a deleted object has two relationships pointing to it from
  899. another object, the other object should still only be listed
  900. once.
  901. """
  902. should_contain = """<li>Plot: <a href="/test_admin/admin/admin_views/plot/2/">World Peace</a></li>"""
  903. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(2))
  904. self.assertContains(response, should_contain, 1)
  905. def test_inheritance(self):
  906. """
  907. In the case of an inherited model, if either the child or
  908. parent-model instance is deleted, both instances are listed
  909. for deletion, as well as any relationships they have.
  910. """
  911. should_contain = [
  912. """<li>Villain: <a href="/test_admin/admin/admin_views/villain/3/">Bob</a>""",
  913. """<li>Super villain: <a href="/test_admin/admin/admin_views/supervillain/3/">Bob</a>""",
  914. """<li>Secret hideout: floating castle""",
  915. """<li>Super secret hideout: super floating castle!"""
  916. ]
  917. response = self.client.get('/test_admin/admin/admin_views/villain/%s/delete/' % quote(3))
  918. for should in should_contain:
  919. self.a

Large files files are truncated, but you can click here to view the full file