Skip to content

Commit

Permalink
Merge pull request #105 from Bishoy-at-pieces/add-tests
Browse files Browse the repository at this point in the history
Create test_share.py
  • Loading branch information
bishoy-at-pieces authored Jul 1, 2024
2 parents 168ec6a + cbf7d17 commit fad161d
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/test_share.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
from UnitTesting.unittesting import DeferrableTestCase
import sublime

from Pieces.assets.share_asset import PiecesShareAssetCommand
from Pieces.assets.utils import AssetSnapshot

class TestShareCommand(DeferrableTestCase):
def setUp(self):
self.window = sublime.active_window()
self.main_views = self.window.views(include_transient=True)
self.view = self.window.new_file()
self.command = PiecesShareAssetCommand(self.window)
yield 3000 # Wait 3 sec for everything to load (websockets)
self.asset_id = list(AssetSnapshot.identifiers_snapshot.keys())[0]
self.inital_shares_len = self.get_shares_len()
print(self.inital_shares_len)

def tearDown(self):
if self.view:
self.view.close()

def get_shares_len(self):
return len(AssetSnapshot.identifiers_snapshot[self.asset_id].shares.iterable)

def disconnect_cloud(self):
self.window.run_command("pieces_allocation_disconnect")

def connect_cloud(self):
self.window.run_command("pieces_allocation_connect")

def test_share(self):
self.command.run(self.asset_id)


def test_share_disconnect_cloud(self):
"""
Test the shares API when the cloud is disconnected
"""
self.disconnect_cloud()
self.test_share()
yield 10000 # Wait for the shareable link to be generated
self.assertEqual(self.get_shares_len(),self.inital_shares_len)

def test_share_connect_cloud(self):
"""
Test the shares API when the cloud is Connected
"""
self.connect_cloud()
yield 5000
self.test_share()
yield 10000 # Wait for the shareable link to be generated
self.assertEqual(self.get_shares_len(),self.inital_shares_len+1)

0 comments on commit fad161d

Please sign in to comment.