Skip to content
Closed
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
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")
Loading