hydrus/include/TestFunctions.py

71 lines
3.1 KiB
Python
Raw Normal View History

2013-07-10 20:25:57 +00:00
import collections
import HydrusConstants as HC
2015-03-25 22:04:19 +00:00
import ClientDownloading
2013-07-10 20:25:57 +00:00
import os
import TestConstants
import unittest
2015-03-25 22:04:19 +00:00
import HydrusData
2015-06-03 21:05:13 +00:00
import ClientConstants as CC
2013-07-10 20:25:57 +00:00
2015-03-25 22:04:19 +00:00
class TestClientDownloadingFunctions( unittest.TestCase ):
2013-07-10 20:25:57 +00:00
def test_dict_to_content_updates( self ):
2015-07-01 22:02:07 +00:00
hash = HydrusData.GenerateKey()
2013-07-10 20:25:57 +00:00
hashes = set( [ hash ] )
2015-06-03 21:05:13 +00:00
local_key = CC.LOCAL_TAG_SERVICE_KEY
2015-07-01 22:02:07 +00:00
remote_key = HydrusData.GenerateKey()
2013-07-10 20:25:57 +00:00
2014-08-27 22:15:22 +00:00
service_keys_to_tags = { local_key : { 'a' } }
2013-07-10 20:25:57 +00:00
2015-03-25 22:04:19 +00:00
content_updates = { local_key : [ HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ) ] }
2013-07-10 20:25:57 +00:00
2015-03-25 22:04:19 +00:00
self.assertEqual( ClientDownloading.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( hash, service_keys_to_tags ), content_updates )
2013-07-10 20:25:57 +00:00
2014-08-27 22:15:22 +00:00
service_keys_to_tags = { remote_key : { 'c' } }
2013-07-10 20:25:57 +00:00
2015-09-23 21:21:02 +00:00
content_updates = { remote_key : [ HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ) ] }
2013-07-10 20:25:57 +00:00
2015-03-25 22:04:19 +00:00
self.assertEqual( ClientDownloading.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( hash, service_keys_to_tags ), content_updates )
2013-07-10 20:25:57 +00:00
2014-08-27 22:15:22 +00:00
service_keys_to_tags = { local_key : [ 'a', 'character:b' ], remote_key : [ 'c', 'series:d' ] }
2013-07-10 20:25:57 +00:00
content_updates = {}
2015-03-25 22:04:19 +00:00
content_updates[ local_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'character:b', hashes ) ) ]
2015-09-23 21:21:02 +00:00
content_updates[ remote_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'series:d', hashes ) ) ]
2013-07-10 20:25:57 +00:00
2015-09-23 21:21:02 +00:00
self.assertEqual( HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ), HydrusData.ContentUpdate( HC.CONTENT_DATA_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ) )
2015-03-25 22:04:19 +00:00
self.assertEqual( ClientDownloading.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( hash, service_keys_to_tags ), content_updates )
2013-07-10 20:25:57 +00:00
2014-07-30 21:18:17 +00:00
def test_number_conversion( self ):
i = 123456789
2015-03-25 22:04:19 +00:00
i_pretty = HydrusData.ConvertIntToPrettyString( i )
2014-07-30 21:18:17 +00:00
# this test only works on anglo computers; it is mostly so I can check it is working on mine
self.assertEqual( i_pretty, '123,456,789' )
2013-07-10 20:25:57 +00:00
def test_tags_to_dict( self ):
2015-07-01 22:02:07 +00:00
local_key = HydrusData.GenerateKey()
remote_key = HydrusData.GenerateKey()
2013-07-10 20:25:57 +00:00
advanced_tag_options = {}
2014-08-27 22:15:22 +00:00
advanced_tag_options[ local_key ] = [ '', 'character' ]
advanced_tag_options[ remote_key ] = [ '', 'character' ]
2013-07-10 20:25:57 +00:00
tags = [ 'a', 'character:b', 'series:c' ]
2014-08-27 22:15:22 +00:00
service_keys_to_tags = { local_key : { 'a', 'character:b' }, remote_key : { 'a', 'character:b' } }
2013-07-10 20:25:57 +00:00
2015-03-25 22:04:19 +00:00
self.assertEqual( ClientDownloading.ConvertTagsToServiceKeysToTags( tags, advanced_tag_options ), service_keys_to_tags )
2013-07-10 20:25:57 +00:00