Пример #1
0
class ApiAccessRequestTests(TestCase):
    def setUp(self):
        super(ApiAccessRequestTests, self).setUp()
        self.user = UserFactory()
        self.request = ApiAccessRequestFactory(user=self.user)

    def test_default_status(self):
        self.assertEqual(self.request.status, ApiAccessRequest.PENDING)
        self.assertFalse(ApiAccessRequest.has_api_access(self.user))

    def test_approve(self):
        self.request.approve()
        self.assertEqual(self.request.status, ApiAccessRequest.APPROVED)

    def test_deny(self):
        self.request.deny()
        self.assertEqual(self.request.status, ApiAccessRequest.DENIED)

    def test_nonexistent_request(self):
        """Test that users who have not requested API access do not get it."""
        other_user = UserFactory()
        self.assertFalse(ApiAccessRequest.has_api_access(other_user))

    @ddt.data(
        (ApiAccessRequest.PENDING, False),
        (ApiAccessRequest.DENIED, False),
        (ApiAccessRequest.APPROVED, True),
    )
    @ddt.unpack
    def test_has_access(self, status, should_have_access):
        self.request.status = status
        self.request.save()
        self.assertEqual(ApiAccessRequest.has_api_access(self.user),
                         should_have_access)

    def test_unique_per_user(self):
        with self.assertRaises(IntegrityError):
            ApiAccessRequestFactory(user=self.user)

    def test_no_access(self):
        self.request.delete()
        self.assertIsNone(ApiAccessRequest.api_access_status(self.user))

    def test_unicode(self):
        request_unicode = six.text_type(self.request)
        self.assertIn(self.request.website, request_unicode)
        self.assertIn(self.request.status, request_unicode)

    def test_retire_user_success(self):
        retire_result = self.request.retire_user(self.user)
        self.assertTrue(retire_result)
        self.assertEqual(self.request.company_address, '')
        self.assertEqual(self.request.company_name, '')
        self.assertEqual(self.request.website, '')
        self.assertEqual(self.request.reason, '')

    def test_retire_user_do_not_exist(self):
        user2 = UserFactory()
        retire_result = self.request.retire_user(user2)
        self.assertFalse(retire_result)
Пример #2
0
class ApiAccessRequestTests(TestCase):
    def setUp(self):
        super(ApiAccessRequestTests, self).setUp()
        self.user = UserFactory()
        self.request = ApiAccessRequestFactory(user=self.user)

    def test_default_status(self):
        self.assertEqual(self.request.status, ApiAccessRequest.PENDING)
        self.assertFalse(ApiAccessRequest.has_api_access(self.user))

    def test_approve(self):
        self.request.approve()  # pylint: disable=no-member
        self.assertEqual(self.request.status, ApiAccessRequest.APPROVED)

    def test_deny(self):
        self.request.deny()  # pylint: disable=no-member
        self.assertEqual(self.request.status, ApiAccessRequest.DENIED)

    def test_nonexistent_request(self):
        """Test that users who have not requested API access do not get it."""
        other_user = UserFactory()
        self.assertFalse(ApiAccessRequest.has_api_access(other_user))

    @ddt.data(
        (ApiAccessRequest.PENDING, False),
        (ApiAccessRequest.DENIED, False),
        (ApiAccessRequest.APPROVED, True),
    )
    @ddt.unpack
    def test_has_access(self, status, should_have_access):
        self.request.status = status
        self.request.save()  # pylint: disable=no-member
        self.assertEqual(ApiAccessRequest.has_api_access(self.user),
                         should_have_access)
