""" from datetime import datetime, timedelta from StringIO import StringIO from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase from factory.django import get_model from mock import patch from slumber.exceptions import HttpClientError from ecommerce.core.management.commands.sync_hubspot import Command as sync_command from ecommerce.extensions.test.factories import create_order from ecommerce.tests.factories import SiteConfigurationFactory SiteConfiguration = get_model('core', 'SiteConfiguration') @patch.object(sync_command, '_hubspot_endpoint') class TestSyncHubspotCommand(TestCase): """ Test sync_hubspot management command. """ order = None hubspot_site_configuration = None def setUp(self): super(TestSyncHubspotCommand, self).setUp() self.hubspot_site_configuration = SiteConfigurationFactory.create( hubspot_secret_key='test_key', ) self.order = self._create_order('1122',
from django.contrib.admin.utils import NestedObjects from django.db import DEFAULT_DB_ALIAS from django.core import serializers from factory.django import get_model import django django.setup() Survey = get_model('survey', 'Survey') restore_me = Survey.objects.filter(id=1) collector = NestedObjects(using=DEFAULT_DB_ALIAS) collector.collect(restore_me) # This generates a hierarchical list of all of the objects related to the # object that was deleted. The same output that Django creates when it prompts # you for confirmation to delete something. result = collector.nested() output = '[' def json_dump(obj): global output for model in obj: if not isinstance(model, list): # Ignore many to many tables as they are included in the primary # object serialization if "_" not in model.__class__.__name__: # Use Django's built in serializer, and strip off the array # brackets output += serializers.serialize("json", [model])[1:-1]
from datetime import datetime, timedelta from StringIO import StringIO from django.core.management import call_command from django.core.management.base import CommandError from django.test import TestCase from factory.django import get_model from mock import patch from oscar.test.factories import UserFactory from slumber.exceptions import HttpClientError from ecommerce.core.management.commands.sync_hubspot import Command as sync_command from ecommerce.extensions.test.factories import create_basket, create_order from ecommerce.tests.factories import SiteConfigurationFactory SiteConfiguration = get_model('core', 'SiteConfiguration') Basket = get_model('basket', 'Basket') DEFAULT_INITIAL_DAYS = 1 class TestSyncHubspotCommand(TestCase): """ Test sync_hubspot management command. """ order = None hubspot_site_configuration = None def setUp(self): super(TestSyncHubspotCommand, self).setUp() self.hubspot_site_configuration = SiteConfigurationFactory.create(
def get_model_class(definition): # code based on https://github.com/FactoryBoy/factory_boy/blob/371815b219d0f91c3032fdd479fc2ef7d1d3af6b/factory/django.py#L90 if isinstance(definition, str) and '.' in definition: app, model = definition.split('.', 1) return get_model(app, model) return definition