예제 #1
0
    def test_check_not_cancel_if_paid(self):
        ''' This test checks that if the user does not uploads a PO before 30 days, the site will be cancelled
        automatically'''
        today = datetime.today()
        do_test_login(self, user="******")
        # Create site (more than 30 days ago start date)
        site = Site.objects.create(name="testSite",
                                   email='*****@*****.**',
                                   type=ServerType.objects.get(id=1),
                                   start_date=today - timedelta(days=40))
        site.users.add(User.objects.get(username="******"))

        self.assertFalse(hasattr(site, 'billing'))
        pofile = SimpleUploadedFile("file.pdf", "file_content")
        self.client.post(
            reverse('billing_management', kwargs={'site_id': site.id}), {
                'purchase_order_number': 'testOrderNumber',
                'group': 'testGroup',
                'purchase_order': pofile
            })
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertTrue(hasattr(site, 'billing'))

        # Check that the site is not cancelled, it has a PO attached
        self.assertIsNone(site.end_date)
        self.assertIn(User.objects.get(username='******'), site.users.all())
        check_subscription()
        self.assertEqual(len(mail.outbox), 0)
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())
예제 #2
0
    def test_scheduled_deletion_unpaid_service(self):
        today = datetime.today().date()
        do_test_login(self, user="******")
        site = Site.objects.create(name="testSite",
                                   email='*****@*****.**',
                                   type=ServerType.objects.get(id=1),
                                   start_date=today - timedelta(days=15))
        netconf = NetworkConfig.objects.create(
            IPv4='131.111.58.253',
            IPv6='2001:630:212:8::8c:253',
            type='ipvxpub',
            name="mws-66424.mws3.csx.cam.ac.uk")
        Service.objects.create(site=site,
                               type='production',
                               status="ready",
                               network_configuration=netconf)
        site.users.add(User.objects.get(username="******"))

        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        site.start_date = today - timedelta(days=32)
        site.save()
        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(mail.outbox[1].subject,
                         'Your managed web server has been cancelled')
        self.assertEqual(mail.outbox[1].to, [site.email])
        self.assertEqual(site.end_date, today)
        self.assertFalse(site.users.exists())

        site.start_date = today - timedelta(days=62)
        site.end_date = today - timedelta(days=30)
        site.save()
        check_subscription()
        delete_cancelled()
        # Retrieve object
        self.assertFalse(Site.objects.filter(pk=site.id))
예제 #3
0
    def test_scheduled_cancellation(self):
        today = datetime.today()
        do_test_login(self, user="******")
        # Create site (300 days ago start date)
        site = Site.objects.create(name="testSite",
                                   email='*****@*****.**',
                                   type=ServerType.objects.get(id=1),
                                   start_date=today - timedelta(days=300))
        netconf = NetworkConfig.objects.create(
            IPv4='131.111.58.253',
            IPv6='2001:630:212:8::8c:253',
            type='ipvxpub',
            name="mws-66424.mws3.csx.cam.ac.uk")
        Service.objects.create(site=site,
                               type='production',
                               status="ready",
                               network_configuration=netconf)
        site.users.add(User.objects.get(username="******"))

        self.assertFalse(hasattr(site, 'billing'))
        pofile = SimpleUploadedFile("file.pdf", "file_content")
        self.client.post(
            reverse('billing_management', kwargs={'site_id': site.id}), {
                'purchase_order_number': 'testOrderNumber',
                'group': 'testGroup',
                'purchase_order': pofile
            })
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertTrue(hasattr(site, 'billing'))

        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertEqual(len(mail.outbox), 0)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        asdfasd = self.client.post(
            reverse('donotrenew', kwargs={'site_id': site.id}), {})
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertFalse(site.subscription)
        self.assertTrue(site.users.exists())

        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertEqual(len(mail.outbox), 0)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.users.exists())

        site.start_date = today - timedelta(days=370)
        site.save()
        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(mail.outbox[0].subject,
                         'Your managed web server has been cancelled')
        self.assertEqual(mail.outbox[0].to, [site.email])
        self.assertEqual(site.end_date, today.date())
        self.assertFalse(site.users.exists())

        # After 3 weeks the site should have not been deleted yet
        site.end_date = today - timedelta(days=21)
        site.save()
        check_subscription()
        delete_cancelled()
        # Retrieve object
        site = Site.objects.get(pk=site.id)

        # After 9 weeks the site should have been deleted
        site.end_date = today - timedelta(days=60)
        site.save()
        check_subscription()
        delete_cancelled()
        # Retrieve object
        self.assertFalse(Site.objects.filter(pk=site.id))
예제 #4
0
    def test_check_cacnel_if_not_paid(self):
        ''' This test checks that if the user does not uploads a PO before 30 days, the site will be cancelled
        automatically'''
        # 1 month for renewal warning
        today = datetime.today()
        site = Site.objects.create(name="testSite",
                                   email='*****@*****.**',
                                   type=ServerType.objects.get(id=1),
                                   start_date=today - timedelta(days=10))
        User.objects.create(username="******")
        site.users.add(User.objects.get(username="******"))
        check_subscription()
        # Nothing should happen, only 10 days
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertEqual(len(mail.outbox), 0)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        # 15 days reminder
        site.start_date = today - timedelta(days=15)
        site.save()
        check_subscription()
        self.assertEqual(len(mail.outbox), 1)
        self.assertEqual(
            mail.outbox[0].subject,
            'Remember to upload a purchase order for your managed web server')
        self.assertEqual(mail.outbox[0].to, [site.email])
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        # 20 days reminder (nothing)
        site.start_date = today - timedelta(days=20)
        site.save()
        check_subscription()
        self.assertEqual(len(mail.outbox), 1)
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        # 25 days reminder, last week reminder
        site.start_date = today - timedelta(days=25)
        site.save()
        check_subscription()
        self.assertEqual(len(mail.outbox), 2)
        self.assertEqual(
            mail.outbox[1].subject,
            'Remember to upload a purchase order for your managed web server')
        self.assertEqual(mail.outbox[1].to, [site.email])
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertIsNone(site.end_date)
        self.assertTrue(site.subscription)
        self.assertTrue(site.users.exists())

        # More tha 30 days, cancel the site
        site.start_date = today - timedelta(days=35)
        site.save()
        self.assertIsNone(site.end_date)
        self.assertIn(User.objects.get(username='******'), site.users.all())
        check_subscription()
        self.assertEqual(len(mail.outbox), 3)
        self.assertEqual(mail.outbox[2].subject,
                         'Your managed web server has been cancelled')
        self.assertEqual(mail.outbox[2].to, [site.email])
        # Retrieve object
        site = Site.objects.get(pk=site.id)
        self.assertTrue(site.subscription)
        self.assertEqual(site.end_date, today.date())
        self.assertFalse(site.users.exists())