Пример #3
0
class ApiAccessRequestTests(TestCase):

    def setUp(self):
        super(ApiAccessRequestTests, self).setUp()
        self.user = UserFactory()
        self.request = ApiAccessRequestFactory(user=self.user)

    def test_default_status(self):
        self.assertEqual(self.request.status, ApiAccessRequest.PENDING)
        self.assertFalse(ApiAccessRequest.has_api_access(self.user))

    def test_approve(self):
        self.request.approve()
        self.assertEqual(self.request.status, ApiAccessRequest.APPROVED)

    def test_deny(self):
        self.request.deny()
        self.assertEqual(self.request.status, ApiAccessRequest.DENIED)

    def test_nonexistent_request(self):
        """Test that users who have not requested API access do not get it."""
        other_user = UserFactory()
        self.assertFalse(ApiAccessRequest.has_api_access(other_user))

    @ddt.data(
        (ApiAccessRequest.PENDING, False),
        (ApiAccessRequest.DENIED, False),
        (ApiAccessRequest.APPROVED, True),
    )
    @ddt.unpack
    def test_has_access(self, status, should_have_access):
        self.request.status = status
        self.request.save()
        self.assertEqual(ApiAccessRequest.has_api_access(self.user), should_have_access)

    def test_unique_per_user(self):
        with self.assertRaises(IntegrityError):
            ApiAccessRequestFactory(user=self.user)

    def test_no_access(self):
        self.request.delete()
        self.assertIsNone(ApiAccessRequest.api_access_status(self.user))

    def test_unicode(self):
        request_unicode = six.text_type(self.request)
        self.assertIn(self.request.website, request_unicode)
        self.assertIn(self.request.status, request_unicode)

    def test_retire_user_success(self):
        retire_result = self.request.retire_user(self.user)
        self.assertTrue(retire_result)
        self.assertEqual(self.request.company_address, '')
        self.assertEqual(self.request.company_name, '')
        self.assertEqual(self.request.website, '')
        self.assertEqual(self.request.reason, '')

    def test_retire_user_do_not_exist(self):
        user2 = UserFactory()
        retire_result = self.request.retire_user(user2)
        self.assertFalse(retire_result)
Пример #4
0
class ApiAccessRequestTests(TestCase):

    def setUp(self):
        super(ApiAccessRequestTests, self).setUp()
        self.user = UserFactory()
        self.request = ApiAccessRequestFactory(user=self.user)

    def test_default_status(self):
        self.assertEqual(self.request.status, ApiAccessRequest.PENDING)
        self.assertFalse(ApiAccessRequest.has_api_access(self.user))

    def test_approve(self):
        self.request.approve()  # pylint: disable=no-member
        self.assertEqual(self.request.status, ApiAccessRequest.APPROVED)

    def test_deny(self):
        self.request.deny()  # pylint: disable=no-member
        self.assertEqual(self.request.status, ApiAccessRequest.DENIED)

    def test_nonexistent_request(self):
        """Test that users who have not requested API access do not get it."""
        other_user = UserFactory()
        self.assertFalse(ApiAccessRequest.has_api_access(other_user))

    @ddt.data(
        (ApiAccessRequest.PENDING, False),
        (ApiAccessRequest.DENIED, False),
        (ApiAccessRequest.APPROVED, True),
    )
    @ddt.unpack
    def test_has_access(self, status, should_have_access):
        self.request.status = status
        self.request.save()  # pylint: disable=no-member
        self.assertEqual(ApiAccessRequest.has_api_access(self.user), should_have_access)
Пример #5
0
class ApiAccessRequestTests(TestCase):
    def setUp(self):
        super(ApiAccessRequestTests, self).setUp()  # lint-amnesty, pylint: disable=super-with-arguments
        self.user = UserFactory()
        self.request = ApiAccessRequestFactory(user=self.user)

    def test_default_status(self):
        assert self.request.status == ApiAccessRequest.PENDING
        assert not ApiAccessRequest.has_api_access(self.user)

    def test_approve(self):
        self.request.approve()
        assert self.request.status == ApiAccessRequest.APPROVED

    def test_deny(self):
        self.request.deny()
        assert self.request.status == ApiAccessRequest.DENIED

    def test_nonexistent_request(self):
        """Test that users who have not requested API access do not get it."""
        other_user = UserFactory()
        assert not ApiAccessRequest.has_api_access(other_user)

    @ddt.data(
        (ApiAccessRequest.PENDING, False),
        (ApiAccessRequest.DENIED, False),
        (ApiAccessRequest.APPROVED, True),
    )
    @ddt.unpack
    def test_has_access(self, status, should_have_access):
        self.request.status = status
        self.request.save()
        assert ApiAccessRequest.has_api_access(self.user) == should_have_access

    def test_unique_per_user(self):
        with pytest.raises(IntegrityError):
            ApiAccessRequestFactory(user=self.user)

    def test_no_access(self):
        self.request.delete()
        assert ApiAccessRequest.api_access_status(self.user) is None

    def test_unicode(self):
        request_unicode = six.text_type(self.request)
        assert self.request.website in request_unicode
        assert self.request.status in request_unicode

    def test_retire_user_success(self):
        retire_result = self.request.retire_user(self.user)
        assert retire_result
        assert self.request.company_address == ''
        assert self.request.company_name == ''
        assert self.request.website == ''
        assert self.request.reason == ''

    def test_retire_user_do_not_exist(self):
        user2 = UserFactory()
        retire_result = self.request.retire_user(user2)
        assert not retire_result