Example #1
0
    def setUp(self):
        """
        Switch to test config.
        Create initial files set in the Upload Dir.
        Create initial records in the 'files' table.
        Remember challenge seed and response.
        Remember initial blacklist content.
        """
        self.app = storj.app
        self.app.config['TESTING'] = True

        self.file_data = b'existing file data'
        self.data_hash = sha256(self.file_data).hexdigest()
        valid_signature = test_btctx_api.sign_unicode(test_owner_wif,
                                                      self.data_hash)

        self.blocked_data = b'blocked_data'
        self.blocked_hash = sha256(self.blocked_data).hexdigest()
        with open(self.app.config['BLACKLIST_FILE'], 'r+') as fp:
            self.initial_blacklist = fp.read()
            fp.writelines((self.blocked_hash + '\n',))

        self.file_saving_path = os.path.join(
            self.app.config['UPLOAD_FOLDER'], self.data_hash
        )

        with open(self.file_saving_path, 'wb') as stored_file:
            stored_file.write(self.file_data)

        self.owner = test_owner_address

        self.files_id = files.insert().values(
            hash=self.data_hash, role='000', size=len(self.file_data),
            owner=self.owner
        ).execute().inserted_primary_key

        audit.delete().execute()

        self.challenge_seed = sha256(b'seed').hexdigest()
        self.challenge_response = sha256(
            self.file_data + self.challenge_seed.encode()
        ).hexdigest()

        self.send_data = {
            'data_hash': self.data_hash,
            'challenge_seed': self.challenge_seed
        }

        self.headers = {
            'sender_address': self.owner,
            'signature': valid_signature
        }

        self.other = test_other_address
        self.other_signature = test_btctx_api.sign_unicode(test_other_wfi,
                                                           self.data_hash)

        self.patcher = patch('metacore.processor.BTCTX_API', test_btctx_api)
        self.patcher.start()
Example #2
0
    def tearDown(self):
        """
        Switch off some test configs.
        Remove initial files from Upload Dir.
        Remove initial records form the 'files' table.
        Return initial blacklist content.
        """
        self.patcher.stop()

        try:
            os.unlink(self.file_saving_path)
        except OSError:
            pass

        files.delete().where(files.c.hash.in_(self.files_id)).execute()
        audit.delete().execute()

        with open(self.app.config['BLACKLIST_FILE'], 'w') as fp:
            fp.write(self.initial_blacklist)