Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/story_tests/create_bibtex.robot
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ When Get BibTeX Is Clicked The Generated BibTeX Is Shown
Create Test Citation Author1 Title1 2024 Journal1
Go To Home Page
Click Get Bibtex
Sleep 0.25
Wait Until Element Is Visible copy_bibtex_button
Page Should Contain author = \{Author1\},\n\ttitle = \{Title1\},\n\tyear = \{2024\},\n\tjournal = \{Journal1\}

Expand Down
2 changes: 1 addition & 1 deletion src/story_tests/edit_citation.robot
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ After removing an optional field and closing the edit without updating, the fiel
Click Element //button[@name='exit-edit']
Reload Page
Click Citation Row 1
Sleep 0.25
Sleep 0.5
Page Should Contain volume
Page Should Contain 5050

Expand Down
50 changes: 50 additions & 0 deletions src/tests/generate_citekey_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,53 @@ def unique(key):
key = generate_cite_key(self.fields)
expected = "JouTo20"
self.assertEqual(expected, key)

@patch("util.unique_key")
@patch("secrets.token_hex")
def test_generate_cite_key_with_few_fields(self, mock_token_hex, mock_unique_key):
def unique(key):
return key not in ["Jou10", "Jou88"]

mock_unique_key.side_effect = unique
mock_token_hex.return_value = "abcd"
fields = {"author": "Jo", "year": "2020"}
cite_key = generate_cite_key(fields)
expected = "Jo20abcd"
self.assertEqual(expected, cite_key)

@patch("util.unique_key")
@patch("secrets.token_hex")
def test_generate_cite_key_with_short_fields(self, mock_token_hex, mock_unique_key):
def unique(key):
return key not in ["Jou10", "Jou88"]

mock_unique_key.side_effect = unique
mock_token_hex.return_value = "abcd"
fields = {"author": "J", "edition": "5"}
cite_key = generate_cite_key(fields)
self.assertEqual(cite_key, "J5abcd")

@patch("util.unique_key")
@patch("secrets.token_hex")
def test_generate_cite_key_with_empty_fields(self, mock_token_hex, mock_unique_key):
def unique(key):
return key not in ["Jou10", "Jou88"]

mock_unique_key.side_effect = unique
mock_token_hex.return_value = "abcd"
fields = {}
cite_key = generate_cite_key(fields)
self.assertEqual(cite_key, "abcd")

@patch("util.unique_key")
@patch("secrets.token_hex")
def test_generate_cite_key_not_unique_after_generating(
self, mock_token_hex, mock_unique_key
):
def unique(key):
return key not in ["JouTo20", "Jou88"]

mock_unique_key.side_effect = unique
mock_token_hex.return_value = "abcd"
cite_key = generate_cite_key(self.fields)
self.assertEqual(cite_key, "JouTo20abcd")