<commit_before>from ddt import data, ddt
from rest_framework import status, test

from waldur_core.structure.tests import factories as structure_factories
from waldur_core.structure.tests import fixtures as structure_fixtures

from .. import models
from . import factories


@ddt
class ProfileRetrieveTest(test.APITransactionTestCase):
    def setUp(self):
        self.fixture = structure_fixtures.ProjectFixture()
        self.profile = factories.PaymentProfileFactory(
            organization=self.fixture.customer
        )
        self.url = factories.PaymentProfileFactory.get_url(profile=self.profile)

    @data('owner', 'staff', 'global_support')
    def test_user_with_access_can_retrieve_customer_profile(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @data('manager', 'admin', 'user')
    def test_user_cannot_retrieve_customer_profile(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

    @data('staff', 'global_support')
    def test_user_with_access_can_retrieve_unactive_customer_profile(self, user):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @data('owner', 'manager', 'admin', 'user')
    def test_user_cannot_retrieve_unactive_customer_profile(self, user):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
<commit_msg>[WAL-3000] Add tests.<commit_after>from ddt import data, ddt
from rest_framework import status, test

from waldur_core.structure.tests import factories as structure_factories
from waldur_core.structure.tests import fixtures as structure_fixtures

from .. import models
from . import factories


@ddt
class ProfileRetrieveTest(test.APITransactionTestCase):
    def setUp(self):
        self.fixture = structure_fixtures.ProjectFixture()
        self.profile = factories.PaymentProfileFactory(
            organization=self.fixture.customer
        )
        self.url = factories.PaymentProfileFactory.get_url(profile=self.profile)
        self.customer_url = structure_factories.CustomerFactory.get_url(
            customer=self.fixture.customer
        )

    @data('owner', 'staff', 'global_support')
    def test_user_with_access_can_retrieve_customer_profile(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @data('manager', 'admin', 'user')
    def test_user_cannot_retrieve_customer_profile(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

    @data('staff', 'global_support')
    def test_user_with_access_can_retrieve_unactive_customer_profile(self, user):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

    @data('owner', 'manager', 'admin', 'user')
    def test_user_cannot_retrieve_unactive_customer_profile(self, user):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)

    @data('owner', 'staff', 'global_support')
    def test_user_with_access_can_retrieve_customer_profile_in_organization_endpoint(
        self, user
    ):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.customer_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['payment_profiles']), 1)

    @data('manager', 'admin')
    def test_user_cannot_retrieve_customer_profile_in_organization_endpoint(self, user):
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.customer_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['payment_profiles'], None)

    @data('staff', 'global_support')
    def test_user_with_access_can_retrieve_unactive_customer_profile_in_organization_endpoint(
        self, user
    ):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.customer_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['payment_profiles']), 1)

    @data('owner',)
    def test_user_cannot_retrieve_unactive_customer_profile_in_organization_endpoint(
        self, user
    ):
        self.profile.is_active = False
        self.profile.save()
        self.client.force_authenticate(getattr(self.fixture, user))
        response = self.client.get(self.customer_url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['payment_profiles'], [])

{'fraction_non_alphanumeric': 0.10192407696307852, 'fraction_numerical': 0.007280291211648466, 'mean_word_length': 3.9527896995708156, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3867115', 'n_tokens_mistral': 1791, 'n_tokens_neox': 1712, 'n_words': 253}