Created
April 4, 2019 10:31
-
-
Save dp-quant/25cd954b232f4149734c2af42ddbdd82 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from rest_framework.test import APITestCase | |
from rest_framework import status | |
from django.core.urlresolvers import reverse | |
from core.tests.creator_mixin import TestSuitesCreatorMixin | |
from ..models import ContractChangesRecord | |
from profilesmanagement.constants import SUBSCRIPTION_LEVEL_CHOICES | |
import logging | |
logger = logging.getLogger(__name__) | |
class VerificationFlowTestCase(TestSuitesCreatorMixin, APITestCase): | |
def setUp(self): | |
self.account = self.create_user(is_verified=True) | |
self.profile = self.create_profile(self.account) | |
self.subscribe(self.profile, SUBSCRIPTION_LEVEL_CHOICES.investment) | |
self.product = self.create_product() | |
self.new_product = self.create_product() | |
def test_contract_flow(self): | |
self.client.force_authenticate(user=self.account) | |
self.assertEquals(self.profile.subscription.level, SUBSCRIPTION_LEVEL_CHOICES.investment) | |
self.assertTrue(self.account.is_verified) | |
contact_data = { | |
"name": "Test Contract", | |
"is_active": True, | |
"certification_code": "C7O3D6E6", | |
"on_hold": False, | |
"uid": "12312323", | |
"products": [self.product.pk], | |
"philosophy": 1 | |
} | |
contracts_url = reverse('contract-list') | |
response = self.client.post(contracts_url, contact_data) | |
logger.info(response.content) | |
self.assertEquals(response.status_code, status.HTTP_201_CREATED) | |
data = response.json() | |
data.update({'philosophy': 2, 'products': [self.new_product.pk]}) | |
logger.info('new contact data=%s', data) | |
contract_details_url = reverse('contract-detail', kwargs={'pk': data.get('id')}) | |
self.client.put(contract_details_url, data) | |
verification = ContractChangesRecord.objects.filter(contract_id=data.get('id'), | |
accept_for_id=self.account.pk).last() | |
self.assertIsNotNone(verification) | |
verification_url = reverse('changes_apply', kwargs={'activation_code': verification.key}) | |
response = self.client.get(verification_url) | |
redirects_to_url = reverse('itoucan') | |
self.assertRedirects(response, redirects_to_url, target_status_code=200) | |
response = self.client.get(contract_details_url) | |
self.assertEquals(response.status_code, status.HTTP_200_OK) | |
data = response.json() | |
logger.info('new contact data=%s', data) | |
self.assertEqual(data.get('philosophy'), 2) | |
self.assertEquals([product.get('id') for product in data.get('products')], [self.new_product.pk]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment