• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / ba6f9e1f-4683-40a1-aae1-40dd0fcb64e3

25 Aug 2025 06:57PM UTC coverage: 43.284% (+0.6%) from 42.715%
ba6f9e1f-4683-40a1-aae1-40dd0fcb64e3

push

circleci

mpasternak
Merge branch 'release/v202508.1208'

77 of 961 new or added lines in 27 files covered. (8.01%)

731 existing lines in 54 files now uncovered.

17273 of 39906 relevant lines covered (43.28%)

0.78 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

9.28
src/bpp/tests/test_export/test_export_bibtex.py
1
"""
2
Tests for BibTeX export functionality.
3
"""
4

UNCOV
5
from unittest.mock import Mock
1✔
6

UNCOV
7
import pytest
1✔
UNCOV
8
from model_bakery import baker
1✔
9

UNCOV
10
from bpp.export.bibtex import (
1✔
11
    export_to_bibtex,
12
    generate_bibtex_key,
13
    patent_to_bibtex,
14
    praca_doktorska_to_bibtex,
15
    praca_habilitacyjna_to_bibtex,
16
    sanitize_bibtex_string,
17
    wydawnictwo_ciagle_to_bibtex,
18
    wydawnictwo_zwarte_to_bibtex,
19
)
UNCOV
20
from bpp.models import (
1✔
21
    Autor,
22
    Patent,
23
    Praca_Doktorska,
24
    Praca_Habilitacyjna,
25
    Wydawnictwo_Ciagle,
26
    Wydawnictwo_Zwarte,
27
    Zrodlo,
28
)
29

30

UNCOV
31
@pytest.mark.django_db
1✔
UNCOV
32
class TestBibTeXExport:
1✔
UNCOV
33
    def test_sanitize_bibtex_string(self):
1✔
34
        """Test that problematic characters are properly escaped."""
35
        test_cases = [
×
36
            ("Test & Title", "Test \\& Title"),
37
            ("Title with {braces}", "Title with \\{braces\\}"),
38
            ("Math $formula$", "Math \\$formula\\$"),
39
            ("Percentage 100%", "Percentage 100\\%"),
40
            ("Hash #tag", "Hash \\#tag"),
41
            ("Under_score", "Under\\_score"),
42
            ("Super^script", "Super\\^script"),
43
            ("Tilde~space", "Tilde\\~space"),
44
            (None, ""),
45
            ("", ""),
46
        ]
47

48
        for input_str, expected in test_cases:
×
49
            result = sanitize_bibtex_string(input_str)
×
50
            assert (
×
51
                result == expected
52
            ), f"Input: {input_str}, Expected: {expected}, Got: {result}"
53

UNCOV
54
    def test_generate_bibtex_key(self):
1✔
55
        """Test BibTeX key generation."""
56
        # Mock author
57
        autor = Mock()
×
58
        autor.nazwisko = "Kowalski"
×
59
        autor.imiona = "Jan"
×
60

61
        # Mock author relation
62
        autor_rel = Mock()
×
63
        autor_rel.autor = autor
×
64

65
        # Mock wydawnictwo
66
        wydawnictwo = Mock()
×
67
        wydawnictwo.rok = 2023
×
68
        wydawnictwo.pk = 123
×
69
        wydawnictwo.autorzy_dla_opisu.return_value.first.return_value = autor_rel
×
70

71
        key = generate_bibtex_key(wydawnictwo)
×
72
        assert "Kowalski" in key
×
73
        assert "2023" in key
×
74
        assert "id123" in key
×
75

UNCOV
76
    def test_wydawnictwo_ciagle_to_bibtex(self):
1✔
77
        """Test BibTeX export for Wydawnictwo_Ciagle."""
78
        # Mock zrodlo
79
        zrodlo = Mock()
×
80
        zrodlo.nazwa = "Test Journal"
×
81

82
        # Mock author
83
        autor = Mock()
×
84
        autor.nazwisko = "Smith"
×
85
        autor.imiona = "John"
×
86

87
        # Mock author relation
88
        autor_rel = Mock()
×
89
        autor_rel.autor = autor
×
90
        autor_rel.zapisany_jako = "Smith, John"
×
91

92
        # Mock wydawnictwo
93
        wydawnictwo = Mock()
×
94
        wydawnictwo.tytul_oryginalny = "Test Article Title"
×
95
        wydawnictwo.rok = 2023
