From b97144dcc970750b265b8e9605f9a4da0cee50e4 Mon Sep 17 00:00:00 2001 From: Sebastian Spaeth Date: Tue, 8 Jan 2013 13:31:16 +0100 Subject: tests: More instances where a fresh database is not needed Save test runtime by not dumping the databases when not needed. --- mediagoblin/tests/test_misc.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 94ae5a51..8a96e7d0 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,11 +16,9 @@ from nose.tools import assert_equal -from mediagoblin.tests.tools import setup_fresh_app +from mediagoblin.tests.tools import get_test_app - -@setup_fresh_app -def test_404_for_non_existent(test_app): - assert_equal(test_app.get('/does-not-exist/', - expect_errors=True).status_int, - 404) +def test_404_for_non_existent(): + test_app = get_test_app(dump_old_app=False) + res = test_app.get('/does-not-exist/', expect_errors=True) + assert_equal(res.status_int, 404) -- cgit v1.2.3 From 1be247b36e58c8c71a974b65dff7194f28483f12 Mon Sep 17 00:00:00 2001 From: Elrond Date: Fri, 18 Jan 2013 11:40:40 +0100 Subject: Rename get_test_app to get_app. nosetests runs everything that even vaguely looks like a test case... even our get_test_app. And as it is imported everywhere... it is run everywhere as a test case. Renaming it saves us about 10+ tests and a few seconds of time. --- mediagoblin/tests/test_misc.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 8a96e7d0..ae5d7e50 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,9 +16,9 @@ from nose.tools import assert_equal -from mediagoblin.tests.tools import get_test_app +from mediagoblin.tests.tools import get_app def test_404_for_non_existent(): - test_app = get_test_app(dump_old_app=False) + test_app = get_app(dump_old_app=False) res = test_app.get('/does-not-exist/', expect_errors=True) assert_equal(res.status_int, 404) -- cgit v1.2.3 From e9b4e50007405d548572ad874bdf7d76f6668b27 Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 29 Jan 2013 21:13:49 +0100 Subject: Failing testcase for issue 611. This currently fails (with foreign key constrain error): 1. Have user A and B. 2. User B creates media M. 3. User A post a comment on M. 4. User A deletes his own account. The test is a little bit wider. --- mediagoblin/tests/test_misc.py | 52 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index ae5d7e50..22a06898 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,9 +16,59 @@ from nose.tools import assert_equal -from mediagoblin.tests.tools import get_app +from mediagoblin.db.models import User, MediaEntry, MediaComment +from mediagoblin.tests.tools import get_app, \ + fixture_add_user, fixture_media_entry + def test_404_for_non_existent(): test_app = get_app(dump_old_app=False) res = test_app.get('/does-not-exist/', expect_errors=True) assert_equal(res.status_int, 404) + + +def test_user_deletes_other_comments(): + user_a = fixture_add_user(u"chris_a") + user_b = fixture_add_user(u"chris_b") + + media_a = fixture_media_entry(uploader=user_a.id) + media_b = fixture_media_entry(uploader=user_b.id) + + # Create all 4 possible comments: + for u_id in (user_a.id, user_b.id): + for m_id in (media_a.id, media_b.id): + cmt = MediaComment() + cmt.media_entry = m_id + cmt.author = u_id + cmt.content = u"Some Comment" + cmt.save() + + usr_cnt1 = User.query.count() + med_cnt1 = MediaEntry.query.count() + cmt_cnt1 = MediaComment.query.count() + + User.query.get(user_a.id).delete() + + usr_cnt2 = User.query.count() + med_cnt2 = MediaEntry.query.count() + cmt_cnt2 = MediaComment.query.count() + + # One user deleted + assert_equal(usr_cnt2, usr_cnt1 - 1) + # One media gone + assert_equal(med_cnt2, med_cnt1 - 1) + # Three of four comments gone. + assert_equal(cmt_cnt2, cmt_cnt1 - 3) + + User.query.get(user_b.id).delete() + + usr_cnt2 = User.query.count() + med_cnt2 = MediaEntry.query.count() + cmt_cnt2 = MediaComment.query.count() + + # All users gone + assert_equal(usr_cnt2, usr_cnt1 - 2) + # All media gone + assert_equal(med_cnt2, med_cnt1 - 2) + # All comments gone + assert_equal(cmt_cnt2, cmt_cnt1 - 4) -- cgit v1.2.3 From 3f931680e361086508d24d357f3d4d44466164bf Mon Sep 17 00:00:00 2001 From: Elrond Date: Tue, 29 Jan 2013 21:45:16 +0100 Subject: Improve runtime of one test. Do not commit so often. flushing is enough. --- mediagoblin/tests/test_misc.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 22a06898..b48b8762 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -16,6 +16,7 @@ from nose.tools import assert_equal +from mediagoblin.db.base import Session from mediagoblin.db.models import User, MediaEntry, MediaComment from mediagoblin.tests.tools import get_app, \ fixture_add_user, fixture_media_entry @@ -31,8 +32,11 @@ def test_user_deletes_other_comments(): user_a = fixture_add_user(u"chris_a") user_b = fixture_add_user(u"chris_b") - media_a = fixture_media_entry(uploader=user_a.id) - media_b = fixture_media_entry(uploader=user_b.id) + media_a = fixture_media_entry(uploader=user_a.id, save=False) + media_b = fixture_media_entry(uploader=user_b.id, save=False) + Session.add(media_a) + Session.add(media_b) + Session.flush() # Create all 4 possible comments: for u_id in (user_a.id, user_b.id): @@ -41,13 +45,15 @@ def test_user_deletes_other_comments(): cmt.media_entry = m_id cmt.author = u_id cmt.content = u"Some Comment" - cmt.save() + Session.add(cmt) + + Session.flush() usr_cnt1 = User.query.count() med_cnt1 = MediaEntry.query.count() cmt_cnt1 = MediaComment.query.count() - User.query.get(user_a.id).delete() + User.query.get(user_a.id).delete(commit=False) usr_cnt2 = User.query.count() med_cnt2 = MediaEntry.query.count() -- cgit v1.2.3 From df5b142ab9bfc590f17768079104f6cfa2cd7bba Mon Sep 17 00:00:00 2001 From: Elrond Date: Mon, 18 Feb 2013 14:46:28 +0100 Subject: Fix deleting media with attachments. If one deletes a media with attachments, there have been various problems: 1) If the file in the storage did not exist any more (maybe because due to a previous deletion attempt?), the error propagation failed, because the wrong thing was gathered. 2) The attachment database entries were not deleted. Using cascade for this, for now. Also add a simple unit test, that tests both by having a broken attachment on a media. --- mediagoblin/tests/test_misc.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index b48b8762..776affc6 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -78,3 +78,18 @@ def test_user_deletes_other_comments(): assert_equal(med_cnt2, med_cnt1 - 2) # All comments gone assert_equal(cmt_cnt2, cmt_cnt1 - 4) + + +def test_media_deletes_broken_attachment(): + user_a = fixture_add_user(u"chris_a") + + media = fixture_media_entry(uploader=user_a.id, save=False) + media.attachment_files.append(dict( + name=u"some name", + filepath=[u"does", u"not", u"exist"], + )) + Session.add(media) + Session.flush() + + MediaEntry.query.get(media.id).delete() + User.query.get(user_a.id).delete() -- cgit v1.2.3 From cb1454408299afed5376b15c004e0e2170280a05 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Wed, 3 Apr 2013 14:32:35 -0500 Subject: These tests need to have a MediaGoblin app setup so they can connect to the db! Thanks to py.test --boxed for helping discover that ;) --- mediagoblin/tests/test_misc.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 776affc6..b20262cf 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -29,6 +29,7 @@ def test_404_for_non_existent(): def test_user_deletes_other_comments(): + get_app() # gotta init the db and etc user_a = fixture_add_user(u"chris_a") user_b = fixture_add_user(u"chris_b") @@ -81,6 +82,7 @@ def test_user_deletes_other_comments(): def test_media_deletes_broken_attachment(): + get_app() # gotta init the db and etc user_a = fixture_add_user(u"chris_a") media = fixture_media_entry(uploader=user_a.id, save=False) -- cgit v1.2.3 From 5c2ece7401723486d76ea0fcd2f99ba4d1002504 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 4 Apr 2013 19:23:04 -0500 Subject: Switch test_app generation over to use py.test fixtures. By doing this, we can take advantage of py.test's ability to create temporary directories that are then cleaned up later during testing. This helps for sandboxing things. This also involves a ton of changes: - Changing the get_app stuff appropriately, getting rid of the setup_fresh_app decorator - Making said fixture - Switching over a billion tests to use it --- mediagoblin/tests/test_misc.py | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index b20262cf..7143938e 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -18,18 +18,15 @@ from nose.tools import assert_equal from mediagoblin.db.base import Session from mediagoblin.db.models import User, MediaEntry, MediaComment -from mediagoblin.tests.tools import get_app, \ - fixture_add_user, fixture_media_entry +from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry -def test_404_for_non_existent(): - test_app = get_app(dump_old_app=False) +def test_404_for_non_existent(test_app): res = test_app.get('/does-not-exist/', expect_errors=True) assert_equal(res.status_int, 404) -def test_user_deletes_other_comments(): - get_app() # gotta init the db and etc +def test_user_deletes_other_comments(test_app): user_a = fixture_add_user(u"chris_a") user_b = fixture_add_user(u"chris_b") @@ -81,8 +78,7 @@ def test_user_deletes_other_comments(): assert_equal(cmt_cnt2, cmt_cnt1 - 4) -def test_media_deletes_broken_attachment(): - get_app() # gotta init the db and etc +def test_media_deletes_broken_attachment(test_app): user_a = fixture_add_user(u"chris_a") media = fixture_media_entry(uploader=user_a.id, save=False) -- cgit v1.2.3 From 7d503a897bddfadcd98d278bdb648503485a19de Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Sat, 6 Apr 2013 10:07:47 -0500 Subject: Really removing nosetests things now! all assert_whatever removed --- mediagoblin/tests/test_misc.py | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 7143938e..755d863f 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -14,8 +14,6 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . -from nose.tools import assert_equal - from mediagoblin.db.base import Session from mediagoblin.db.models import User, MediaEntry, MediaComment from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry @@ -23,7 +21,7 @@ from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry def test_404_for_non_existent(test_app): res = test_app.get('/does-not-exist/', expect_errors=True) - assert_equal(res.status_int, 404) + assert res.status_int == 404 def test_user_deletes_other_comments(test_app): @@ -58,11 +56,11 @@ def test_user_deletes_other_comments(test_app): cmt_cnt2 = MediaComment.query.count() # One user deleted - assert_equal(usr_cnt2, usr_cnt1 - 1) + assert usr_cnt2 == usr_cnt1 - 1 # One media gone - assert_equal(med_cnt2, med_cnt1 - 1) + assert med_cnt2 == med_cnt1 - 1 # Three of four comments gone. - assert_equal(cmt_cnt2, cmt_cnt1 - 3) + assert cmt_cnt2 == cmt_cnt1 - 3 User.query.get(user_b.id).delete() @@ -71,11 +69,11 @@ def test_user_deletes_other_comments(test_app): cmt_cnt2 = MediaComment.query.count() # All users gone - assert_equal(usr_cnt2, usr_cnt1 - 2) + assert usr_cnt2 == usr_cnt1 - 2 # All media gone - assert_equal(med_cnt2, med_cnt1 - 2) + assert med_cnt2 == med_cnt1 - 2 # All comments gone - assert_equal(cmt_cnt2, cmt_cnt1 - 4) + assert cmt_cnt2 == cmt_cnt1 - 4 def test_media_deletes_broken_attachment(test_app): -- cgit v1.2.3 From 0536306048daa0970d2e43411ba2a9bf073e570e Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Thu, 16 May 2013 17:51:21 -0500 Subject: Always activate testing in every test module ever. Kind of a dorky way to implement this, but... --- mediagoblin/tests/test_misc.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index 755d863f..a16ab61d 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -17,6 +17,9 @@ from mediagoblin.db.base import Session from mediagoblin.db.models import User, MediaEntry, MediaComment from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry +from mediagoblin.tools.testing import _activate_testing + +_activate_testing() def test_404_for_non_existent(test_app): -- cgit v1.2.3 From 9a9bafc078192317695a4f06233ea261fe147989 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Fri, 17 May 2013 11:12:56 -0500 Subject: Reverting "Always activate testing in every test module ever." Revert "Always activate testing in every test module ever." This reverts commit 0536306048daa0970d2e43411ba2a9bf073e570e. --- mediagoblin/tests/test_misc.py | 3 --- 1 file changed, 3 deletions(-) (limited to 'mediagoblin/tests/test_misc.py') diff --git a/mediagoblin/tests/test_misc.py b/mediagoblin/tests/test_misc.py index a16ab61d..755d863f 100644 --- a/mediagoblin/tests/test_misc.py +++ b/mediagoblin/tests/test_misc.py @@ -17,9 +17,6 @@ from mediagoblin.db.base import Session from mediagoblin.db.models import User, MediaEntry, MediaComment from mediagoblin.tests.tools import fixture_add_user, fixture_media_entry -from mediagoblin.tools.testing import _activate_testing - -_activate_testing() def test_404_for_non_existent(test_app): -- cgit v1.2.3