Ejemplo n.º 1
0
    def test_builds_zero_metrics_when_files_is_None(self):
        self.mock_sia_api.get_renter_contracts.return_value = {
            u'message': u'dummy get_renter_contracts error'
        }
        # 'files' is set to None when there are zero files.
        self.mock_sia_api.get_renter_files.return_value = {u'files': None}
        self.mock_sia_api.get_wallet.return_value = {
            u'message': u'dummy get_wallet error'
        }

        self.assertSiaStateEqual(
            state.SiaState(timestamp=_DUMMY_END_TIMESTAMP,
                           contract_count=None,
                           file_count=0,
                           total_file_bytes=0,
                           total_contract_size=None,
                           uploads_in_progress_count=0,
                           uploaded_bytes=0,
                           total_contract_spending=None,
                           contract_fee_spending=None,
                           upload_spending=None,
                           download_spending=None,
                           remaining_renter_funds=None,
                           storage_spending=None,
                           wallet_siacoin_balance=None,
                           api_latency=207.0), self.builder.build())
Ejemplo n.º 2
0
    def test_builds_empty_state_when_all_api_calls_raise_exceptions(self):
        self.mock_sia_api.get_renter_contracts.side_effect = ValueError(
            'dummy get_renter_contracts exception')
        self.mock_sia_api.get_renter_files.side_effect = ValueError(
            'dummy get_renter_files exception')
        self.mock_sia_api.get_wallet.side_effect = ValueError(
            'dummy get_wallet exception')

        self.assertSiaStateEqual(
            state.SiaState(timestamp=_DUMMY_END_TIMESTAMP, api_latency=207.0),
            self.builder.build())
Ejemplo n.º 3
0
    def test_builds_empty_state_when_all_api_calls_return_errors(self):
        self.mock_sia_api.get_renter_contracts.return_value = {
            u'message': u'dummy get_renter_contracts error'
        }
        self.mock_sia_api.get_renter_files.return_value = {
            u'message': u'dummy get_renter_files error'
        }
        self.mock_sia_api.get_wallet.return_value = {
            u'message': u'dummy get_wallet error'
        }

        self.assertSiaStateEqual(
            state.SiaState(timestamp=_DUMMY_END_TIMESTAMP, api_latency=207.0),
            self.builder.build())
Ejemplo n.º 4
0
    def test_writes_state_to_file(self):
        mock_file = io.BytesIO()

        serializer = serialize.CsvSerializer(mock_file)
        serializer.write_state(
            state.SiaState(timestamp=datetime.datetime(2018, 2, 11, 16, 5, 2),
                           contract_count=5,
                           file_count=3,
                           uploads_in_progress_count=2,
                           total_contract_size=9,
                           total_file_bytes=4444,
                           uploaded_bytes=900,
                           total_contract_spending=65,
                           contract_fee_spending=25,
                           storage_spending=2,
                           upload_spending=35,
                           download_spending=0,
                           remaining_renter_funds=100,
                           wallet_siacoin_balance=75,
                           wallet_outgoing_siacoins=26,
                           wallet_incoming_siacoins=83,
                           api_latency=5.0))

        self.assertEqual((
            'timestamp,'
            'contract_count,'
            'file_count,'
            'uploads_in_progress_count,'
            'total_contract_size,'
            'total_file_bytes,'
            'uploaded_bytes,'
            'total_contract_spending,'
            'contract_fee_spending,'
            'storage_spending,'
            'upload_spending,'
            'download_spending,'
            'remaining_renter_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'api_latency\n'
            '2018-02-11T16:05:02,5,3,2,9,4444,900,65,25,2,35,0,100,75,26,83,5.0\n'
        ), mock_file.getvalue())