×
96
        wydawnictwo.zrodlo = zrodlo
×
97
        wydawnictwo.doi = "10.1000/test"
×
98
        wydawnictwo.issn = "1234-5678"
×
99
        wydawnictwo.www = "https://example.com"
×
100
        wydawnictwo.pk = 1
×
101
        mock_queryset = Mock()
×
102
        mock_queryset.first.return_value = autor_rel
×
103
        mock_queryset.__iter__ = Mock(return_value=iter([autor_rel]))
×
104
        wydawnictwo.autorzy_dla_opisu.return_value = mock_queryset
×
105
        wydawnictwo.numer_tomu.return_value = None
×
106
        wydawnictwo.numer_wydania.return_value = None
×
107
        wydawnictwo.zakres_stron.return_value = "10-20"
×
108

109
        bibtex = wydawnictwo_ciagle_to_bibtex(wydawnictwo)
×
110

111
        # Check that all expected fields are present
112
        assert "@article{" in bibtex
×
113
        assert "title = {Test Article Title}" in bibtex
×
114
        assert "author = {Smith, John}" in bibtex
×
115
        assert "journal = {Test Journal}" in bibtex
×
116
        assert "year = {2023}" in bibtex
×
117
        assert "doi = {10.1000/test}" in bibtex
×
118
        assert "issn = {1234-5678}" in bibtex
×
119
        assert "url = {https://example.com}" in bibtex
×
120
        assert "pages = {10-20}" in bibtex
×
121
        assert bibtex.endswith("}\n")
×
122

UNCOV
123
    def test_wydawnictwo_zwarte_to_bibtex(self):
1✔
124
        """Test BibTeX export for Wydawnictwo_Zwarte."""
125
        # Create test data
126
        autor = baker.make(Autor, nazwisko="Johnson", imiona="Jane")
×
127
        wydawca = baker.make("bpp.Wydawca", nazwa="Test Publisher")
×
128

129
        wydawnictwo = baker.make(
×
130
            Wydawnictwo_Zwarte,
131
            tytul_oryginalny="Test Book Title",
132
            rok=2022,
133
            wydawca=wydawca,
134
            miejsce_i_rok="New York 2022",
135
            isbn="978-0-123456-78-9",
136
            www="https://book.example.com",
137
            strony="1-300",
138
        )
139

140
        # Add author
141
        baker.make(
×
142
            "bpp.Wydawnictwo_Zwarte_Autor",
143
            rekord=wydawnictwo,
144
            autor=autor,
145
            zapisany_jako="Johnson, Jane",
146
            kolejnosc=1,
147
        )
148

149
        bibtex = wydawnictwo_zwarte_to_bibtex(wydawnictwo)
×
150

151
        # Check that all expected fields are present
152
        assert "@book{" in bibtex
×
153
        assert "title = {Test Book Title}" in bibtex
×
154
        assert "author = {Johnson, Jane}" in bibtex
×
155
        assert "publisher = {Test Publisher}" in bibtex
×
156
        assert "year = {2022}" in bibtex
×
157
        assert "address = {New York}" in bibtex
×
158
        assert "isbn = {978-0-123456-78-9}" in bibtex
×
159
        assert "url = {https://book.example.com}" in bibtex
×
160
        assert "pages = {1-300}" in bibtex
×
161
        assert bibtex.endswith("}\n")
×
162

UNCOV
163
    def test_wydawnictwo_zwarte_chapter_to_bibtex(self):
1✔
164
        """Test BibTeX export for book chapter (Wydawnictwo_Zwarte with parent)."""
165
        # Create parent book
166
        parent_book = baker.make(
×
167
            Wydawnictwo_Zwarte, tytul_oryginalny="Parent Book Title", rok=2023
168
        )
169

170
        # Create chapter
171
        autor = baker.make(Autor, nazwisko="Brown", imiona="Bob")
×
172
        wydawca = baker.make("bpp.Wydawca", nazwa="Chapter Publisher")
×
173

174
        chapter = baker.make(
×
175
            Wydawnictwo_Zwarte,
176
            tytul_oryginalny="Chapter Title",
177
            rok=2023,
178
            wydawca=wydawca,
179
            wydawnictwo_nadrzedne=parent_book,
180
            strony="45-60",
181
        )
182

183
        # Add author
