Skip to content

Commit 54612c4

Browse files
committed
resolving merge conflict by incorporating suggestions
2 parents 5ad11c0 + 9cef7ba commit 54612c4

File tree

19 files changed

+469
-247
lines changed

19 files changed

+469
-247
lines changed

docker/solr/conf/managed-schema

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
<!-- Combine the "title" and "abstract" fields so that we search both when performing basic search -->
125125
<copyField source="title" dest="basic_search" />
126126
<copyField source="abstract" dest="basic_search" />
127-
<field name="basic_search" type="text_general" />
127+
<field name="basic_search" type="text_general" indexed="true" stored="false" />
128128

129129
<!--
130130
END COMPENDIUM FIELDS

docker/solr/conf/solrconfig.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@
849849
<!-- a spellchecker built from a field of the main index -->
850850
<lst name="spellchecker">
851851
<str name="name">default</str>
852-
<str name="field">_text_</str>
852+
<str name="field">title</str>
853853
<str name="classname">solr.DirectSolrSpellChecker</str>
854854
<!-- the spellcheck distance measure used, the default is the internal levenshtein -->
855855
<str name="distanceMeasure">internal</str>

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
bibtexparser == 1.1.0
2+
csscompressor == 0.9.5
23
django-compressor == 2.4
34
django[argon2] == 3.0.3
45
gunicorn == 20.0.4
56
psycopg2-binary == 2.8.4
67
pylibmc == 1.6.1
7-
pysolr == 3.8.1
88
python-dotenv == 0.11.0
9+
requests == 2.23.0

src/assets/css/style.css

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ br.sep {
3737
}
3838

3939
.site-title {
40-
font-weight: bold;
41-
font-size: 4.5em;
42-
font-family: "Nobile", Roboto, arial, monospace;
40+
font-family: "Nobile", Roboto, Arial, sans-serif !important;
4341
}
4442

