diff --git a/src/tests/generate_citekey_test.py b/src/tests/generate_citekey_test.py index 94fbab9..76a8a94 100644 --- a/src/tests/generate_citekey_test.py +++ b/src/tests/generate_citekey_test.py @@ -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")