Ejemplo n.º 5
0
    def test_builds_full_state_when_all_api_calls_return_successfully(self):
        self.mock_sia_api.get_renter_contracts.return_value = {
            u'activecontracts': [
                {
                    u'totalcost': u'200000',
                    u'fees': u'10000',
                    u'StorageSpending': u'2000',
                    u'uploadspending': u'800',
                    u'downloadspending': u'60',
                    u'renterfunds': u'3',
                    u'size': 22,
                },
                {
                    u'totalcost': u'500000',
                    u'fees': u'70000',
                    u'StorageSpending': u'5000',
                    u'uploadspending': u'100',
                    u'downloadspending': u'10',
                    u'renterfunds': u'2',
                    u'size': 77,
                },
            ],
            u'inactivecontracts': [
                {
                    u'totalcost': u'100000',
                    u'fees': u'5000',
                    u'StorageSpending': u'1000',
                    u'uploadspending': u'400',
                    u'downloadspending': u'30',
                    u'renterfunds': u'1',
                    u'size': 11,
                },
                {
                    u'totalcost': u'250000',
                    u'fees': u'35000',
                    u'StorageSpending': u'2500',
                    u'uploadspending': u'50',
                    u'downloadspending': u'5',
                    u'renterfunds': u'3',
                    u'size': 33,
                },
            ]
        }
        self.mock_sia_api.get_renter_files.return_value = {
            u'files': [
                {
                    u'filesize': 900,
                    u'uploadedbytes': 50,
                    u'uploadprogress': 90,
                },
                {
                    u'filesize': 800,
                    u'uploadedbytes': 100,
                    u'uploadprogress': 100,
                },
                {
                    u'filesize': 100,
                    u'uploadedbytes': 5,
                    u'uploadprogress': 90,
                },
            ],
        }
        self.mock_sia_api.get_wallet.return_value = {
            u'confirmedsiacoinbalance': u'900',
            u'unconfirmedoutgoingsiacoins': u'35',
            u'unconfirmedincomingsiacoins': u'92',
        }

        self.assertSiaStateEqual(
            state.SiaState(
                timestamp=_DUMMY_END_TIMESTAMP,
                api_latency=207.0,
                file_count=3,
                file_total_bytes=((900 * .9) + (800 * 1.0) + (100 * .9)),
                file_uploads_in_progress_count=2,
                file_uploaded_bytes=155,
                contract_count_active=2,
                contract_count_inactive=2,
                contract_total_size=143L,
                contract_total_spending=1050000L,
                contract_fee_spending=120000L,
                contract_storage_spending=10500L,
                contract_upload_spending=1350L,
                contract_download_spending=105L,
                contract_remaining_funds=9L,
                wallet_siacoin_balance=900L,
                wallet_outgoing_siacoins=35L,
                wallet_incoming_siacoins=92L,
                renter_allowance=None,
                renter_contract_fees=None,
                renter_total_allocated=None,
                renter_contract_spending=None,
                renter_download_spending=None,
                renter_storage_spending=None,
                renter_upload_spending=None,
                renter_unspent=None), self.builder.build())
Ejemplo n.º 6
0
    def test_appends_to_existing_file(self):
        if True:
            return
        mock_file = io.BytesIO((
            'timestamp,'
            'contract_count,'
            'file_count,'
            'uploads_in_progress_count,'
            'total_contract_size,'
            'total_file_bytes,'
            'uploaded_bytes,'
            'total_contract_spending,'
            'contract_fee_spending,'
            'storage_spending,'
            'upload_spending,'
            'download_spending,'
            'remaining_renter_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'api_latency\n'
            '2018-02-11T16:05:02,5,3,2,9,4444,900,65,25,2,35,0,100,75,26,83,5.0\n'
        ))

        serializer = serialize.CsvSerializer(mock_file)
        serializer.write_state(
            state.SiaState(timestamp=datetime.datetime(2018, 2, 11, 16, 5, 7),
                           contract_count=6,
                           file_count=4,
                           uploads_in_progress_count=3,
                           total_contract_size=10,
                           total_file_bytes=5555,
                           uploaded_bytes=901,
                           total_contract_spending=75,
                           contract_fee_spending=26,
                           storage_spending=3,
                           upload_spending=36,
                           download_spending=1,
                           remaining_renter_funds=101,
                           wallet_siacoin_balance=76,
                           wallet_outgoing_siacoins=27,
                           wallet_incoming_siacoins=84,
                           api_latency=6.0))

        self.assertEqual((
            'timestamp,'
            'contract_count,'
            'file_count,'
            'uploads_in_progress_count,'
            'total_contract_size,'
            'total_file_bytes,'
            'uploaded_bytes,'
            'total_contract_spending,'
            'contract_fee_spending,'
            'storage_spending,'
            'upload_spending,'
            'download_spending,'
            'remaining_renter_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'api_latency\n'
            '2018-02-11T16:05:02,5,3,2,9,4444,900,65,25,2,35,0,100,75,26,83,5.0\n'
            '2018-02-11T16:05:07,6,4,3,10,5555,901,75,26,3,36,1,101,76,27,84,6.0\n'
        ), mock_file.getvalue())
