1
1
#!/usr/bin/env python3
2
2
"""
3
- Integration tests for Confluence v2 API.
4
- These tests are designed to be run against a real Confluence instance.
5
-
6
- NOTE: To run these tests, you need to set the following environment variables:
7
- - CONFLUENCE_URL: The URL of the Confluence instance
8
- - CONFLUENCE_USERNAME: The username to use for authentication
9
- - CONFLUENCE_API_TOKEN: The API token to use for authentication
10
- - CONFLUENCE_SPACE_KEY: A space key to use for testing
3
+ Integration tests for Confluence V2 API
11
4
"""
12
-
13
5
import os
14
- import unittest
15
- import warnings
16
- from typing import Dict , Any , List , Union , Optional
6
+ import sys
7
+ import logging
8
+ import pytest
9
+ import responses
10
+ import json
11
+ import re
12
+ from datetime import datetime , timezone
13
+ from typing import Dict , List , Optional , Union , Any
14
+
15
+ from atlassian import ConfluenceV2
17
16
18
- from atlassian . confluence_v2 import ConfluenceV2
17
+ log = logging . getLogger ( __name__ )
19
18
20
19
# Create a module-level object to store test data between tests
21
20
class _STORED_TEST_PAGE_DATA :
@@ -403,21 +402,21 @@ def search(self,
403
402
return mock_response
404
403
405
404
406
- @unittest . skipIf (
405
+ @pytest . mark . skipif (
407
406
not (
408
407
os .environ .get ("CONFLUENCE_URL" )
409
408
and os .environ .get ("CONFLUENCE_USERNAME" )
410
409
and os .environ .get ("CONFLUENCE_API_TOKEN" )
411
410
and os .environ .get ("CONFLUENCE_SPACE_KEY" )
412
411
),
413
- "Confluence credentials not found in environment variables" ,
412
+ reason = "Confluence credentials not found in environment variables" ,
414
413
)
415
- class TestConfluenceV2Integration ( unittest . TestCase ) :
414
+ class TestConfluenceV2Integration :
416
415
"""
417
416
Test the ConfluenceV2 class.
418
417
"""
419
418
420
- def setUp (self ):
419
+ def setup (self ):
421
420
"""
422
421
Set up the test environment.
423
422
"""
@@ -442,7 +441,7 @@ def setUp(self):
442
441
space_key = self .space_key
443
442
)
444
443
445
- def tearDown (self ):
444
+ def teardown (self ):
446
445
"""
447
446
Clean up after tests.
448
447
"""
@@ -466,32 +465,32 @@ def test_01_authentication(self):
466
465
467
466
# Test spaces with mock responses
468
467
spaces = self .confluence .get_spaces (limit = 1 )
469
- self . assertIn ( "results" , spaces )
470
- self . assertIsInstance (spaces ["results" ], list )
468
+ assert "results" in spaces
469
+ assert isinstance (spaces ["results" ], list )
471
470
if len (spaces ["results" ]) > 0 :
472
- self . assertIn ( "id" , spaces ["results" ][0 ])
473
- self . assertIn ( "key" , spaces ["results" ][0 ])
471
+ assert "id" in spaces ["results" ][0 ]
472
+ assert "key" in spaces ["results" ][0 ]
474
473
475
474
def test_02_get_spaces (self ):
476
475
"""Test getting spaces."""
477
476
spaces = self .confluence .get_spaces (limit = 3 )
478
- self . assertIsInstance (spaces , dict )
479
- self . assertIn ( "results" , spaces )
480
- self . assertLessEqual ( len (spaces ["results" ]), 3 )
477
+ assert isinstance (spaces , dict )
478
+ assert "results" in spaces
479
+ assert len (spaces ["results" ]) <= 3
481
480
482
481
if spaces ["results" ]:
483
482
space = spaces ["results" ][0 ]
484
- self . assertIn ( "id" , space )
485
- self . assertIn ( "key" , space )
486
- self . assertIn ( "name" , space )
483
+ assert "id" in space
484
+ assert "key" in space
485
+ assert "name" in space
487
486
488
487
def test_03_get_space_by_key (self ):
489
488
"""Test getting a space by key."""
490
489
space = self .confluence .get_space (self .space_key )
491
- self . assertIsInstance (space , dict )
492
- self . assertIn ( "id" , space )
493
- self . assertIn ( "key" , space )
494
- self . assertEqual ( space ["key" ], self .space_key )
490
+ assert isinstance (space , dict )
491
+ assert "id" in space
492
+ assert "key" in space
493
+ assert space ["key" ] == self .space_key
495
494
496
495
def test_04_page_operations (self ):
497
496
"""Test creating, updating, and deleting a page."""
@@ -505,14 +504,14 @@ def test_04_page_operations(self):
505
504
body = body ,
506
505
)
507
506
508
- self . assertIsInstance (page , dict )
509
- self . assertIn ( "id" , page )
507
+ assert isinstance (page , dict )
508
+ assert "id" in page
510
509
page_id = page ["id" ]
511
510
512
511
# Get the page
513
512
retrieved_page = self .confluence .get_page_by_id (page_id )
514
- self . assertEqual ( retrieved_page ["id" ], page_id )
515
- self . assertEqual ( retrieved_page ["title" ], title )
513
+ assert retrieved_page ["id" ] == page_id
514
+ assert retrieved_page ["title" ] == title
516
515
517
516
# Update the page
518
517
updated_title = f"{ title } - Updated"
@@ -525,19 +524,19 @@ def test_04_page_operations(self):
525
524
version = retrieved_page ["version" ]["number" ],
526
525
)
527
526
528
- self . assertEqual ( updated_page ["id" ], page_id )
529
- self . assertEqual ( updated_page ["title" ], updated_title )
527
+ assert updated_page ["id" ] == page_id
528
+ assert updated_page ["title" ] == updated_title
530
529
531
530
# Get the updated page
532
531
retrieved_updated_page = self .confluence .get_page_by_id (page_id )
533
- self . assertEqual ( retrieved_updated_page ["title" ], updated_title )
532
+ assert retrieved_updated_page ["title" ] == updated_title
534
533
535
534
# Delete the page
536
535
response = self .confluence .delete_page (page_id )
537
- self . assertEqual ( response .get ("status" , 204 ), 204 )
536
+ assert response .get ("status" , 204 ) == 204
538
537
539
538
# Verify it's deleted by trying to get it (should raise an exception)
540
- with self . assertRaises (Exception ):
539
+ with pytest . raises (Exception ):
541
540
self .confluence .get_page_by_id (page_id )
542
541
543
542
def test_05_search (self ):
@@ -550,15 +549,15 @@ def test_05_search(self):
550
549
limit = 5
551
550
)
552
551
553
- self . assertIsInstance (results , dict )
554
- self . assertIn ( "results" , results )
552
+ assert isinstance (results , dict )
553
+ assert "results" in results
555
554
556
555
def test_06_pagination (self ):
557
556
"""Test pagination of results."""
558
557
# Get pages with pagination
559
558
page1 = self .confluence .get_pages (limit = 5 )
560
- self . assertIsInstance (page1 , dict )
561
- self . assertIn ( "results" , page1 )
559
+ assert isinstance (page1 , dict )
560
+ assert "results" in page1
562
561
563
562
# If there are more pages
564
563
if "next" in page1 .get ("_links" , {}):
@@ -574,26 +573,23 @@ def test_06_pagination(self):
574
573
# Get next page using cursor
575
574
if "cursor" in query_params :
576
575
page2 = self .confluence .get_pages (limit = 5 , cursor = query_params ["cursor" ])
577
- self . assertIsInstance (page2 , dict )
578
- self . assertIn ( "results" , page2 )
576
+ assert isinstance (page2 , dict )
577
+ assert "results" in page2
579
578
580
579
# Verify we got different results
581
580
if page1 ["results" ] and page2 ["results" ]:
582
- self .assertNotEqual (
583
- page1 ["results" ][0 ]["id" ] if page1 ["results" ] else None ,
584
- page2 ["results" ][0 ]["id" ] if page2 ["results" ] else None
585
- )
581
+ assert page1 ["results" ][0 ]["id" ] != page2 ["results" ][0 ]["id" ]
586
582
587
583
def test_07_error_handling (self ):
588
584
"""Test error handling."""
589
585
# Test with an invalid page ID
590
- with self . assertRaises (Exception ):
586
+ with pytest . raises (Exception ):
591
587
self .confluence .get_page_by_id ("invalid-id" )
592
588
593
589
# Test with an invalid space key
594
- with self . assertRaises (Exception ):
590
+ with pytest . raises (Exception ):
595
591
self .confluence .get_space ("invalid-space-key-that-does-not-exist" )
596
592
597
593
598
594
if __name__ == "__main__" :
599
- unittest .main ()
595
+ pytest .main ()
0 commit comments