184
        baker.make(
×
185
            "bpp.Wydawnictwo_Zwarte_Autor",
186
            rekord=chapter,
187
            autor=autor,
188
            zapisany_jako="Brown, Bob",
189
            kolejnosc=1,
190
        )
191

192
        bibtex = wydawnictwo_zwarte_to_bibtex(chapter)
×
193

194
        # Check that it's formatted as incollection
195
        assert "@incollection{" in bibtex
×
196
        assert "title = {Chapter Title}" in bibtex
×
197
        assert "booktitle = {Parent Book Title}" in bibtex
×
198
        assert "author = {Brown, Bob}" in bibtex
×
199
        assert "pages = {45-60}" in bibtex
×
200

UNCOV
201
    def test_export_to_bibtex_multiple(self):
1✔
202
        """Test bulk export of multiple publications."""
203
        # Create test data
204
        zrodlo = baker.make(Zrodlo, nazwa="Journal")
×
205
        autor1 = baker.make(Autor, nazwisko="First", imiona="Author")
×
206
        autor2 = baker.make(Autor, nazwisko="Second", imiona="Author")
×
207
        wydawca = baker.make("bpp.Wydawca", nazwa="Publisher")
×
208

209
        # Create publications
210
        ciagle = baker.make(
×
211
            Wydawnictwo_Ciagle,
212
            tytul_oryginalny="Article Title",
213
            rok=2023,
214
            zrodlo=zrodlo,
215
        )
216
        baker.make(
×
217
            "bpp.Wydawnictwo_Ciagle_Autor",
218
            rekord=ciagle,
219
            autor=autor1,
220
            zapisany_jako="First, Author",
221
            kolejnosc=1,
222
        )
223

224
        zwarte = baker.make(
×
225
            Wydawnictwo_Zwarte, tytul_oryginalny="Book Title", rok=2023, wydawca=wydawca
226
        )
227
        baker.make(
×
228
            "bpp.Wydawnictwo_Zwarte_Autor",
229
            rekord=zwarte,
230
            autor=autor2,
231
            zapisany_jako="Second, Author",
232
            kolejnosc=1,
233
        )
234

235
        publications = [ciagle, zwarte]
×
236
        bibtex = export_to_bibtex(publications)
×
237

238
        # Check that both publications are included
239
        assert "@article{" in bibtex
×
240
        assert "@book{" in bibtex
×
241
        assert "Article Title" in bibtex
×
242
        assert "Book Title" in bibtex
×
243
        assert "First, Author" in bibtex
×
244
        assert "Second, Author" in bibtex
×
245

UNCOV
246
    def test_patent_to_bibtex(self):
1✔
247
        """Test BibTeX export for Patent."""
248
        # Create test data
249
        autor = baker.make(Autor, nazwisko="Tesla", imiona="Nikola")
×
250
        wydzial = baker.make("bpp.Wydzial", nazwa="Faculty of Engineering")
×
251

252
        patent = baker.make(
×
253
            Patent,
254
            tytul_oryginalny="Innovative Patent Title",
255
            rok=2023,
256
            numer_zgloszenia="P.123456",
257
            numer_prawa_wylacznego="123456",
258
            data_zgloszenia="2023-01-01",
259
            data_decyzji="2023-06-01",
260
            www="https://patent.example.com",
261
            wydzial=wydzial,
262
        )
263

264
        # Add author
265
        baker.make(
×
266
            "bpp.Patent_Autor",
267
            rekord=patent,
268
            autor=autor,
269
            zapisany_jako="Tesla, Nikola",
270
            kolejnosc=1,
271
        )
272

273
        bibtex = patent_to_bibtex(patent)
×
274

275
        # Check that all expected fields are present
276
        assert "@misc{" in bibtex
×
277
        assert "title = {Innovative Patent Title}" in bibtex
×
278
        assert "author = {Tesla, Nikola}" in bibtex
×
279
        assert "year = {2023}" in bibtex
×
280
        assert "Numer zgłoszenia: P.123456" in bibtex
×
281
        assert "Numer prawa wyłącznego: 123456" in bibtex
×
282
        assert "url = {https://patent.example.com}" in bibtex
×
283
        assert bibtex.endswith("}\n")
×
284

UNCOV
285
    def test_praca_doktorska_to_bibtex(self):
1✔
286
        """Test BibTeX export for Praca_Doktorska."""
287
        # Create test data
288
        autor = baker.make(Autor, nazwisko="Smith", imiona="John")
