Skip to content

Commit

Permalink
Unit tests: Import query classes at top of file
Browse files Browse the repository at this point in the history
  • Loading branch information
ferdnyc committed May 28, 2021
1 parent 36f380a commit a4fe6fc
Showing 1 changed file with 5 additions and 61 deletions.
66 changes: 5 additions & 61 deletions src/tests/query_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
sys.path.append(PATH)

from classes.app import OpenShotApp
from classes.query import Clip, File, Transition
from classes import info

app = None
Expand Down Expand Up @@ -130,22 +131,16 @@ def setUpClass(TestQueryClass):

@classmethod
def tearDownClass(cls):
"Hook method for deconstructing the class fixture after running all tests in the class."
TestQueryClass.app.quit()
""" Clean up after running all tests in the class. """
cls.app.quit()

def test_add_clip(self):
""" Test the Clip.save method by adding multiple clips """

# Import additional classes that need the app defined first
from classes.query import Clip

# Find number of clips in project
num_clips = len(Clip.filter())

# Create clip
c = openshot.Clip(os.path.join(info.IMAGES_PATH, "AboutLogo.png"))

# Parse JSON
clip_data = json.loads(c.Json())

# Insert into project data
Expand All @@ -158,16 +153,11 @@ def test_add_clip(self):

# Save the clip again (which should not change the total # of clips)
query_clip.save()

self.assertEqual(len(Clip.filter()), num_clips + 1)

def test_update_clip(self):
""" Test the Clip.save method """

# Import additional classes that need the app defined first
from classes.query import Clip

# Find a clip named file1
update_id = TestQueryClass.clip_ids[0]
clip = Clip.get(id=update_id)
self.assertTrue(clip)
Expand All @@ -178,7 +168,6 @@ def test_update_clip(self):
clip.save()

# Verify updated data
# Get clip again
clip = Clip.get(id=update_id)
self.assertEqual(clip.data["layer"], 2)
self.assertEqual(clip.data["title"], "My Title")
Expand All @@ -189,15 +178,10 @@ def test_update_clip(self):
def test_delete_clip(self):
""" Test the Clip.delete method """

# Import additional classes that need the app defined first
from classes.query import Clip

# Find a clip named file1
delete_id = TestQueryClass.clip_ids[4]
clip = Clip.get(id=delete_id)
self.assertTrue(clip)

# Delete clip
clip.delete()

# Verify deleted data
Expand All @@ -206,18 +190,12 @@ def test_delete_clip(self):

# Delete clip again (should do nothing)
clip.delete()

# Verify deleted data
deleted_clip = Clip.get(id=delete_id)
self.assertFalse(deleted_clip)

def test_filter_clip(self):
""" Test the Clip.filter method """

# Import additional classes that need the app defined first
from classes.query import Clip

# Find all clips named file1
clips = Clip.filter(id=TestQueryClass.clip_ids[0])
self.assertTrue(clips)

Expand All @@ -228,10 +206,6 @@ def test_filter_clip(self):
def test_get_clip(self):
""" Test the Clip.get method """

# Import additional classes that need the app defined first
from classes.query import Clip

# Find a clip named file1
clip = Clip.get(id=TestQueryClass.clip_ids[1])
self.assertTrue(clip)

Expand All @@ -242,9 +216,6 @@ def test_get_clip(self):
def test_intersect(self):
""" Test special filter argument 'intersect' """

# Import additional classes that need the app defined first
from classes.query import Clip, Transition

trans = Transition.get(id=self.transition_ids[0])
self.assertTrue(trans)

Expand Down Expand Up @@ -286,10 +257,6 @@ def get_times(item):
def test_update_File(self):
""" Test the File.save method """

# Import additional classes that need the app defined first
from classes.query import File

# Find a File named file1
update_id = TestQueryClass.file_ids[0]
file = File.get(id=update_id)
self.assertTrue(file)
Expand All @@ -300,43 +267,31 @@ def test_update_File(self):
file.save()

# Verify updated data
# Get File again
file = File.get(id=update_id)
self.assertEqual(file.data["height"], 1080)
self.assertEqual(file.data["width"], 1920)

def test_delete_File(self):
""" Test the File.delete method """

# Import additional classes that need the app defined first
from classes.query import File

# Find a File named file1
delete_id = TestQueryClass.file_ids[4]
file = File.get(id=delete_id)
self.assertTrue(file)

# Delete File
file.delete()

# Verify deleted data
deleted_file = File.get(id=delete_id)
self.assertFalse(deleted_file)

# Delete File again (should do nothing
# Delete File again (should do nothing)
file.delete()

# Verify deleted data
deleted_file = File.get(id=delete_id)
self.assertFalse(deleted_file)

def test_filter_File(self):
""" Test the File.filter method """

# Import additional classes that need the app defined first
from classes.query import File

# Find all Files named file1
files = File.filter(id=TestQueryClass.file_ids[0])
self.assertTrue(files)

Expand All @@ -347,10 +302,6 @@ def test_filter_File(self):
def test_get_File(self):
""" Test the File.get method """

# Import additional classes that need the app defined first
from classes.query import File

# Find a File named file1
file = File.get(id=TestQueryClass.file_ids[1])
self.assertTrue(file)

Expand All @@ -359,33 +310,26 @@ def test_get_File(self):
self.assertEqual(file, None)

def test_add_file(self):
""" Test the File.save method by adding multiple files """

# Import additional classes that need the app defined first
from classes.query import File

# Find number of files in project
num_files = len(File.filter())

# Create file
r = openshot.DummyReader(openshot.Fraction(24, 1), 640, 480, 44100, 2, 30.0)

# Parse JSON
file_data = json.loads(r.Json())

# Insert into project data
query_file = File()
query_file.data = file_data
query_file.data["path"] = os.path.join(info.IMAGES_PATH, "AboutLogo.png")
query_file.data["media_type"] = "image"
query_file.save()

query_file.save()
self.assertTrue(query_file)
self.assertEqual(len(File.filter()), num_files + 1)

# Save the file again (which should not change the total # of files)
query_file.save()

self.assertEqual(len(File.filter()), num_files + 1)


Expand Down

0 comments on commit a4fe6fc

Please sign in to comment.