def test_get_billing_period_partial_month_server(self): """ This method will test billing dates for given months when servers were only created in the middle of the month. """ # This will test appservers that were started during the month # but kept running after the month is over. invoice_month = self._generate_invoice_date(2017, 9) self.appserver.created = invoice_month + timedelta(days=10) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertEqual(first_billing_day.date(), timezone.make_aware(datetime(2017, 9, 11)).date()) self.assertEqual(last_billing_day.date(), timezone.make_aware(datetime(2017, 9, 30)).date()) # This will test appservers that were started during the month # and terminated during the month. invoice_month = self._generate_invoice_date(2017, 9) self.appserver.created = invoice_month + timedelta(days=10) self.appserver.terminated = invoice_month + timedelta(days=20) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertEqual(first_billing_day.date(), timezone.make_aware(datetime(2017, 9, 11)).date()) self.assertEqual(last_billing_day.date(), timezone.make_aware(datetime(2017, 9, 21)).date())
def test_get_billing_period_not_terminated_server(self): """ This includes two cases, if we're still in the current month and the AppServer is still running, or if the invoice is for a previous month and the AppServer wasn't terminated during that month. """ # We're issuing an invoice for the current month when appserver is still running. invoice_month = self._generate_invoice_date(this_month=True) self.appserver.created = invoice_month - timedelta(weeks=3) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) # First billing day will be the first day of this month. self.assertEqual(first_billing_day.date(), invoice_month.date()) # Last billing day will be today as the month is still active. self.assertEqual(last_billing_day.date(), timezone.now().date()) # We're issuing an invoice for a previous month when AppServer was running during the whole month invoice_month = self._generate_invoice_date(year=2017) next_month = datetime(invoice_month.year, invoice_month.month + 1, 1) last_day = next_month - timedelta(days=1) self.appserver.created = invoice_month - timedelta(weeks=6) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) # First billing day will be the first day of the generated month. self.assertEqual(first_billing_day.date(), invoice_month.date()) # Last billing day will be the last day of the month. self.assertEqual(last_billing_day.date(), last_day.date())
def test_get_billing_period_terminated_server(self): """ Tests the calculated billing dates (start, and end) for a given terminated appserver before the month of the invoice month. """ invoice_month = self._generate_invoice_date(this_month=True) # The app server was created in the past and terminated before the billing start date created = invoice_month - timedelta(weeks=10) terminated = invoice_month - timedelta(weeks=7) self.appserver.created = created self.appserver.terminated = terminated first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertIsNone(first_billing_day) self.assertIsNone(last_billing_day) # An invoice from the past invoice_month = timezone.make_aware(datetime(2016, 10, 3)) # The app server was created in the past and terminated before the billing start date created = invoice_month - timedelta(weeks=10) terminated = invoice_month - timedelta(weeks=7) self.appserver.created = created self.appserver.terminated = terminated first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertIsNone(first_billing_day) self.assertIsNone(last_billing_day)
def test_get_billing_period_future_billing_date(self): """ If the invoice is for future month then no billing dates are expected to be returned. """ invoice_month = timezone.now() + timedelta(weeks=13) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertIsNone(first_billing_day) self.assertIsNone(last_billing_day)
def test_get_billing_period_future_created_server(self): """ If the invoice is being generated for an appserver that's created after the invoice month then no dates must be generated. """ invoice_month = self._generate_invoice_date(year=2017) self.appserver.created = self._generate_invoice_date(year=2018) first_billing_day, last_billing_day = get_billing_period( self.appserver, invoice_month) self.assertIsNone(first_billing_day) self.assertIsNone(last_billing_day)