Ejemplo n.º 1
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()
Ejemplo n.º 2
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()
 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()
 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_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()
Ejemplo n.º 6
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())
Ejemplo n.º 7
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)
 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(
     )
Ejemplo n.º 9
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()
 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(
     )
Ejemplo n.º 11
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')
Ejemplo n.º 12
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)
 def test_init_fail(self):
     try:
         Factory.get_format(Translations(), 0)  # fail
         assert False, 'Accessing unreadable!'
     except UploadException as ex:
         assert 'DRIVEFILE VARIANT NOT SET' == ex.get_message()
 def _mock_storage(self) -> DataStorage:
     return VolumeBasic(Translations())
 def tearDown(self):
     if Files.is_file(self._mock_test_file()):
         lib = Volume(Translations())
         lib.remove(self._mock_test_file())
     super().tearDown()
 def _mock_storage(self) -> InfoStorage:
     return Volume(Translations())
Ejemplo n.º 17
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))
 def test_init(self):
     lang = Translations()
     assert isinstance(Factory.get_format(lang, Factory.FORMAT_TEXT), Text)
     assert isinstance(Factory.get_format(lang, Factory.FORMAT_JSON), Json)