Ticket #795: 0002-Add-test-to-check-that-an-activity-is-created-when-a.patch

File 0002-Add-test-to-check-that-an-activity-is-created-when-a.patch, 2.5 KB (added by tofay, 9 years ago)
  • mediagoblin/tests/test_submission.py

    From 19ef92f84585198ee67cdcf9b37973b767409feb Mon Sep 17 00:00:00 2001
    From: tom <tom@teamfay.co.uk>
    Date: Sat, 12 Dec 2015 11:29:27 +0000
    Subject: [PATCH 2/2] Add test to check that an activity is created when a
     collection was chosen.
    
    ---
     mediagoblin/tests/test_submission.py | 15 +++++++++++----
     1 file changed, 11 insertions(+), 4 deletions(-)
    
    diff --git a/mediagoblin/tests/test_submission.py b/mediagoblin/tests/test_submission.py
    index eed7afa..0ec49ec 100644
    a b Gst.init(None)  
    3636from mediagoblin.tests.tools import fixture_add_user, fixture_add_collection
    3737from .media_tools import create_av
    3838from mediagoblin import mg_globals
    39 from mediagoblin.db.models import MediaEntry, User, LocalUser
     39from mediagoblin.db.models import MediaEntry, User, LocalUser, Activity
    4040from mediagoblin.db.base import Session
    4141from mediagoblin.tools import template
    4242from mediagoblin.media_types.image import ImageMediaManager
    class TestSubmission:  
    426426    def test_collection_selection(self):
    427427        """Test the ability to choose a collection when submitting media
    428428        """
    429         # Collection option shouldn't be present if the user has no collections
     429        # Collection option should have been removed if the user has no
     430        # collections.
    430431        response = self.test_app.get('/submit/')
    431432        assert 'collection' not in response.form.fields
    432433
     434        # Test upload of an image when a user has no collections.
    433435        upload = webtest.forms.Upload(os.path.join(
    434436            'mediagoblin', 'static', 'images', 'media_thumbs', 'image.png'))
    435 
    436         # Check that upload of an image when a user has no collections
    437437        response.form['file'] = upload
    438438        no_collection_title = 'no collection'
    439439        response.form['title'] = no_collection_title
    class TestSubmission:  
    466466        col = self.our_user().collections[0]
    467467        assert col.collection_items[0].get_object().title == title
    468468
     469        # Test that an activity was created when the item was added to the
     470        # collection. That should be the last activity.
     471        assert Activity.query.order_by(
     472            Activity.id.desc()
     473        ).first().content == '{0} added new picture to {1}'.format(
     474            self.our_user().username, col.title)
     475
    469476        # Test upload succeeds if the user has collection and no collection is
    470477        # chosen.
    471478        form['file'] = webtest.forms.Upload(os.path.join(