×
289
        uczelnia = baker.make("bpp.Uczelnia", nazwa="University")
×
290
        wydzial = baker.make(
×
291
            "bpp.Wydzial", nazwa="Faculty of Science", uczelnia=uczelnia
292
        )
293
        jednostka = baker.make(
×
294
            "bpp.Jednostka", nazwa="Department", wydzial=wydzial, uczelnia=uczelnia
295
        )
296

297
        praca = baker.make(
×
298
            Praca_Doktorska,
299
            tytul_oryginalny="Doctoral Dissertation Title",
300
            rok=2023,
301
            autor=autor,
302
            jednostka=jednostka,
303
            miejsce_i_rok="Warsaw 2023",
304
            www="https://thesis.example.com",
305
        )
306

307
        bibtex = praca_doktorska_to_bibtex(praca)
×
308

309
        # Check that all expected fields are present
310
        assert "@phdthesis{" in bibtex
×
311
        assert "title = {Doctoral Dissertation Title}" in bibtex
×
312
        assert "author = {Smith John}" in bibtex  # Note: format from autorzy_dla_opisu
×
313
        assert "school = {Faculty of Science}" in bibtex
×
314
        assert "year = {2023}" in bibtex
×
315
        assert "type = {Rozprawa doktorska}" in bibtex
×
316
        assert "address = {Warsaw}" in bibtex
×
317
        assert "url = {https://thesis.example.com}" in bibtex
×
318
        assert bibtex.endswith("}\n")
×
319

UNCOV
320
    def test_praca_habilitacyjna_to_bibtex(self):
1✔
321
        """Test BibTeX export for Praca_Habilitacyjna."""
322
        # Create test data
323
        autor = baker.make(Autor, nazwisko="Johnson", imiona="Jane")
×
324
        uczelnia = baker.make("bpp.Uczelnia", nazwa="University")
×
325
        wydzial = baker.make(
×
326
            "bpp.Wydzial", nazwa="Faculty of Medicine", uczelnia=uczelnia
327
        )
328
        jednostka = baker.make(
×
329
            "bpp.Jednostka", nazwa="Department", wydzial=wydzial, uczelnia=uczelnia
330
        )
331

332
        praca = baker.make(
×
333
            Praca_Habilitacyjna,
334
            tytul_oryginalny="Habilitation Thesis Title",
335
            rok=2022,
336
            autor=autor,
337
            jednostka=jednostka,
338
            miejsce_i_rok="Cracow 2022",
339
            www="https://habil.example.com",
340
        )
341

342
        bibtex = praca_habilitacyjna_to_bibtex(praca)
×
343

344
        # Check that all expected fields are present
345
        assert "@misc{" in bibtex
×
346
        assert "title = {Habilitation Thesis Title}" in bibtex
×
347
        assert (
×
348
            "author = {Johnson Jane}" in bibtex
349
        )  # Note: format from autorzy_dla_opisu
350
        assert "school = {Faculty of Medicine}" in bibtex
×
351
        assert "year = {2022}" in bibtex
×
352
        assert "note = {Rozprawa habilitacyjna}" in bibtex
×
353
        assert "address = {Cracow}" in bibtex
×
354
        assert "url = {https://habil.example.com}" in bibtex
×
355
        assert bibtex.endswith("}\n")
×
356

UNCOV
357
    def test_export_to_bibtex_all_types(self):
1✔
358
        """Test bulk export with all publication types."""
359
        # Create test data
360
        autor = baker.make(Autor, nazwisko="Multi", imiona="Author")
×
361
        zrodlo = baker.make(Zrodlo, nazwa="Journal")
×
362
        wydawca = baker.make("bpp.Wydawca", nazwa="Publisher")
×
363
        uczelnia = baker.make("bpp.Uczelnia", nazwa="University")
×
364
        wydzial = baker.make("bpp.Wydzial", nazwa="Faculty", uczelnia=uczelnia)
×
365
        jednostka = baker.make(
×
366
            "bpp.Jednostka", nazwa="Department", wydzial=wydzial, uczelnia=uczelnia
367
        )
368

369
        # Create publications of all types
370
        ciagle = baker.make(
×
371
            Wydawnictwo_Ciagle,
372
            tytul_oryginalny="Article Title",
373
            rok=2023,
374
            zrodlo=zrodlo,
375
        )
