__author__ = 'tonycastronova'

from unittest import TestCase

from django.contrib.auth.models import User, Group

from hs_core.models import GenericResource
from hs_core.hydroshare import resource
from hs_core.hydroshare import users

# iRODS mocking has not been used here as we want test bag creation


class TestGetResource(TestCase):
    def setUp(self):
        self.hydroshare_author_group, _ = Group.objects.get_or_create(name='Hydroshare Author')
        # create a user
        self.user = users.create_account(
            'test_user@email.com',
            username='sometestuser',
            first_name='some_first_name',
            last_name='some_last_name',
            superuser=False,
            groups=[])

        self.res = resource.create_resource(
            'GenericResource',
            self.user,
            'My Test Resource'
            )

    def tearDown(self):
        User.objects.all().delete()
        Group.objects.all().delete()
        GenericResource.objects.all().delete()

    def test_get_resource(self):
        # function to test: hydroshare.get_resource() which returns a Bags object (not the actual bag file)
        # TODO: Don't see any useful way of using the hydroshare.get_resource() function
        # One can't do much with a Bags object. For downloading a bag we are using resource.bag_url.
        # So it is better that we delete the get_resource() function and remove this test
        
        res_bag = resource.get_resource(self.res.short_id)
        self.assertTrue(res_bag is not None)

@@ -53,16 +53,39 @@
 TestCase
+%0Afrom mock import patch
 %0A%0Afrom d
@@ -301,16 +301,19 @@
 we want 
+to 
 test bag
@@ -370,32 +370,135 @@
 ef setUp(self):%0A
+        # stop mocking of iRODS interaction in case those patchers are active%0A        patch.stopall()%0A%0A
         self.hyd

stop mocked iRODS patchers for test_get_resource