Ejemplo n.º 7
0
    def test_writes_state_to_file(self):
        mock_file = io.BytesIO()

        serializer = serialize.CsvSerializer(mock_file)
        serializer.write_state(
            state.SiaState(timestamp=datetime.datetime(2018, 2, 11, 16, 5, 2),
                           api_latency=5.0,
                           file_count=3,
                           file_total_bytes=4444,
                           file_uploads_in_progress_count=2,
                           file_uploaded_bytes=900,
                           contract_count_active=3,
                           contract_count_inactive=2,
                           contract_total_size=9,
                           contract_total_spending=65,
                           contract_fee_spending=25,
                           contract_storage_spending=2,
                           contract_upload_spending=35,
                           contract_download_spending=0,
                           contract_remaining_funds=100,
                           wallet_siacoin_balance=75,
                           wallet_outgoing_siacoins=26,
                           wallet_incoming_siacoins=83,
                           renter_allowance=500,
                           renter_contract_fees=233,
                           renter_total_allocated=443,
                           renter_contract_spending=123,
                           renter_download_spending=0,
                           renter_storage_spending=200,
                           renter_upload_spending=66,
                           renter_unspent=111))

        self.assertEqual((
            'timestamp,'
            'api_latency,'
            'file_count,'
            'file_total_bytes,'
            'file_uploads_in_progress_count,'
            'file_uploaded_bytes,'
            'contract_count_active,'
            'contract_count_inactive,'
            'contract_total_size,'
            'contract_total_spending,'
            'contract_fee_spending,'
            'contract_storage_spending,'
            'contract_upload_spending,'
            'contract_download_spending,'
            'contract_remaining_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'renter_allowance,'
            'renter_contract_fees,'
            'renter_total_allocated,'
            'renter_contract_spending,'
            'renter_download_spending,'
            'renter_storage_spending,'
            'renter_upload_spending,'
            'renter_unspent\n'
            '2018-02-11T16:05:02,5.0,3,4444,2,900,3,2,9,65,25,2,35,0,100,75,26,83,500,233,443,123,0,200,66,111\n'
        ), mock_file.getvalue())
