コード例 #1
0
ファイル: tests.py プロジェクト: giang-nghg/opencraft
    def test_get_instance_charges(self, charges_details_mock, mock_consul):
        """
        Test that an instance is going to generate charges for all of its
        terminated and running appservers only and make sure that servers
        from other instances are not included in the subtotals, total, etc.
        """
        desired_instance = OpenEdXInstanceFactory()
        make_test_appserver(desired_instance, status=AppServerStatus.Running)
        make_test_appserver(desired_instance,
                            status=AppServerStatus.Terminated)
        make_test_appserver(desired_instance,
                            status=AppServerStatus.ConfigurationFailed)

        another_instance = OpenEdXInstanceFactory()
        make_test_appserver(instance=another_instance)

        invoice_month = self._generate_invoice_date()
        expected_charges_details = {
            'name': 'Mock AppServer charge',
            'billing_start': invoice_month,
            'billing_end': invoice_month,
            'days': 20,
            'charge': 12,
        }
        charges_details_mock.return_value = expected_charges_details
        appservers_charges, appservers_total = get_instance_charges(
            desired_instance, invoice_month)

        self.assertEqual(len(appservers_charges), 2)
        for charge in appservers_charges:
            self.assertEqual(charge, expected_charges_details)

        self.assertEqual(appservers_total,
                         2 * expected_charges_details['charge'])
コード例 #2
0
ファイル: tests.py プロジェクト: giang-nghg/opencraft
 def get_instance_charges_future_month(self, mock_consul):
     """
     Test that the instance will return empty charges and 0 total for its
     AppServers if the invoice month is in future.
     """
     invoice_month = self._generate_invoice_date(year=datetime.now().year +
                                                 1)
     appservers_charges, appservers_total = get_instance_charges(
         OpenEdXInstanceFactory(), invoice_month)
     self.assertEqual(appservers_charges, [])
     self.assertEqual(appservers_total, 0)