示例#1
0
class TestTransferDomainModel(BaseDomainTest):
    def setUp(self):
        super(TestTransferDomainModel, self).setUp()

        self.transfer = TransferDomainRequest(to_username=self.mugglename,
                                              from_username=self.username,
                                              domain=self.domain.name)
        self.transfer.save()

    def tearDown(self):
        super(TestTransferDomainModel, self).tearDown()

        self.transfer.delete()

    def test_domain_transfer_inactive(self):
        self.transfer.active = False
        self.transfer.save()

        with self.assertRaises(InactiveTransferDomainException):
            self.transfer.transfer_domain()

        with self.assertRaises(InactiveTransferDomainException):
            self.transfer.send_transfer_request()

    def test_domain_transfer(self):
        self.transfer.transfer_domain()

        self.assertFalse(self.transfer.active)
        self.assertFalse(self.transfer.from_user.is_member_of(self.domain))
        self.assertTrue(self.transfer.to_user.is_member_of(self.domain))

    def test_send_transfer_request(self):
        with patch('corehq.apps.hqwebapp.tasks.send_HTML_email'
                   ) as patched_send_HTML_email:
            self.transfer.send_transfer_request()

            self.assertIsNotNone(self.transfer.transfer_guid)
            self.assertEqual(
                patched_send_HTML_email.call_count, 2,
                "Should send an email to both requester and requestee")

    def test_get_active_transfer(self):
        res = TransferDomainRequest.get_active_transfer(
            self.domain, self.user.username)
        self.assertIsNotNone(res)

        newer = TransferDomainRequest(to_username=self.mugglename,
                                      from_username=self.username,
                                      request_time=datetime.utcnow(),
                                      domain=self.domain.name)
        newer.save()

        res = TransferDomainRequest.get_active_transfer(
            self.domain, self.user.username)
        self.assertEqual(res.pk, newer.pk)
        self.assertFalse(
            TransferDomainRequest.objects.get(pk=self.transfer.pk).active)
class TestTransferDomainModel(BaseDomainTest):

    def setUp(self):
        super(TestTransferDomainModel, self).setUp()

        self.transfer = TransferDomainRequest(
            to_username=self.mugglename,
            from_username=self.username,
            domain=self.domain.name)
        self.transfer.save()

    def tearDown(self):
        super(TestTransferDomainModel, self).tearDown()

        self.transfer.delete()

    def test_domain_transfer_inactive(self):
        self.transfer.active = False
        self.transfer.save()

        with self.assertRaises(InactiveTransferDomainException):
            self.transfer.transfer_domain()

        with self.assertRaises(InactiveTransferDomainException):
            self.transfer.send_transfer_request()

    def test_domain_transfer(self):
        self.transfer.transfer_domain()

        self.assertFalse(self.transfer.active)
        self.assertFalse(self.transfer.from_user.is_member_of(self.domain))
        self.assertTrue(self.transfer.to_user.is_member_of(self.domain))

    def test_send_transfer_request(self):
        self.transfer.send_transfer_request()

        self.assertIsNotNone(self.transfer.transfer_guid)
        self.assertEqual(len(mail.outbox), 2,
                         "Should send an email to both requester and requestee")

    def test_get_active_transfer(self):
        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertIsNotNone(res)

        newer = TransferDomainRequest(
            to_username=self.mugglename,
            from_username=self.username,
            request_time=datetime.utcnow(),
            domain=self.domain.name)
        newer.save()

        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertEqual(res.pk, newer.pk)
        self.assertFalse(TransferDomainRequest.objects.get(pk=self.transfer.pk).active)
    def test_get_active_transfer(self):
        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertIsNotNone(res)

        newer = TransferDomainRequest(
            to_username=self.mugglename,
            from_username=self.username,
            request_time=datetime.utcnow(),
            domain=self.domain.name)
        newer.save()

        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertEqual(res.pk, newer.pk)
        self.assertFalse(TransferDomainRequest.objects.get(pk=self.transfer.pk).active)
示例#4
0
    def test_get_active_transfer(self):
        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertIsNotNone(res)

        newer = TransferDomainRequest(
            to_username=self.mugglename,
            from_username=self.username,
            request_time=datetime.utcnow(),
            domain=self.domain.name)
        newer.save()

        res = TransferDomainRequest.get_active_transfer(self.domain, self.user.username)
        self.assertEqual(res.pk, newer.pk)
        self.assertFalse(TransferDomainRequest.objects.get(pk=self.transfer.pk).active)
