26
26
import tempfile
27
27
import unittest
28
28
29
- from freeseer .framework .config import Config
30
- from freeseer .framework .config import options
29
+ from freeseer .framework .config import Config , options
31
30
from freeseer .framework .config .exceptions import StorageNotSetError
32
- from freeseer .framework .config .persist import ConfigParserStorage
33
- from freeseer .framework .config .persist import JSONConfigStorage
34
- from freeseer .framework .config .profile import Profile
35
- from freeseer .framework .config .profile import ProfileManager
31
+ from freeseer .framework .config .persist import ConfigParserStorage , JSONConfigStorage
32
+ from freeseer .framework .config .profile import Profile , ProfileAlreadyExists , ProfileDoesNotExist , ProfileManager
36
33
from freeseer .framework .database import QtDBConnector
37
34
38
35
@@ -56,12 +53,55 @@ def test_get(self):
56
53
profile = self .profile_manager .get ('testing' )
57
54
self .assertIsInstance (profile , Profile )
58
55
56
+ def test_get_non_existent (self ):
57
+ """Test for non-existent profile."""
58
+ self .assertRaises (ProfileDoesNotExist , self .profile_manager .get , 'non-existent_profile' , create_if_needed = False )
59
+
60
+ def test_get_non_existent_creates (self ):
61
+ """Test that get creates non-existent profile if create_if_needed=True."""
62
+ self .assertRaises (ProfileDoesNotExist , self .profile_manager .get , 'non-existent_profile' , create_if_needed = False )
63
+ profile = self .profile_manager .get ('non_existent_profile' )
64
+ self .assertIsInstance (profile , Profile )
65
+
59
66
def test_get_cache (self ):
60
67
"""Tests that get caching is working as expected."""
61
68
profile1 = self .profile_manager .get ('testing' )
62
69
profile2 = self .profile_manager .get ('testing' )
63
70
self .assertEqual (profile1 , profile2 )
64
71
72
+ def test_list_profiles (self ):
73
+ """Tests that list_profiles returns all profiles on file."""
74
+ self .profile_manager .create ('testing1' )
75
+ self .profile_manager .create ('testing2' )
76
+ profiles = self .profile_manager .list_profiles ()
77
+ self .assertItemsEqual (['testing1' , 'testing2' ], profiles )
78
+
79
+ def test_create_profile (self ):
80
+ """Tests that create_profile returns an instance of Profile.."""
81
+ profile = self .profile_manager .create ('testing1' )
82
+ self .assertIsInstance (profile , Profile )
83
+
84
+ def test_create_profile_existing (self ):
85
+ """Tests that exception is raised if trying to overwrite existing profile."""
86
+ self .profile_manager .create ('testing1' )
87
+ self .assertRaises (ProfileAlreadyExists , self .profile_manager .create , 'testing1' )
88
+
89
+ def test_create_profile_caches (self ):
90
+ """Tests that create_profile adds the new Profile instance to cache."""
91
+ self .assertNotIn ('testing1' , self .profile_manager ._cache )
92
+ self .profile_manager .create ('testing1' )
93
+ self .assertIn ('testing1' , self .profile_manager ._cache )
94
+
95
+ def test_delete_profile_existing (self ):
96
+ """Tests that delete_profile deletes the profile from cache and file."""
97
+ self .profile_manager .create ('testing1' )
98
+ self .profile_manager .delete ('testing1' )
99
+ self .assertRaises (ProfileDoesNotExist , self .profile_manager .get , 'testing1' , create_if_needed = False )
100
+
101
+ def test_delete_profile_non_existing (self ):
102
+ """Non-existent profiles can't be deleted."""
103
+ self .assertRaises (ProfileDoesNotExist , self .profile_manager .delete , 'testing' )
104
+
65
105
66
106
class TestProfile (unittest .TestCase ):
67
107
"""Tests Profile."""
0 commit comments