Skip to content

Commit

Permalink
Python3: test/unit/
Browse files Browse the repository at this point in the history
  • Loading branch information
nsoranzo committed Jun 29, 2016
1 parent 40f85f2 commit 9a97a29
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 129 deletions.
21 changes: 1 addition & 20 deletions .ci/py3_sources.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,26 +69,7 @@ scripts/cleanup_datasets/update_metadata.py
scripts/data_libraries/build_whoosh_index.py
scripts/db_shell.py
scripts/drmaa_external_runner.py
test/api/helpers.py
test/api/test_datasets.py
test/api/test_tool_data.py
test/api/test_workflow_extraction.py
test/api/test_workflows.py
test/api/test_workflows_from_yaml.py
test/base/
test/casperjs/
test/functional/
test/integration/
test/manual/
test/shed_functional/base/twilltestcase.py
test/shed_functional/functional_tests.py
test/unit/datatypes/dataproviders/test_base_dataproviders.py
test/unit/datatypes/dataproviders/test_line_dataproviders.py
test/unit/managers/base.py
test/unit/managers/test_DatasetManager.py
test/unit/test_galaxy_mapping.py
test/unit/tools/test_actions.py
test/unit/workflows/test_run_parameters.py
test/
tool_list.py
tools/data_source/
tools/evolution/
Expand Down
30 changes: 14 additions & 16 deletions test/unit/managers/test_HDAManager.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
# -*- coding: utf-8 -*-
import os
import imp
import os
import unittest

test_utils = imp.load_source( 'test_utils',
os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) )

import sqlalchemy
from six import string_types

from galaxy import model
from galaxy import exceptions

from base import BaseTestCase

from galaxy.managers.histories import HistoryManager
from galaxy.managers.datasets import DatasetManager
from galaxy import exceptions, model
from galaxy.managers import hdas
from galaxy.managers.datasets import DatasetManager
from galaxy.managers.histories import HistoryManager

from .base import BaseTestCase

# =============================================================================
default_password = '123456'
Expand Down Expand Up @@ -429,11 +427,11 @@ def test_serializers( self ):
self.assertIsInstance( serialized[ 'dataset' ], dict )
self.assertEncodedId( serialized[ 'dataset_id' ] )
self.assertUUID( serialized[ 'uuid' ] )
self.assertIsInstance( serialized[ 'file_name' ], basestring )
self.assertIsInstance( serialized[ 'extra_files_path' ], basestring )
self.assertIsInstance( serialized[ 'file_name' ], string_types )
self.assertIsInstance( serialized[ 'extra_files_path' ], string_types )
self.assertIsInstance( serialized[ 'size' ], int )
self.assertIsInstance( serialized[ 'file_size' ], int )
self.assertIsInstance( serialized[ 'nice_size' ], basestring )
self.assertIsInstance( serialized[ 'nice_size' ], string_types )
# TODO: these should be tested w/copy
self.assertNullableEncodedId( serialized[ 'copied_from_history_dataset_association_id'] )
self.assertNullableEncodedId( serialized[ 'copied_from_library_dataset_dataset_association_id'] )
Expand All @@ -443,8 +441,8 @@ def test_serializers( self ):
self.assertIsInstance( serialized[ 'meta_files' ], list )
self.assertNullableEncodedId( serialized[ 'parent_id'] )
self.assertEqual( serialized[ 'designation' ], None )
self.assertIsInstance( serialized[ 'genome_build' ], basestring )
self.assertIsInstance( serialized[ 'data_type' ], basestring )
self.assertIsInstance( serialized[ 'genome_build' ], string_types )
self.assertIsInstance( serialized[ 'data_type' ], string_types )

# hda
self.assertEncodedId( serialized[ 'history_id' ] )
Expand All @@ -469,9 +467,9 @@ def test_serializers( self ):
self.assertEqual( serialized[ 'api_type' ], 'file' )
self.assertEqual( serialized[ 'type' ], 'file' )

self.assertIsInstance( serialized[ 'url' ], basestring )
self.assertIsInstance( serialized[ 'url' ], string_types )
self.assertIsInstance( serialized[ 'urls' ], dict )
self.assertIsInstance( serialized[ 'download_url' ], basestring )
self.assertIsInstance( serialized[ 'download_url' ], string_types )

self.log( 'serialized should jsonify well' )
self.assertIsJsonifyable( serialized )
Expand Down Expand Up @@ -579,7 +577,7 @@ def test_deserialize_visible( self ):
def test_deserialize_genome_build( self ):
hda = self._create_vanilla_hda()

self.assertIsInstance( hda.dbkey, basestring )
self.assertIsInstance( hda.dbkey, string_types )
self.log( 'should deserialize to "?" from None' )
self.hda_deserializer.deserialize( hda, { 'genome_build': None } )
self.assertEqual( hda.dbkey, '?' )
Expand Down
8 changes: 4 additions & 4 deletions test/unit/managers/test_HDCAManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
test_utils = imp.load_source( 'test_utils',
os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) )

