2013-07-10 20:25:57 +00:00
|
|
|
import collections
|
2019-01-09 22:59:03 +00:00
|
|
|
from . import HydrusConstants as HC
|
|
|
|
from . import ClientData
|
2013-07-10 20:25:57 +00:00
|
|
|
import os
|
2019-01-09 22:59:03 +00:00
|
|
|
from . import TestConstants
|
2013-07-10 20:25:57 +00:00
|
|
|
import unittest
|
2019-01-09 22:59:03 +00:00
|
|
|
from . import HydrusData
|
|
|
|
from . import ClientConstants as CC
|
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
|
|
|
|
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-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
|
|
|
|
2014-08-27 22:15:22 +00:00
|
|
|
service_keys_to_tags = { 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
|
|
|
|
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-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
|
|
|
|