376
        baker.make(
×
377
            "bpp.Wydawnictwo_Ciagle_Autor",
378
            rekord=ciagle,
379
            autor=autor,
380
            zapisany_jako="Multi, Author",
381
            kolejnosc=1,
382
        )
383

384
        zwarte = baker.make(
×
385
            Wydawnictwo_Zwarte,
386
            tytul_oryginalny="Book Title",
387
            rok=2023,
388
            wydawca=wydawca,
389
        )
390
        baker.make(
×
391
            "bpp.Wydawnictwo_Zwarte_Autor",
392
            rekord=zwarte,
393
            autor=autor,
394
            zapisany_jako="Multi, Author",
395
            kolejnosc=1,
396
        )
397

398
        patent = baker.make(
×
399
            Patent,
400
            tytul_oryginalny="Patent Title",
401
            rok=2023,
402
        )
403
        baker.make(
×
404
            "bpp.Patent_Autor",
405
            rekord=patent,
406
            autor=autor,
407
            zapisany_jako="Multi, Author",
408
            kolejnosc=1,
409
        )
410

411
        praca_doktorska = baker.make(
×
412
            Praca_Doktorska,
413
            tytul_oryginalny="PhD Title",
414
            rok=2023,
415
            autor=autor,
416
            jednostka=jednostka,
417
        )
418

419
        praca_habilitacyjna = baker.make(
×
420
            Praca_Habilitacyjna,
421
            tytul_oryginalny="Habil Title",
422
            rok=2023,
423
            autor=autor,
424
            jednostka=jednostka,
425
        )
426

427
        publications = [ciagle, zwarte, patent, praca_doktorska, praca_habilitacyjna]
×
428
        bibtex = export_to_bibtex(publications)
×
429

430
        # Check that all publication types are included
431
        assert "@article{" in bibtex
×
432
        assert "@book{" in bibtex
×
433
        assert "@misc{" in bibtex
×
434
        assert "@phdthesis{" in bibtex
×
435
        assert "Article Title" in bibtex
×
436
        assert "Book Title" in bibtex
×
437
        assert "Patent Title" in bibtex
×
438
        assert "PhD Title" in bibtex
×
439
        assert "Habil Title" in bibtex
×
440

UNCOV
441
    def test_model_to_bibtex_methods(self):
1✔
442
        """Test that model instances have to_bibtex methods."""
443
        # Create minimal test data
444
        autor = baker.make(Autor, nazwisko="Test", imiona="Author")
×
445
        uczelnia = baker.make("bpp.Uczelnia", nazwa="University")
×
446
        wydzial = baker.make("bpp.Wydzial", nazwa="Faculty", uczelnia=uczelnia)
×
447
        jednostka = baker.make(
×
448
            "bpp.Jednostka", nazwa="Department", wydzial=wydzial, uczelnia=uczelnia
449
        )
450

451
        ciagle = baker.make(Wydawnictwo_Ciagle, tytul_oryginalny="Test Article")
×
452
        zwarte = baker.make(Wydawnictwo_Zwarte, tytul_oryginalny="Test Book")
×
453
        patent = baker.make(Patent, tytul_oryginalny="Test Patent")
×
454
        praca_doktorska = baker.make(
×
455
            Praca_Doktorska,
456
            tytul_oryginalny="Test PhD",
457
            autor=autor,
458
            jednostka=jednostka,
459
        )
460
        praca_habilitacyjna = baker.make(
×
461
            Praca_Habilitacyjna,
462
            tytul_oryginalny="Test Habil",
463
            autor=autor,
464
            jednostka=jednostka,
465
        )
466

467
        # Test that methods exist and return strings
468
        models_to_test = [
×
469
            (ciagle, "Test Article"),
470
            (zwarte, "Test Book"),
471
            (patent, "Test Patent"),
472
            (praca_doktorska, "Test PhD"),
473
            (praca_habilitacyjna, "Test Habil"),
474
        ]
475

476
        for model, expected_title in models_to_test:
×
477
            assert hasattr(
×
478
                model, "to_bibtex"
479
            ), f"{model._meta.model_name} missing to_bibtex method"
480
            bibtex = model.to_bibtex()
×
481
            assert isinstance(
×
482
                bibtex, str
483
            ), f"{model._meta.model_name} to_bibtex should return string"
484
            assert (
×
485
                expected_title in bibtex
486
            ), f"{expected_title} not found in bibtex for {model._meta.model_name}"
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc