aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorElrond <elrond+mediagoblin.org@samba-tng.org>2013-01-18 11:42:56 +0100
committerElrond <elrond+mediagoblin.org@samba-tng.org>2013-01-18 11:42:56 +0100
commitcd75b2280fc2fe953bf1158ec1b9d5fb0d43a881 (patch)
tree1035787839344665135fee320bc62858a0ec8c6d
parent1be247b36e58c8c71a974b65dff7194f28483f12 (diff)
downloadmediagoblin-cd75b2280fc2fe953bf1158ec1b9d5fb0d43a881.tar.lz
mediagoblin-cd75b2280fc2fe953bf1158ec1b9d5fb0d43a881.tar.xz
mediagoblin-cd75b2280fc2fe953bf1158ec1b9d5fb0d43a881.zip
Add some simple collection test.
-rw-r--r--mediagoblin/tests/test_collections.py37
-rw-r--r--mediagoblin/tests/tools.py23
2 files changed, 59 insertions, 1 deletions
diff --git a/mediagoblin/tests/test_collections.py b/mediagoblin/tests/test_collections.py
new file mode 100644
index 00000000..b19f6362
--- /dev/null
+++ b/mediagoblin/tests/test_collections.py
@@ -0,0 +1,37 @@
+# GNU MediaGoblin -- federated, autonomous media hosting
+# Copyright (C) 2013 MediaGoblin contributors. See AUTHORS.
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+from mediagoblin.tests.tools import fixture_add_collection, fixture_add_user, \
+ get_app
+from mediagoblin.db.models import Collection, User
+from mediagoblin.db.base import Session
+from nose.tools import assert_equal
+
+
+def test_user_deletes_collection():
+ # Setup db.
+ get_app(dump_old_app=False)
+
+ user = fixture_add_user()
+ coll = fixture_add_collection(user=user)
+ # Reload into session:
+ user = User.query.get(user.id)
+
+ cnt1 = Collection.query.count()
+ user.delete()
+ cnt2 = Collection.query.count()
+
+ assert_equal(cnt1, cnt2 + 1)
diff --git a/mediagoblin/tests/tools.py b/mediagoblin/tests/tools.py
index 30218ede..18d4ec0c 100644
--- a/mediagoblin/tests/tools.py
+++ b/mediagoblin/tests/tools.py
@@ -25,7 +25,7 @@ from paste.deploy import loadapp
from webtest import TestApp
from mediagoblin import mg_globals
-from mediagoblin.db.models import User
+from mediagoblin.db.models import User, Collection
from mediagoblin.tools import testing
from mediagoblin.init.config import read_mediagoblin_config
from mediagoblin.db.open import setup_connection_and_db_from_config
@@ -226,3 +226,24 @@ def fixture_add_user(username=u'chris', password=u'toast',
Session.expunge(test_user)
return test_user
+
+
+def fixture_add_collection(name=u"My first Collection", user=None):
+ if user is None:
+ user = fixture_add_user()
+ coll = Collection.query.filter_by(creator=user.id, title=name).first()
+ if coll is not None:
+ return coll
+ coll = Collection()
+ coll.creator = user.id
+ coll.title = name
+ coll.generate_slug()
+ coll.save()
+
+ # Reload
+ Session.refresh(coll)
+
+ # ... and detach from session:
+ Session.expunge(coll)
+
+ return coll