def test_fail_no_remote(self):
     lang = Translations()
     lib = TargetSearch(lang, InfoRam(lang), DataRam(lang))
     try:
         lib.process()
         assert False, 'No remote and passed'
     except UploadException as ex:
         assert 'SENT FILE NAME IS EMPTY' == ex.get_message()
 def test_fail_no_base(self):
     lang = Translations()
     lib = TargetSearch(lang, InfoRam(lang), DataRam(lang))
     try:
         lib.get_final_target_name()
         assert False, 'No final target name and passed'
     except UploadException as ex:
         assert 'UPLOAD FILE NAME IS EMPTY' == ex.get_message()
예제 #3
0
    def test_redis(self):
        import hashlib
        lang = Translations()
        target = TargetSearch(lang, InfoRam(lang), DataRam(lang))
        target.set_remote_file_name('poiuztrewq').set_target_dir(self._get_test_dir()).process()
        lib = Redis(lang, target)
        lib.generate_keys()

        key1 = 'poiuztrewq'
        key2 = '/tmp/lkjhg'
        assert hashlib.md5(key1.encode("utf-8")).hexdigest() == lib.get_shared_key()
        assert Redis.PREFIX + key2 == lib.from_shared_key(key2)
예제 #4
0
    def test_volume(self):
        import base64
        lang = Translations()
        target = TargetSearch(lang, InfoRam(lang), DataRam(lang))
        target.set_remote_file_name('poiuztrewq').set_target_dir('/tmp/').process()
        lib = SimpleVolume(lang, target)
        lib.generate_keys()

        key1 = '/tmp/poiuztrewq' + TargetSearch.FILE_DRIVER_SUFF
        key2 = '/tmp/lkjhg'
        assert base64.encodebytes(key1.encode("utf-8")).decode("utf-8").strip() == lib.get_shared_key()
        assert key2 == lib.from_shared_key(base64.encodebytes(key2.encode("utf-8")).decode("utf-8").strip())
        try:
            lib.from_shared_key('**' + key2)  # aaand failed... - chars outside the b64
            assert False, 'Decode some unknown chars'
        except UploadException as ex:
            assert 'SHARED KEY IS INVALID' == ex.get_message()
예제 #5
0
 def test_shared_fail(self):
     lang = Translations()
     lib = Random(lang, TargetSearch(lang, InfoRam(lang), DataRam(lang)))
     try:
         lib.get_shared_key()  # no key set!
         assert False, 'Got empty shared key'
     except UploadException as ex:
         assert 'SHARED KEY IS EMPTY' == ex.get_message()
예제 #6
0
 def test_init_fail(self):
     lang = Translations()
     target = TargetSearch(lang, InfoRam(lang), DataRam(lang))
     try:
         Factory.get_variant(lang, target, 0)
         assert False, 'Use unknown variant'
     except UploadException as ex:
         assert 'KEY VARIANT NOT SET' == ex.get_message()
 def test_process_name_lookup(self):
     lang = Translations()
     data_ram = DataRam(lang)
     data_ram.add_part(self._get_test_dir() + 'dummyFile.tst',
                       'asdfghjklqwertzuiopyxcvbnm')
     data_ram.add_part(self._get_test_dir() + 'dummyFile.0.tst',
                       'asdfghjklqwertzuiopyxcvbnm')
     data_ram.add_part(self._get_test_dir() + 'dummyFile.1.tst',
                       'asdfghjklqwertzuiopyxcvbnm')
     data_ram.add_part(self._get_test_dir() + 'dummyFile.2.tst',
                       'asdfghjklqwertzuiopyxcvbnm')
     lib = TargetSearch(lang, InfoRam(lang), data_ram, False, False)
     lib.set_target_dir(self._get_test_dir()).set_remote_file_name(
         'dummyFile.tst').process()
     assert self._get_test_dir(
     ) + 'dummyFile.3.tst' + TargetSearch.FILE_UPLOAD_SUFF == lib.get_temporary_target_location(
     )
예제 #8
0
 def __init__(self, methodName='runTest'):
     super().__init__(methodName)
     _lang = Translations()
     self._info_storage = InfoRam(_lang)
     self._data_storage = DataRam(_lang)
     target = TargetSearch(_lang, self._info_storage, self._data_storage)
     self._drive_file = DriveFile(_lang, self._info_storage, Json(),
                                  Key(_lang, target))
     self._processor = Processor(_lang, self._drive_file,
                                 self._data_storage, Hashed())
 def test_process_no_clear(self):
     lang = Translations()
     lib = TargetSearch(lang, InfoRam(lang), DataRam(lang), False, False)
     lib.set_target_dir(self._get_test_dir()).set_remote_file_name(
         'what el$e can be found').process()
     assert 'what el$e can be found' == lib.get_final_target_name()
     assert self._get_test_dir(
     ) + 'what el$e can be found' + TargetSearch.FILE_DRIVER_SUFF == lib.get_driver_location(
     )
     assert self._get_test_dir(
     ) + 'what el$e can be found' + TargetSearch.FILE_UPLOAD_SUFF == lib.get_temporary_target_location(
     )
 def test_fail_no_target(self):
     lang = Translations()
     lib = TargetSearch(lang, InfoRam(lang), DataRam(lang))
     lib.set_remote_file_name('abcdefg')
     try:
         lib.process()
         assert False, 'No target and passed'
     except UploadException as ex:
         assert 'TARGET DIR IS NOT SET' == ex.get_message()
예제 #11
0
 def _get_drive_file(self) -> DriveFile:
     lang = Translations()
     storage = InfoRam(lang)
     target = TargetSearch(lang, storage, DataRam(lang))
     return DriveFile(lang, storage, Json(), Key(lang, target))
예제 #12
0
    def test_random(self):
        assert 'aaaaaaa' == Random.generate_random_text(7, ['a','a','a','a'])

        lang = Translations()
        lib = Random(lang, TargetSearch(lang, InfoRam(lang), DataRam(lang)))
        assert 'abcdefghi' + TargetSearch.FILE_DRIVER_SUFF == lib.from_shared_key('abcdefghi')
예제 #13
0
 def test_init(self):
     lang = Translations()
     target = TargetSearch(lang, InfoRam(lang), DataRam(lang))
     assert isinstance(Factory.get_variant(lang, target, Factory.VARIANT_VOLUME), SimpleVolume)
     assert isinstance(Factory.get_variant(lang, target, Factory.VARIANT_RANDOM), Random)
     assert isinstance(Factory.get_variant(lang, target, Factory.VARIANT_REDIS), Redis)