示例#5
0
class TestTransferDomainViews(BaseDomainTest):
    def setUp(self):
        super(TestTransferDomainViews, self).setUp()
        self.transfer = TransferDomainRequest(to_username=self.mugglename,
                                              from_username=self.username,
                                              domain=self.domain.name)
        self.transfer.save()
        self.transfer.send_transfer_request()

        self.rando = WebUser.create(self.domain.name, 'rando', self.password,
                                    None, None)

    def tearDown(self):
        self.transfer.delete()
        self.rando.delete()
        super(TestTransferDomainViews, self).tearDown()

    def test_permissions_for_activation(self):
        # No one logged in
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.template_name, ['login_and_password/login.html'],
                         'Should redirect to login page')

        # Initiator logged in
        self.client.login(username=self.username, password=self.password)
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.status_code, 403)

        # Accepter logged in
        self.client.login(username=self.mugglename, password=self.password)
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_permissions_for_deactivation(self):
        # No one logged in
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.template_name, ['login_and_password/login.html'],
                         'Should redirect to login page')

        # Random user who belongs to the domain
        self.client.login(username=self.rando.username, password=self.password)
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.status_code, 403)

        # Accepter logged in
        self.client.login(username=self.mugglename, password=self.password)
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]),
                                follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_permissions_for_transfer_domain_view(self):
        # No one logged in
        resp = self.client.get(reverse('transfer_domain_view',
                                       args=[self.domain.name]),
                               follow=True)
        self.assertRedirects(
            resp,
            reverse('domain_login', kwargs={'domain': self.domain.name}) +
            '?next=' +
            reverse('transfer_domain_view', args=[self.domain.name]))

        # Random user who belongs to the domain but not an admin
        self.client.login(username=self.rando.username, password=self.password)
        resp = self.client.get(
            reverse('transfer_domain_view', args=[self.domain.name]))
        self.assertEqual(resp.status_code, 302, 'Should redirect to dashboard')

        # Domain admin logged in
        self.client.login(username=self.user.username, password=self.password)
        resp = self.client.get(
            reverse('transfer_domain_view', args=[self.domain.name]))
        self.assertEqual(resp.status_code, 200)
class TestTransferDomainViews(BaseDomainTest):
    def setUp(self):
        super(TestTransferDomainViews, self).setUp()
        self.transfer = TransferDomainRequest(
            to_username=self.mugglename,
            from_username=self.username,
            domain=self.domain.name)
        self.transfer.save()
        self.transfer.send_transfer_request()

        self.rando = WebUser.create(self.domain.name, 'rando', self.password)

    def tearDown(self):
        super(TestTransferDomainViews, self).tearDown()
        self.transfer.delete()
        self.rando.delete()

    def test_permissions_for_activation(self):
        # No one logged in
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.template_name, 'login_and_password/login.html',
                         'Should redirect to login page')

        # Initiator logged in
        self.client.login(username=self.username, password=self.password)
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.status_code, 403)

        # Accepter logged in
        self.client.login(username=self.mugglename, password=self.password)
        resp = self.client.post(reverse('activate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_permissions_for_deactivation(self):
        # No one logged in
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.template_name, 'login_and_password/login.html',
                         'Should redirect to login page')

        # Random user who belongs to the domain
        self.client.login(username=self.rando.username, password=self.password)
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.status_code, 403)

        # Accepter logged in
        self.client.login(username=self.mugglename, password=self.password)
        resp = self.client.post(reverse('deactivate_transfer_domain',
                                        args=[self.transfer.transfer_guid]), follow=True)
        self.assertEqual(resp.status_code, 200)

    def test_permissions_for_transfer_domain_view(self):
        # No one logged in
        resp = self.client.get(reverse('transfer_domain_view',
                                       args=[self.domain.name]), follow=True)
        self.assertRedirects(resp, reverse('domain_login', kwargs={'domain': self.domain.name}) +
            '?next=' + reverse('transfer_domain_view', args=[self.domain.name]))

        # Random user who belongs to the domain but not an admin
        self.client.login(username=self.rando.username, password=self.password)
        resp = self.client.get(reverse('transfer_domain_view',
                                       args=[self.domain.name]))
        self.assertEqual(resp.status_code, 302, 'Should redirect to dashboard')

        # Domain admin logged in
        self.client.login(username=self.user.username, password=self.password)
        resp = self.client.get(reverse('transfer_domain_view',
                                       args=[self.domain.name]))
        self.assertEqual(resp.status_code, 200)