4543
.tag-selector-button {
@@ -52,6 +50,14 @@ br.sep {
5250
margin-bottom: auto;
5351
}
5452

53+
54+
/****************************
55+
* Background colors
56+
****************************/
57+
.bg-white {
58+
background-color: white;
59+
}
60+
5561
/****************************
5662
* Navbar
5763
****************************/
@@ -113,7 +119,7 @@ a.anchor:hover {
113119

114120
.searchbar {
115121
background-color: white;
116-
border: 4px black;
122+
border: 1px solid black;
117123
}
118124

119125
/****************************

src/encryption_compendium/settings.py

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,20 @@
224224
"compressor.finders.CompressorFinder",
225225
)
226226

227-
# Email options
227+
### Compression settings for django-compressor
228+
# COMPRESS_ENABLED: whether or not to compress files. Defaults to the
229+
# opposite of DEBUG.
230+
# COMPRESS_ENABLED = not DEBUG
231+
232+
# Filters to apply during compression
233+
COMPRESS_FILTERS = {
234+
"css": [
235+
"compressor.filters.css_default.CssAbsoluteFilter",
236+
"compressor.filters.cssmin.CSSCompressorFilter",
237+
],
238+
}
239+
240+
### Email options
228241
EMAIL_USER = os.getenv("EMAIL_USER")
229242
EMAIL_PASSWORD = os.getenv("EMAIL_PASSWORD")
230243
EMAIL_PORT = int(os.getenv("EMAIL_PORT", 587))
@@ -235,3 +248,47 @@
235248
EMAIL_USE_TLS = False
236249
else:
237250
raise Exception("EMAIL_USE_TLS should be 'yes' or 'no'.")
251+
252+
### Logging configuration
253+
LOGGING = {
254+
"version": 1,
255+
"disable_existing_loggers": False,
256+
"formatters": {
257+
"default": {
258+
"format": "[{asctime}] [{process:d}] [{levelname}] {message}",
259+
"style": "{",
260+
},
261+
"verbose": {
262+
"format": "[{asctime}] {module} {process:d} {thread:d} [{levelname}] {message}",
263+
"style": "{",
264+
},
265+
},
266+
"handlers": {
267+
"console": {"class": "logging.StreamHandler", "formatter": "default",},
268+
"console_debug": {"class": "logging.StreamHandler", "formatter": "verbose",},
269+
},
270+
"root": {"handlers": ["console"], "level": "INFO" if DEBUG else "WARNING"},
271+
"loggers": {
272+
# Search loggers
273+
"search": {
274+
"handlers": ["console"],
275+
"level": os.getenv("DJANGO_SEARCH_LOGLEVEL", "INFO"),
276+
},
277+
"search.solr": {
278+
"handlers": ["console"],
279+
"level": os.getenv("DJANGO_SEARCH_LOGLEVEL", "DEBUG" if DEBUG else "INFO"),
280+
"propagate": False,
281+
},
282+
# Authentication loggers
283+
"auth": {
284+
"handlers": ["console"],
285+
"level": os.getenv("DJANGO_AUTH_LOGLEVEL", "DEBUG" if DEBUG else "INFO"),
286+
},
287+
"auth.login": {"handlers": ["console"], "level": "INFO",},
288+
# Compendium loggers
289+
"compendium": {
290+
"handlers": ["console"],
291+
"level": os.getenv("DJANGO_COMPENDIUM_LOGLEVEL", "INFO"),
292+
},
293+
},
294+
}
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
"""
2+
Tests for views that are used to modify the compendium.
3+
"""
4+
5+
import datetime
6+
import os
7+
import random
8+
9+
from django.urls import reverse
10+
from django.test import tag
11+
from entries.models import CompendiumEntry, CompendiumEntryTag, Author
12+
from utils.test_utils import UnitTest, random_username
13+
14+
15+
@tag("compendium-modification")
16+
class AddNewCompendiumEntryTestCase(UnitTest):
17+
"""
18+
Test the view that presents a form for manually creating a new compendium
19+
entry.
20+
"""
21+
22+
def setUp(self):
23+
super().setUp(preauth=True)
24+
self.new_entry_page = reverse("research new article")
25+
26+
# Add three tags for testing purposes
27+
for tagname in ("test_tag_A", "test_tag_B", "test_tag_C"):
28+
if not CompendiumEntryTag.objects.filter(tagname=tagname).exists():
29+
CompendiumEntryTag.objects.create(tagname=tagname)
30+
31+
def test_page_templates(self):
32+
# Ensure that the page uses the correct templates in its response
33+
response = self.client.get(self.new_entry_page)
34+
self.assertTemplateUsed("dashboard_base.html")
35+
self.assertTemplateUsed("new_article.html")
36+
37+
@tag("tags")
38+
def test_add_new_compendium_entry(self):
39+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
40+
41+
# Retrieve the tag ID for "test_tag_B"
42+
tag_id = CompendiumEntryTag.objects.get(tagname="test_tag_B").id
43+
44+
# publisher information
45+
publisher = random_username(self.rd)
46+
47+
# published date
48+
year = random.randrange(1900, datetime.date.today().year)
49+
month = random.randrange(1, 12)
50+
day = random.randrange(1, 31)
51+
52+
# Send POST data to the URL to create a new entry and ensure that
53+
# the entry was created correctly.
54+
data = {
55+
"title": "New compendium entry",
56+
"abstract": "Abstract for new entry",
57+
"url": "https://example.com",
58+
"tags": [tag_id],
59+
"publisher_text": publisher,
60+
"year": year,
61+
"month": month,
62+
"day": day,
63+
"edit-entry": "",
64+
}
65+
response = self.client.post(self.new_entry_page, data)
66+
self.assertTrue(len(CompendiumEntry.objects.all()), 1)
67+
68+
entry = CompendiumEntry.objects.get(title="New compendium entry")
69+
self.assertEqual(entry.owner, self.user)
70+
self.assertEqual(entry.title, "New compendium entry")
71+
self.assertEqual(entry.abstract, "Abstract for new entry")
72+
self.assertEqual(entry.url, "https://example.com")
73+
self.assertEqual(len(entry.tags.all()), 1)
74+
self.assertEqual(entry.tags.get().tagname, "test_tag_B")
75+
self.assertEqual(entry.publisher.publishername, publisher)
76+
self.assertEqual(entry.year, year)
77+
self.assertEqual(entry.month, month)
78+
self.assertEqual(entry.day, day)
79+
80+
@tag("tags")
81+
def test_add_compendium_entry_with_multiple_tags(self):
82+
"""Create a CompendiumEntry with multiple tags"""
83+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
84+
85+
# Retrieve tag IDs for "test_tag_B" and "test_tag_C"
86+
id_A = CompendiumEntryTag.objects.get(tagname="test_tag_A").id
87+
id_C = CompendiumEntryTag.objects.get(tagname="test_tag_C").id
88+
89+
# Send POST data with multiple tag IDs
90+
data = {
91+
"title": "New compendium entry",
92+
"tags": [id_A, id_C],
93+
"edit-entry": "",
94+
}
95+
self.client.post(self.new_entry_page, data)
96+
self.assertEqual(len(CompendiumEntry.objects.all()), 1)
97+
98+
entry = CompendiumEntry.objects.get(title="New compendium entry")
99+
self.assertEqual(len(entry.tags.all()), 2)
100+
self.assertTrue(entry.tags.filter(tagname="test_tag_A").exists())
101+
self.assertFalse(entry.tags.filter(tagname="test_tag_B").exists())
102+
self.assertTrue(entry.tags.filter(tagname="test_tag_C").exists())
103+
104+
def test_attempt_to_create_entry_with_empty_title(self):
105+
"""New entries must have a title"""
106+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
107+
tag_id = CompendiumEntryTag.objects.get(tagname="test_tag_A").id
108+
109+
### Try to create an entry without a title
110+
data = {
111+
"tags": [tag_id],
112+
}
113+
response = self.client.post(self.new_entry_page, data)
114+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
115+
116+
### Try to create an entry with an empty title
117+
data = {
118+
"title": "",
119+
"tags": [tag_id],
120+
}
121+
response = self.client.post(self.new_entry_page, data)
122+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
123+
124+
def test_attempt_to_create_entry_without_tags(self):
125+
"""New entries must have _at least_ one tag"""
126+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
127+
128+
data = {
129+
"title": "New compendium entry",
130+
}
131+
self.client.post(self.new_entry_page, data)
132+
self.assertEqual(len(CompendiumEntry.objects.all()), 0)
133+
134+
135+
### TODO
136+
137+
138+
@tag("compendium-modification")
139+
class UploadBibTexViewTestCase(UnitTest):
140+
"""
141+
Test the view that's involved in handling BibTeX uploads to the site for
142+
adding new compendium entries.
143+
"""
144+
145+
def setUp(self):
146+
super().setUp(preauth=True)
147+
148+
# Load in a test .bib file
149+
# self.test_filename = os.

0 commit comments

Comments
 (0)