1111client_id = os .environ .get ("BITWARDEN_CLIENT_ID" , None )
1212client_secret = os .environ .get ("BITWARDEN_CLIENT_SECRET" , None )
1313device_id = os .environ .get ("BITWARDEN_DEVICE_ID" , None )
14-
1514bitwarden = BitwardenAPIClient (
1615 url , email , password , client_id , client_secret , device_id
1716)
@@ -27,35 +26,41 @@ def setUp(self) -> None:
2726 self .test_colls_ids = self .organization .collections ()
2827 self .test_users = self .organization .users ()
2928 self .test_org_ciphers = self .organization .ciphers ()
30- self .test_coll_1_cipher = self .organization .ciphers (
31- self .test_colls_names .get ("1_cipher " ).Id
29+ self .test_collection_1_ciphers = self .organization .ciphers (
30+ self .test_colls_names .get ("test-collection " ).Id
3231 )
33- self .test_coll_2_ciphers = self .organization .ciphers (
34- self .test_colls_names .get ("2_ciphers " ).Id
32+ self .test_collection_2_ciphers = self .organization .ciphers (
33+ self .test_colls_names .get ("test-collection-2 " ).Id
3534 )
36- self .test_coll_1_user = self .test_colls_names .get ("1_user" ).users ()
37- self .test_coll_2_users = self .test_colls_names .get ("2_users" ).users ()
35+ self .test_collection_1_users = self .test_colls_names .get (
36+ "test-collection"
37+ ).users ()
38+ self .test_collection_2_users = self .test_colls_names .get (
39+ "test-collection-2"
40+ ).users ()
3841
3942 def test_get_organization_users (self ):
40- self .assertEqual (len (self .test_users ), 4 )
43+ self .assertEqual (len (self .test_users ), 2 )
4144
4245 def test_get_organization_items (self ):
43- self .assertEqual (len (self .test_org_ciphers ), 5 )
46+ self .assertEqual (len (self .test_org_ciphers ), 1 )
4447
4548 def test_get_organization_collection_1_item (self ):
46- self .assertEqual (len (self .test_coll_1_cipher ), 1 )
49+ self .assertEqual (len (self .test_collection_1_ciphers ), 0 )
4750
4851 def test_get_organization_collection_2_items (self ):
49- self .assertEqual (len (self .test_coll_2_ciphers ), 2 )
52+ self .assertEqual (len (self .test_collection_2_ciphers ), 1 )
5053
5154 def test_get_organizations_collections (self ):
52- self .assertEqual (len (self .test_colls_ids ), 5 )
55+ # 2 test collections + default collection
56+ self .assertEqual (len (self .test_colls_ids ), 3 )
5357
5458 def test_get_users_of_collection_1 (self ):
55- self .assertEqual (len (self .test_coll_1_user ), 1 )
59+ # 2 test collections + default collection
60+ self .assertEqual (len (self .test_collection_1_users ), 0 )
5661
5762 def test_get_users_of_collection_2 (self ):
58- self .assertEqual (len (self .test_coll_2_users ), 2 )
63+ self .assertEqual (len (self .test_collection_2_users ), 1 )
5964
6065 def test_create_delete_collection (self ):
6166 len_old_colls = len (self .organization .collections (force_refresh = True ))
@@ -67,30 +72,49 @@ def test_create_delete_collection(self):
6772 self .assertEqual (len (new_colls ), len_old_colls )
6873
6974 def test_set_users_of_collection (self ):
70- coll = self .test_colls_names .get ("1_user" )
71- coll .set_users (self .test_coll_2_users )
72- users = coll .users ()
73- self .assertEqual (len (users ), 2 )
74- coll .set_users (self .test_coll_1_user )
75+ coll = self .test_colls_names .get ("test-collection" )
76+ coll .set_users (self .test_collection_2_users )
7577 users = coll .users ()
7678 self .assertEqual (len (users ), 1 )
79+ coll .set_users (self .test_collection_1_users )
80+ users = coll .users ()
81+ self .assertEqual (len (users ), 0 )
7782
7883 def test_add_remove_collection_from_user (self ):
79- user_org_id = self .test_coll_1_user [0 ].UserId
84+ user_org_id = self .test_collection_2_users [0 ].UserId
8085 user_infos = self .organization .user (user_org_id )
81- coll_1_user = self .test_colls_names .get ("1_user " )
82- user_infos .remove_collections ([coll_1_user .Id ])
86+ collection_2 = self .test_colls_names .get ("test-collection-2 " )
87+ user_infos .remove_collections ([collection_2 .Id ])
8388 self .assertEqual (
84- len (coll_1_user .users ()),
89+ len (collection_2 .users ()),
8590 0 ,
8691 )
87- user_infos .add_collections ([coll_1_user .Id ])
88- users = coll_1_user .users ()
92+ user_infos .add_collections ([collection_2 .Id ])
93+ users = collection_2 .users ()
8994 self .assertEqual (
9095 len (users ),
9196 1 ,
9297 )
9398
99+ def test_invite_user_than_remove (self ):
100+ resp = self .organization .invite ("test-user-3@example.com" )
101+ self .assertTrue (resp .is_success )
102+ user = self .organization .user_search (
103+ "test-user-3@example.com" , force_refresh = True
104+ )
105+ self .assertIsNotNone (user )
106+ user .delete ()
107+
108+ def test_add_remove_collection_cipher (self ):
109+ cipher = self .test_org_ciphers [0 ]
110+ old_colls = cipher .CollectionIds
111+ collection_1 = self .test_colls_ids [0 ]
112+ cipher .add_collections (collections = [collection_1 .Id ])
113+ res = self .organization .ciphers (force_refresh = True )
114+ self .assertEqual (len (res ), 1 )
115+ self .assertEqual (len (res [0 ].CollectionIds ), 2 )
116+ cipher .update_collection (old_colls )
117+
94118 def test_deduplicate (self ):
95119 # Todo build test fixtures and delete them at the end of the test
96120 return
0 commit comments