hydrus/hydrus/test/TestFunctions.py

56 lines
2.7 KiB
Python
Raw Normal View History

2020-07-29 20:52:44 +00:00
import unittest
2020-04-22 21:00:35 +00:00
from hydrus.core import HydrusConstants as HC
2020-07-29 20:52:44 +00:00
from hydrus.core import HydrusData
2020-04-22 21:00:35 +00:00
from hydrus.core import HydrusGlobals as HG
2020-07-29 20:52:44 +00:00
from hydrus.client import ClientConstants as CC
2020-04-22 21:00:35 +00:00
from hydrus.client import ClientData
from hydrus.client.metadata import ClientTags
2013-07-10 20:25:57 +00:00
2017-09-06 20:18:20 +00:00
class TestFunctions( 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
2015-10-07 21:56:22 +00:00
hashes = { hash }
2013-07-10 20:25:57 +00:00
2019-09-18 22:40:39 +00:00
local_key = CC.DEFAULT_LOCAL_TAG_SERVICE_KEY
remote_key = HG.test_controller.example_tag_repo_service_key
2013-07-10 20:25:57 +00:00
2019-02-27 23:03:30 +00:00
service_keys_to_tags = ClientTags.ServiceKeysToTags( { local_key : { 'a' } } )
2013-07-10 20:25:57 +00:00
2015-10-14 21:02:25 +00:00
content_updates = { local_key : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ) ] }
2013-07-10 20:25:57 +00:00
2015-10-07 21:56:22 +00:00
self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( { hash }, service_keys_to_tags ), content_updates )
2013-07-10 20:25:57 +00:00
2019-02-27 23:03:30 +00:00
service_keys_to_tags = ClientTags.ServiceKeysToTags( { remote_key : { 'c' } } )
2013-07-10 20:25:57 +00:00
2015-10-14 21:02:25 +00:00
content_updates = { remote_key : [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ) ] }
2013-07-10 20:25:57 +00:00
2015-10-07 21:56:22 +00:00
self.assertEqual( ClientData.ConvertServiceKeysToTagsToServiceKeysToContentUpdates( { hash }, service_keys_to_tags ), content_updates )
2013-07-10 20:25:57 +00:00
2019-02-27 23:03:30 +00:00
service_keys_to_tags = ClientTags.ServiceKeysToTags( { local_key : [ 'a', 'character:b' ], remote_key : [ 'c', 'series:d' ] } )
2013-07-10 20:25:57 +00:00
content_updates = {}
2015-10-14 21:02:25 +00:00
content_updates[ local_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'a', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_ADD, ( 'character:b', hashes ) ) ]
content_updates[ remote_key ] = [ HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'c', hashes ) ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, ( 'series:d', hashes ) ) ]
2013-07-10 20:25:57 +00:00
2015-10-14 21:02:25 +00:00
self.assertEqual( HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ), HydrusData.ContentUpdate( HC.CONTENT_TYPE_MAPPINGS, HC.CONTENT_UPDATE_PEND, 'c' ) )
2015-10-07 21:56:22 +00:00
self.assertEqual( ClientData.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
2018-07-04 20:48:28 +00:00
i_pretty = HydrusData.ToHumanInt( 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' )
2015-12-16 22:41:06 +00:00