from base import BaseTestCase
from base import CreatesCollectionsMixin
from .base import BaseTestCase
from .base import CreatesCollectionsMixin

from galaxy.managers.histories import HistoryManager
from galaxy.managers.datasets import DatasetManager
Expand Down Expand Up @@ -72,7 +72,7 @@ def set_up_managers( self ):
def test_views( self ):
serializer = self.hdca_serializer
item = self._create_list_hdca([
dict( name=( "hda-{0}".format( i ) ), hid=i ) for i in xrange( 5 )
dict( name=( "hda-{0}".format( i ) ), hid=i ) for i in range( 5 )
])

self.log( 'should have a summary view' )
Expand All @@ -99,7 +99,7 @@ def test_views( self ):
def test_views_and_keys( self ):
serializer = self.hdca_serializer
item = self._create_list_hdca([
dict( name=( "hda-{0}".format( i ) ), hid=i ) for i in xrange( 5 )
dict( name=( "hda-{0}".format( i ) ), hid=i ) for i in range( 5 )
])
summary_plus_key = [ 'elements' ]
only_keys = [ 'id', 'populated_state_message' ]
Expand Down
53 changes: 24 additions & 29 deletions test/unit/managers/test_HistoryContentsManager.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
# -*- coding: utf-8 -*-
"""
"""
import os
import datetime
import imp
import unittest
import os
import random
import datetime
import unittest

test_utils = imp.load_source( 'test_utils',
os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) )

from sqlalchemy import true
from sqlalchemy import false
from sqlalchemy import desc
from sqlalchemy import column, desc, false, true
from sqlalchemy.sql import text
from sqlalchemy import column

from base import BaseTestCase
from base import CreatesCollectionsMixin

from galaxy.managers import collections, hdas, history_contents
from galaxy.managers.histories import HistoryManager
from galaxy.managers import hdas
from galaxy.managers import collections
from galaxy.managers import history_contents

from .base import BaseTestCase
from .base import CreatesCollectionsMixin

default_password = '123456'
user2_data = dict( email='[email protected]', username='user2', password=default_password )
Expand Down Expand Up @@ -62,10 +57,10 @@ def test_contents( self ):
self.assertEqual( [], list( self.contents_manager.contents( history ) ) )

self.log( "calling contents on an history with hdas should return those in order of their hids" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ]
random.shuffle( hdas )
ordered_hda_contents = list( self.contents_manager.contents( history ) )
self.assertEqual( map( lambda hda: hda.hid, ordered_hda_contents ), [ 1, 2, 3 ] )
self.assertEqual( [hda.hid for hda in ordered_hda_contents], [ 1, 2, 3 ] )

self.log( "calling contents on an history with both hdas and collections should return both" )
hdca = self.add_list_collection_to_history( history, hdas )
Expand All @@ -80,7 +75,7 @@ def test_contained( self ):
self.assertEqual( [], list( self.contents_manager.contained( history ) ) )

self.log( "calling contained on an history with both hdas and collections should return only hdas" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ]
self.add_list_collection_to_history( history, hdas )
self.assertEqual( list( self.contents_manager.contained( history ) ), hdas )

Expand All @@ -92,7 +87,7 @@ def test_subcontainers( self ):
self.assertEqual( [], list( self.contents_manager.subcontainers( history ) ) )

self.log( "calling subcontainers on an history with both hdas and collections should return only collections" )
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ]
hdas = [ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ]
hdca = self.add_list_collection_to_history( history, hdas )
subcontainers = list( self.contents_manager.subcontainers( history ) )
self.assertEqual( subcontainers, [ hdca ] )
Expand All @@ -101,9 +96,9 @@ def test_limit_and_offset( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

# _subquery = self.contents_manager._contents_common_query( self.contents_manager.subcontainer_class, history.id )
Expand All @@ -130,9 +125,9 @@ def test_orm_filtering( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

self.log( "should allow filter on deleted" )
Expand Down Expand Up @@ -207,9 +202,9 @@ def test_order_by( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

self.log( "should default to hid order_by" )
Expand Down Expand Up @@ -240,9 +235,9 @@ def test_update_time_filter( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

self.log( "should allow filtering by update_time" )
Expand All @@ -264,9 +259,9 @@ def test_filtered_counting( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

self.log( "should show correct count with filters" )
Expand All @@ -292,9 +287,9 @@ def test_type_id( self ):
user2 = self.user_manager.create( **user2_data )
history = self.history_manager.create( name='history', user=user2 )
contents = []
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 3 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 3 ) ])
contents.append( self.add_list_collection_to_history( history, contents[:3] ) )
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in xrange( 4, 6 ) ])
contents.extend([ self.add_hda_to_history( history, name=( 'hda-' + str( x ) ) ) for x in range( 4, 6 ) ])
contents.append( self.add_list_collection_to_history( history, contents[4:6] ) )

self.log( "should be able to use eq and in with hybrid type_id" )
Expand Down
24 changes: 10 additions & 14 deletions test/unit/managers/test_HistoryManager.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@
# -*- coding: utf-8 -*-
"""
"""
import os
import imp
import os
import unittest

