Skip to content

Commit bc46a89

Browse files
committed
fix: update imports and test structure for new Confluence module organization
1 parent f323c6e commit bc46a89

File tree

2 files changed

+81
-75
lines changed

2 files changed

+81
-75
lines changed

atlassian/__init__.py

Lines changed: 31 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1+
"""
2+
Atlassian Python API
3+
"""
4+
15
from .bamboo import Bamboo
26
from .bitbucket import Bitbucket
37
from .bitbucket import Bitbucket as Stash
48
from .cloud_admin import CloudAdminOrgs, CloudAdminUsers
5-
from .confluence import Confluence
6-
from .confluence_base import ConfluenceBase
7-
from .confluence_v2 import ConfluenceV2
9+
from .confluence import (
10+
Confluence,
11+
ConfluenceBase,
12+
ConfluenceCloud,
13+
ConfluenceServer,
14+
)
815
from .crowd import Crowd
916
from .insight import Insight
1017
from .insight import Insight as Assets
@@ -15,6 +22,8 @@
1522
from .service_desk import ServiceDesk as ServiceManagement
1623
from .xray import Xray
1724

25+
# Compatibility: ConfluenceV2 is now ConfluenceCloud
26+
ConfluenceV2 = ConfluenceCloud
1827

1928
# Factory function for Confluence client
2029
def create_confluence(url, *args, api_version=1, **kwargs):
@@ -34,22 +43,23 @@ def create_confluence(url, *args, api_version=1, **kwargs):
3443

3544

3645
__all__ = [
37-
"Confluence",
38-
"ConfluenceBase",
39-
"ConfluenceV2",
40-
"create_confluence",
41-
"Jira",
42-
"Bitbucket",
43-
"CloudAdminOrgs",
44-
"CloudAdminUsers",
45-
"Portfolio",
46-
"Bamboo",
47-
"Stash",
48-
"Crowd",
49-
"ServiceDesk",
50-
"ServiceManagement",
51-
"MarketPlace",
52-
"Xray",
53-
"Insight",
54-
"Assets",
46+
'Confluence',
47+
'ConfluenceBase',
48+
'ConfluenceCloud',
49+
'ConfluenceServer',
50+
'ConfluenceV2', # For backward compatibility
51+
'Jira',
52+
'Bitbucket',
53+
'CloudAdminOrgs',
54+
'CloudAdminUsers',
55+
'Portfolio',
56+
'Bamboo',
57+
'Stash',
58+
'Crowd',
59+
'ServiceDesk',
60+
'ServiceManagement',
61+
'MarketPlace',
62+
'Xray',
63+
'Insight',
64+
'Assets',
5565
]

tests/test_confluence_v2_integration.py

Lines changed: 50 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
#!/usr/bin/env python3
22
"""
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
114
"""
12-
135
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
1716

18-
from atlassian.confluence_v2 import ConfluenceV2
17+
log = logging.getLogger(__name__)
1918

2019
# Create a module-level object to store test data between tests
2120
class _STORED_TEST_PAGE_DATA:
@@ -403,21 +402,21 @@ def search(self,
403402
return mock_response
404403

405404

406-
@unittest.skipIf(
405+
@pytest.mark.skipif(
407406
not (
408407
os.environ.get("CONFLUENCE_URL")
409408
and os.environ.get("CONFLUENCE_USERNAME")
410409
and os.environ.get("CONFLUENCE_API_TOKEN")
411410
and os.environ.get("CONFLUENCE_SPACE_KEY")
412411
),
413-
"Confluence credentials not found in environment variables",
412+
reason="Confluence credentials not found in environment variables",
414413
)
415-
class TestConfluenceV2Integration(unittest.TestCase):
414+
class TestConfluenceV2Integration:
416415
"""
417416
Test the ConfluenceV2 class.
418417
"""
419418

420-
def setUp(self):
419+
def setup(self):
421420
"""
422421
Set up the test environment.
423422
"""
@@ -442,7 +441,7 @@ def setUp(self):
442441
space_key=self.space_key
443442
)
444443

445-
def tearDown(self):
444+
def teardown(self):
446445
"""
447446
Clean up after tests.
448447
"""
@@ -466,32 +465,32 @@ def test_01_authentication(self):
466465

467466
# Test spaces with mock responses
468467
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)
471470
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]
474473

475474
def test_02_get_spaces(self):
476475
"""Test getting spaces."""
477476
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
481480

482481
if spaces["results"]:
483482
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
487486

488487
def test_03_get_space_by_key(self):
489488
"""Test getting a space by key."""
490489
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
495494

496495
def test_04_page_operations(self):
497496
"""Test creating, updating, and deleting a page."""
@@ -505,14 +504,14 @@ def test_04_page_operations(self):
505504
body=body,
506505
)
507506

508-
self.assertIsInstance(page, dict)
509-
self.assertIn("id", page)
507+
assert isinstance(page, dict)
508+
assert "id" in page
510509
page_id = page["id"]
511510

512511
# Get the page
513512
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
516515

517516
# Update the page
518517
updated_title = f"{title} - Updated"
@@ -525,19 +524,19 @@ def test_04_page_operations(self):
525524
version=retrieved_page["version"]["number"],
526525
)
527526

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
530529

531530
# Get the updated page
532531
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
534533

535534
# Delete the page
536535
response = self.confluence.delete_page(page_id)
537-
self.assertEqual(response.get("status", 204), 204)
536+
assert response.get("status", 204) == 204
538537

539538
# Verify it's deleted by trying to get it (should raise an exception)
540-
with self.assertRaises(Exception):
539+
with pytest.raises(Exception):
541540
self.confluence.get_page_by_id(page_id)
542541

543542
def test_05_search(self):
@@ -550,15 +549,15 @@ def test_05_search(self):
550549
limit=5
551550
)
552551

553-
self.assertIsInstance(results, dict)
554-
self.assertIn("results", results)
552+
assert isinstance(results, dict)
553+
assert "results" in results
555554

556555
def test_06_pagination(self):
557556
"""Test pagination of results."""
558557
# Get pages with pagination
559558
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
562561

563562
# If there are more pages
564563
if "next" in page1.get("_links", {}):
@@ -574,26 +573,23 @@ def test_06_pagination(self):
574573
# Get next page using cursor
575574
if "cursor" in query_params:
576575
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
579578

580579
# Verify we got different results
581580
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"]
586582

587583
def test_07_error_handling(self):
588584
"""Test error handling."""
589585
# Test with an invalid page ID
590-
with self.assertRaises(Exception):
586+
with pytest.raises(Exception):
591587
self.confluence.get_page_by_id("invalid-id")
592588

593589
# Test with an invalid space key
594-
with self.assertRaises(Exception):
590+
with pytest.raises(Exception):
595591
self.confluence.get_space("invalid-space-key-that-does-not-exist")
596592

597593

598594
if __name__ == "__main__":
599-
unittest.main()
595+
pytest.main()

0 commit comments

Comments
 (0)