Ejemplo n.º 8
0
    def test_appends_to_existing_file(self):
        if True:
            return
        mock_file = io.BytesIO((
            'timestamp,'
            'api_latency,'
            'file_count,'
            'file_total_bytes,'
            'file_uploads_in_progress_count,'
            'file_uploaded_bytes,'
            'contract_count_active,'
            'contract_count_inactive,'
            'contract_total_size,'
            'contract_total_spending,'
            'contract_fee_spending,'
            'contract_storage_spending,'
            'contract_upload_spending,'
            'contract_download_spending,'
            'contract_remaining_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'renter_allowance,'
            'renter_contract_fees,'
            'renter_total_allocated,'
            'renter_contract_spending,'
            'renter_download_spending,'
            'renter_storage_spending,'
            'renter_upload_spending,'
            'renter_unspent\n'
            '2018-02-11T16:05:02,5.0,3,4444,2,900,3,2,8,65,25,2,35,0,100,75,26,83,500,233,443,123,0,200,66,111\n'
        ))

        serializer = serialize.CsvSerializer(mock_file)
        serializer.write_state(
            state.SiaState(timestamp=datetime.datetime(2018, 2, 11, 16, 5, 7),
                           api_latency=6.0,
                           file_count=4,
                           file_total_bytes=5555,
                           file_uploads_in_progress_count=3,
                           file_uploaded_bytes=901,
                           contract_count_active=4,
                           contract_count_inactive=2,
                           contract_total_size=10,
                           contract_total_spending=75,
                           contract_fee_spending=26,
                           contract_storage_spending=3,
                           contract_upload_spending=36,
                           contract_download_spending=1,
                           contract_remaining_funds=101,
                           wallet_siacoin_balance=76,
                           wallet_outgoing_siacoins=27,
                           wallet_incoming_siacoins=84,
                           renter_allowance=501,
                           renter_contract_fees=234,
                           renter_total_allocated=444,
                           renter_contract_spending=124,
                           renter_download_spending=1,
                           renter_storage_spending=201,
                           renter_upload_spending=67,
                           renter_unspent=110))

        self.assertEqual((
            'timestamp,'
            'api_latency,'
            'file_count,'
            'file_total_bytes,'
            'file_uploads_in_progress_count,'
            'file_uploaded_bytes,'
            'contract_count_active,'
            'contract_count_inactive,'
            'contract_total_size,'
            'contract_total_spending,'
            'contract_fee_spending,'
            'contract_storage_spending,'
            'contract_upload_spending,'
            'contract_download_spending,'
            'contract_remaining_funds,'
            'wallet_siacoin_balance,'
            'wallet_outgoing_siacoins,'
            'wallet_incoming_siacoins,'
            'renter_allowance,'
            'renter_contract_fees,'
            'renter_total_allocated,'
            'renter_contract_spending,'
            'renter_download_spending,'
            'renter_storage_spending,'
            'renter_upload_spending,'
            'renter_unspent\n'
            '2018-02-11T16:05:02,5.0,3,4444,2,900,3,2,8,65,25,2,35,0,100,75,26,83,500,233,443,123,0,200,66,111\n'
            '2018-02-11T16:05:07,6.0,4,5555,3,901,4,2,10,75,26,3,36,1,101,76,27,84,501,234,444,124,1,201,67,110\n'
        ), mock_file.getvalue())
Ejemplo n.º 9
0
    def test_builds_partial_state_when_one_api_call_fails(self):
        self.mock_sia_api.get_renter_contracts.return_value = {
            u'activecontracts': [
                {
                    u'totalcost': u'200000',
                    u'fees': u'10000',
                    u'StorageSpending': u'2000',
                    u'uploadspending': u'800',
                    u'downloadspending': u'60',
                    u'renterfunds': u'3',
                    u'size': 22,
                },
                {
                    u'totalcost': u'500000',
                    u'fees': u'70000',
                    u'StorageSpending': u'5000',
                    u'uploadspending': u'100',
                    u'downloadspending': u'10',
                    u'renterfunds': u'2',
                    u'size': 77,
                },
            ],
            u'inactivecontracts': [
                {
                    u'totalcost': u'100000',
                    u'fees': u'5000',
                    u'StorageSpending': u'1000',
                    u'uploadspending': u'400',
                    u'downloadspending': u'30',
                    u'renterfunds': u'1',
                    u'size': 11,
                },
                {
                    u'totalcost': u'250000',
                    u'fees': u'35000',
                    u'StorageSpending': u'2500',
                    u'uploadspending': u'50',
                    u'downloadspending': u'5',
                    u'renterfunds': u'3',
                    u'size': 33,
                },
            ]
        }
        self.mock_sia_api.get_renter_files.return_value = {
            u'message': u'dummy get_renter_files error'
        }
        self.mock_sia_api.get_wallet.return_value = {
            u'confirmedsiacoinbalance': u'900',
            u'unconfirmedoutgoingsiacoins': u'35',
            u'unconfirmedincomingsiacoins': u'92',
        }

        self.assertSiaStateEqual(
            state.SiaState(timestamp=_DUMMY_END_TIMESTAMP,
                           contract_count=4,
                           total_contract_size=143L,
                           file_count=None,
                           total_file_bytes=None,
                           uploads_in_progress_count=None,
                           uploaded_bytes=None,
                           total_contract_spending=1050000L,
                           contract_fee_spending=120000L,
                           upload_spending=1350L,
                           download_spending=105L,
                           remaining_renter_funds=9L,
                           storage_spending=10500L,
                           wallet_siacoin_balance=900L,
                           wallet_outgoing_siacoins=35L,
                           wallet_incoming_siacoins=92L,
                           api_latency=207.0), self.builder.build())