def test_has_address(self): self.assertFalse(self.company.has_address) self.company.REQUIRED_ADDRESS_FIELDS = [] self.assertTrue(self.company.has_address) self.company.REQUIRED_ADDRESS_FIELDS = ['street'] self.assertFalse(self.company.has_address) self.company.street = random_gen.gen_string(10) self.assertTrue(self.company.has_address)
def test_sync_does_not_duplicate(mocker, user): GithubRepo.objects.all().delete() repos = { 'edges': random_repos(10), 'cursor': random_gen.gen_string(12), 'pageInfo': { 'endCursor': random_gen.gen_string(12), 'hasNextPage': False } } mocker.patch('core.services.query_repos', return_value=repos) cli = GithubClient(user.username) cli.sync_repos() assert GithubRepo.objects.filter(user=user).count() == 10 cli.sync_repos() assert GithubRepo.objects.filter(user=user).count() == 10
def generate(self, **kwargs): company = self._get_company(**kwargs) buyer = self._get_or_generate('buyer', ShareholderGenerator, kwargs, dict(company=company)) # seller only if not sent as kwarg if 'seller' not in kwargs.keys(): seller = ShareholderGenerator().generate(company=company) else: seller = kwargs.get('seller') count = kwargs.get('count') or 3 value = kwargs.get('value') or 2 security = kwargs.get('security') or SecurityGenerator().generate( company=company) bought_at = kwargs.get('bought_at') or datetime.datetime.now().date() kwargs2 = { "buyer": buyer, "bought_at": bought_at, "count": count, "value": value, "security": security, "comment": kwargs.get('comment') or random_gen.gen_string(55), "number_segments": kwargs.get('number_segments', []) } if seller: kwargs2.update({"seller": seller}) if kwargs.get('registration_type'): kwargs2.update( {'registration_type': kwargs.get('registration_type')}) if kwargs.get('depot_type'): kwargs2.update({'depot_type': kwargs.get('depot_type')}) if kwargs.get('depot_bank'): kwargs2.update({'depot_bank': kwargs.get('depot_bank')}) if kwargs.get('stock_book_id'): kwargs2.update({'stock_book_id': kwargs.get('stock_book_id')}) if kwargs.get('certificate_id'): kwargs2.update({'certificate_id': kwargs.get('certificate_id')}) if kwargs.get('vesting_months'): kwargs2.update({'vesting_months': kwargs.get('vesting_months')}) if kwargs.get('save') == False: return Position(**kwargs2) return Position.objects.create(**kwargs2)
def test_sync_create_repo_instances(mocker, user): GithubRepo.objects.all().delete() repos = { 'edges': random_repos(10), 'cursor': random_gen.gen_string(12), 'pageInfo': { 'endCursor': random_gen.gen_string(12), 'hasNextPage': False } } mocker.patch('core.services.query_repos', return_value=repos) cli = GithubClient(user.username) cli.sync_repos() assert GithubRepo.objects.filter(user=user).count() == 10 assert GithubRepo.objects.filter( repo_id=repos['edges'][0]['node']['id']).exists() assert GithubRepo.objects.filter( name=repos['edges'][0]['node']['name']).exists() assert GithubRepo.objects.filter( url=repos['edges'][0]['node']['url']).exists()
def test_call(self): with self.assertRaises(ValidationError): self.validator() self.validator.company.email = random_gen.gen_string(20) with self.assertRaises(ValidationError): self.validator() self.validator.company.email = random_gen.gen_email() self.assertIsNone(self.validator())
def test_raise_error(self): validator = self.validator_class(self.company) error_message = random_gen.gen_string(10) with self.assertRaises(ValidationError) as ex: validator.raise_error(error_message) self.assertEqual(ex.message, error_message) # pragma: no cover self.assertIsNone(ex.code) # pragma: no cover code = random_gen.gen_integer() with self.assertRaises(ValidationError) as ex: validator.raise_error(error_message, code) self.assertEqual(ex.message, error_message) # pragma: no cover self.assertEqual(ex.code, code) # pragma: no cover
def test_partial_update_from_customer(self): self.client.force_authenticate(self.order_random.customer.user) self.order_random.proxy = None self.order_random.status = Order.DRAFT self.order_random.save() data = { 'name': gen_string(50), 'items': [{ 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'order': None, 'price': gen_decimal(7, 2) }, { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'order': None, 'price': gen_decimal(7, 2) }, { 'link': self.item_random.link, 'name': self.item_random.name, 'notes': self.item_random.notes, 'order': self.item_random.order.id, 'price': self.item_random.price }] } response = self.client.patch(self.order_detail_url, data, format='json') self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertTrue(response.data['proxy'] is None) self.assertEqual(len(response.data['items']), 3) self.assertEqual( Item.objects.filter(order=self.item_random.order).count(), 3)
def test_create(self): self.client.force_authenticate(self.order_random.customer.user) data = { 'name': gen_string(50), 'country': self.country.id, 'items': [ { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'price': gen_decimal(7, 2) }, { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'price': gen_decimal(7, 2) }, { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'price': gen_decimal(7, 2) }, { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'price': gen_decimal(7, 2) }, { 'link': gen_url(), 'name': gen_string(10), 'notes': gen_text(), 'price': gen_decimal(7, 2) }, ], } response = self.client.post(self.orders_list_url, data, format='json') self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.assertEqual(len(response.data['items']), len(data['items']))
def setUp(self): self.api = PingenAPI(random_gen.gen_string(32))
def test_is_valid_email(self): self.assertFalse(is_valid_email(random_gen.gen_string(10))) self.assertTrue(is_valid_email(random_gen.gen_email()))
'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_default', }, 'results': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_results', }, 'sessions': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_sessions', }, } # give random char field values a reasonable length from model_mommy import random_gen MOMMY_CUSTOM_FIELDS_GEN = { 'django.db.models.CharField': lambda: random_gen.gen_string(20) } # Django debug toolbar settings if DEBUG and not TESTING and ENABLE_DEBUG_TOOLBAR: INSTALLED_APPS += ['debug_toolbar'] MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware' ] + MIDDLEWARE def show_toolbar(request): return True DEBUG_TOOLBAR_CONFIG = { 'SHOW_TOOLBAR_CALLBACK': 'evap.settings.show_toolbar', 'JQUERY_URL': '', }
# and does not change behaviour in contrast to disabling the cache entirely. CACHES = { 'default': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_default', }, 'results': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_results', }, 'sessions': { 'BACKEND': 'django.core.cache.backends.db.DatabaseCache', 'LOCATION': 'testing_cache_sessions', }, } # give random char field values a reasonable length from model_mommy import random_gen MOMMY_CUSTOM_FIELDS_GEN = {'django.db.models.CharField': lambda: random_gen.gen_string(20)} # Django debug toolbar settings if DEBUG and not TESTING and ENABLE_DEBUG_TOOLBAR: INSTALLED_APPS += ['debug_toolbar'] MIDDLEWARE = ['debug_toolbar.middleware.DebugToolbarMiddleware'] + MIDDLEWARE def show_toolbar(request): return True DEBUG_TOOLBAR_CONFIG = { 'SHOW_TOOLBAR_CALLBACK': 'evap.settings.show_toolbar', 'JQUERY_URL': '', }
def gen_short_string(max_length): return random_gen.gen_string(min(max_length, 10))