test_utils = imp.load_source( 'test_utils',
os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) )
import galaxy_mock

import sqlalchemy
from six import string_types
from sqlalchemy import true

from galaxy import model
from galaxy import exceptions

from base import BaseTestCase
from galaxy import exceptions, model
from galaxy.managers import base, hdas
from galaxy.managers.histories import (HistoryDeserializer, HistoryFilters,
HistoryManager, HistorySerializer)

from galaxy.managers import base
from galaxy.managers.histories import HistoryManager
from galaxy.managers.histories import HistorySerializer
from galaxy.managers.histories import HistoryDeserializer
from galaxy.managers.histories import HistoryFilters
from galaxy.managers import hdas
from .base import BaseTestCase

default_password = '123456'
user2_data = dict( email='[email protected]', username='user2', password=default_password )
Expand Down Expand Up @@ -260,7 +256,7 @@ def test_sharable( self ):
len( self.history_manager.get_share_assocs( item1 ) ), 1 )
self.assertEqual(
len( self.history_manager.get_share_assocs( item1, user=non_owner ) ), 1 )
self.assertIsInstance( item1.slug, basestring )
self.assertIsInstance( item1.slug, string_types )

self.log( "should be able to unshare with specific users" )
share_assoc = self.history_manager.unshare_with( item1, non_owner )
Expand Down Expand Up @@ -491,7 +487,7 @@ def test_history_serializers( self ):

self.log( 'everything serialized should be of the proper type' )
self.assertIsInstance( serialized[ 'size' ], int )
self.assertIsInstance( serialized[ 'nice_size' ], basestring )
self.assertIsInstance( serialized[ 'nice_size' ], string_types )

self.log( 'serialized should jsonify well' )
self.assertIsJsonifyable( serialized )
Expand Down Expand Up @@ -560,7 +556,7 @@ def test_contents( self ):
self.assertEqual( serialized[ 'state_details' ][ 'ok' ], 1 )
self.assertIsInstance( serialized[ 'state_ids' ][ 'ok' ], list )
self.assertIsInstance( serialized[ 'hdas' ], list )
self.assertIsInstance( serialized[ 'hdas' ][0], basestring )
self.assertIsInstance( serialized[ 'hdas' ][0], string_types )

serialized = self.history_serializer.serialize( history1, [ 'contents' ] )
self.assertHasKeys( serialized[ 'contents' ][0], [ 'id', 'name', 'peek', 'create_time' ])
Expand Down
17 changes: 8 additions & 9 deletions test/unit/managers/test_UserManager.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
# -*- coding: utf-8 -*-
"""
"""
import os
import imp
import os
import unittest

test_utils = imp.load_source( 'test_utils',
os.path.join( os.path.dirname( __file__), '../unittest_utils/utility.py' ) )

import sqlalchemy
from six import string_types

from galaxy import model
from galaxy import exceptions
from galaxy import exceptions, model
from galaxy.managers import histories, users

from base import BaseTestCase
from galaxy.managers import users
from galaxy.managers import histories
from .base import BaseTestCase


# =============================================================================
Expand Down Expand Up @@ -114,7 +113,7 @@ def test_api_keys( self ):

self.log( "should be able to generate and retrieve valid api key" )
user2_api_key = self.user_manager.create_api_key( user2 )
self.assertIsInstance( user2_api_key, basestring )
self.assertIsInstance( user2_api_key, string_types )
self.assertEqual( self.user_manager.valid_api_key( user2 ).key, user2_api_key )

self.log( "should return the most recent (i.e. most valid) api key" )
Expand Down Expand Up @@ -179,7 +178,7 @@ def test_serializers( self ):
# self.assertIsInstance( serialized[ 'active' ], bool )
self.assertIsInstance( serialized[ 'is_admin' ], bool )
self.assertIsInstance( serialized[ 'total_disk_usage' ], float )
self.assertIsInstance( serialized[ 'nice_total_disk_usage' ], basestring )
self.assertIsInstance( serialized[ 'nice_total_disk_usage' ], string_types )
self.assertIsInstance( serialized[ 'quota_percent' ], ( type( None ), float ) )
self.assertIsInstance( serialized[ 'tags_used' ], list )
self.assertIsInstance( serialized[ 'has_requests' ], bool )
Expand Down Expand Up @@ -209,7 +208,7 @@ def test_anonymous( self ):
self.assertEqual( serialized[ 'id' ], None )
self.log( 'everything serialized should be of the proper type' )
self.assertIsInstance( serialized[ 'total_disk_usage' ], float )
self.assertIsInstance( serialized[ 'nice_total_disk_usage' ], basestring )
self.assertIsInstance( serialized[ 'nice_total_disk_usage' ], string_types )
self.assertIsInstance( serialized[ 'quota_percent' ], ( type( None ), float ) )

self.log( 'serialized should jsonify well' )
Expand Down
Loading

0 comments on commit 9a97a29

Please sign in to comment.