diff --git a/dynamic_manipulation/__init__.py b/dynamic_manipulation/__init__.py index 8589c06..8d76f25 100644 --- a/dynamic_manipulation/__init__.py +++ b/dynamic_manipulation/__init__.py @@ -1 +1 @@ -VERSION = '0.1.0' \ No newline at end of file +VERSION = '0.1.1' diff --git a/dynamic_manipulation/dynamic_actions.py b/dynamic_manipulation/dynamic_actions.py index f470475..9a34387 100644 --- a/dynamic_manipulation/dynamic_actions.py +++ b/dynamic_manipulation/dynamic_actions.py @@ -1,10 +1,10 @@ - from dynamic_rules.dynamic_actions import BaseDynamicAction from dynamic_manipulation import models from dynamic_manipulation.models import ManipulationLog -__all__ = ('BaseDynamicManipulation',) +__all__ = ('BaseDynamicManipulation', ) + class BaseDynamicManipulation(BaseDynamicAction): @@ -46,9 +46,7 @@ def do_manipulations(self, *args, **kwargs): pass def log_manipulation(self, side_effect_model=None, side_effect_uri=None): - data = dict( - rule=self.rule_model, - trigger_model=self.trigger_model) + data = dict(rule=self.rule_model, trigger_model=self.trigger_model) if side_effect_uri: data['side_effect_uri'] = side_effect_uri diff --git a/dynamic_manipulation/migrations/0001_initial.py b/dynamic_manipulation/migrations/0001_initial.py index 1b430aa..4ec9548 100644 --- a/dynamic_manipulation/migrations/0001_initial.py +++ b/dynamic_manipulation/migrations/0001_initial.py @@ -1,56 +1,119 @@ # encoding: utf-8 +# flake8: noqa import datetime from south.db import db from south.v2 import SchemaMigration from django.db import models + class Migration(SchemaMigration): def forwards(self, orm): - + # Adding model 'ManipulationLog' - db.create_table('dynamic_manipulation_manipulationlog', ( - ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), - ('rule', self.gf('django.db.models.fields.related.ForeignKey')(related_name='manipulation_logs', to=orm['dynamic_rules.Rule'])), - ('trigger_content_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='manipulation_triggers', to=orm['contenttypes.ContentType'])), - ('trigger_model_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), - ('side_effect_content_type', self.gf('django.db.models.fields.related.ForeignKey')(related_name='manipulation_side_effects', to=orm['contenttypes.ContentType'])), - ('side_effect_model_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), - )) + db.create_table( + 'dynamic_manipulation_manipulationlog', ( + ('id', self.gf('django.db.models.fields.AutoField')(primary_key=True)), + ( + 'rule', self.gf('django.db.models.fields.related.ForeignKey')( + related_name='manipulation_logs', to=orm['dynamic_rules.Rule'] + ) + ), + ( + 'trigger_content_type', self.gf('django.db.models.fields.related.ForeignKey')( + related_name='manipulation_triggers', to=orm['contenttypes.ContentType'] + ) + ), + ('trigger_model_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), + ( + 'side_effect_content_type', self.gf('django.db.models.fields.related.ForeignKey')( + related_name='manipulation_side_effects', to=orm['contenttypes.ContentType'] + ) + ), + ('side_effect_model_id', self.gf('django.db.models.fields.PositiveIntegerField')(db_index=True)), + ) + ) db.send_create_signal('dynamic_manipulation', ['ManipulationLog']) - def backwards(self, orm): - + # Deleting model 'ManipulationLog' db.delete_table('dynamic_manipulation_manipulationlog') - models = { 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + 'Meta': { + 'ordering': "('name',)", + 'unique_together': "(('app_label', 'model'),)", + 'object_name': 'ContentType', + 'db_table': "'django_content_type'" + }, + 'app_label': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }), + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'model': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }), + 'name': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }) }, 'dynamic_manipulation.manipulationlog': { - 'Meta': {'object_name': 'ManipulationLog'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'rule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'manipulation_logs'", 'to': "orm['dynamic_rules.Rule']"}), - 'side_effect_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'manipulation_side_effects'", 'to': "orm['contenttypes.ContentType']"}), - 'side_effect_model_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), - 'trigger_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'manipulation_triggers'", 'to': "orm['contenttypes.ContentType']"}), - 'trigger_model_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + 'Meta': { + 'object_name': 'ManipulationLog' + }, + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'rule': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'related_name': "'manipulation_logs'", + 'to': "orm['dynamic_rules.Rule']" + } + ), + 'side_effect_content_type': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'related_name': "'manipulation_side_effects'", + 'to': "orm['contenttypes.ContentType']" + } + ), + 'side_effect_model_id': ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True' + }), + 'trigger_content_type': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'related_name': "'manipulation_triggers'", + 'to': "orm['contenttypes.ContentType']" + } + ), + 'trigger_model_id': ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True' + }) }, 'dynamic_rules.rule': { - 'Meta': {'object_name': 'Rule'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'Meta': { + 'object_name': 'Rule' + }, + 'content_type': + ('django.db.models.fields.related.ForeignKey', [], { + 'to': "orm['contenttypes.ContentType']" + }), 'dynamic_fields': ('django_fields.fields.PickleField', [], {}), - 'group_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'key': ('django.db.models.fields.CharField', [], {'max_length': '50'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + 'group_object_id': ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True' + }), + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'key': ('django.db.models.fields.CharField', [], { + 'max_length': '50' + }), + 'name': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }) } } diff --git a/dynamic_manipulation/migrations/0002_auto__add_field_manipulationlog_side_effect_uri__chg_field_manipulatio.py b/dynamic_manipulation/migrations/0002_auto__add_field_manipulationlog_side_effect_uri__chg_field_manipulatio.py index 422c2a0..1301331 100644 --- a/dynamic_manipulation/migrations/0002_auto__add_field_manipulationlog_side_effect_uri__chg_field_manipulatio.py +++ b/dynamic_manipulation/migrations/0002_auto__add_field_manipulationlog_side_effect_uri__chg_field_manipulatio.py @@ -1,4 +1,5 @@ # -*- coding: utf-8 -*- +# flake8: noqa import datetime from south.db import db from south.v2 import SchemaMigration @@ -10,53 +11,122 @@ class Migration(SchemaMigration): def forwards(self, orm): # Adding field 'ManipulationLog.side_effect_uri' - db.add_column('dynamic_manipulation_manipulationlog', 'side_effect_uri', - self.gf('django.db.models.fields.URLField')(max_length=200, null=True, blank=True), - keep_default=False) - + db.add_column( + 'dynamic_manipulation_manipulationlog', + 'side_effect_uri', + self.gf('django.db.models.fields.URLField')(max_length=200, null=True, blank=True), + keep_default=False + ) # Changing field 'ManipulationLog.side_effect_content_type' - db.alter_column('dynamic_manipulation_manipulationlog', 'side_effect_content_type_id', self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['contenttypes.ContentType'])) + db.alter_column( + 'dynamic_manipulation_manipulationlog', 'side_effect_content_type_id', + self.gf('django.db.models.fields.related.ForeignKey')(null=True, to=orm['contenttypes.ContentType']) + ) # Changing field 'ManipulationLog.side_effect_model_id' - db.alter_column('dynamic_manipulation_manipulationlog', 'side_effect_model_id', self.gf('django.db.models.fields.PositiveIntegerField')(null=True)) + db.alter_column( + 'dynamic_manipulation_manipulationlog', + 'side_effect_model_id', + self.gf('django.db.models.fields.PositiveIntegerField')(null=True) + ) def backwards(self, orm): db.delete_column('dynamic_manipulation_manipulationlog', 'side_effect_uri') for record in orm.ManipulationLog.objects.filter(side_effect_model_id=None): record.delete() - - - models = { 'contenttypes.contenttype': { - 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, - 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + 'Meta': { + 'ordering': "('name',)", + 'unique_together': "(('app_label', 'model'),)", + 'object_name': 'ContentType', + 'db_table': "'django_content_type'" + }, + 'app_label': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }), + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'model': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }), + 'name': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }) }, 'dynamic_manipulation.manipulationlog': { - 'Meta': {'object_name': 'ManipulationLog'}, - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'rule': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'manipulation_logs'", 'to': "orm['dynamic_rules.Rule']"}), - 'side_effect_content_type': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'manipulation_side_effects'", 'null': 'True', 'to': "orm['contenttypes.ContentType']"}), - 'side_effect_model_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True', 'null': 'True', 'blank': 'True'}), - 'side_effect_uri': ('django.db.models.fields.URLField', [], {'max_length': '200', 'null': 'True', 'blank': 'True'}), - 'trigger_content_type': ('django.db.models.fields.related.ForeignKey', [], {'related_name': "'manipulation_triggers'", 'to': "orm['contenttypes.ContentType']"}), - 'trigger_model_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}) + 'Meta': { + 'object_name': 'ManipulationLog' + }, + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'rule': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'related_name': "'manipulation_logs'", + 'to': "orm['dynamic_rules.Rule']" + } + ), + 'side_effect_content_type': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'blank': 'True', + 'related_name': "'manipulation_side_effects'", + 'null': 'True', + 'to': "orm['contenttypes.ContentType']" + } + ), + 'side_effect_model_id': + ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True', + 'null': 'True', + 'blank': 'True' + }), + 'side_effect_uri': + ('django.db.models.fields.URLField', [], { + 'max_length': '200', + 'null': 'True', + 'blank': 'True' + }), + 'trigger_content_type': ( + 'django.db.models.fields.related.ForeignKey', [], { + 'related_name': "'manipulation_triggers'", + 'to': "orm['contenttypes.ContentType']" + } + ), + 'trigger_model_id': ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True' + }) }, 'dynamic_rules.rule': { - 'Meta': {'object_name': 'Rule'}, - 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': "orm['contenttypes.ContentType']"}), + 'Meta': { + 'object_name': 'Rule' + }, + 'content_type': + ('django.db.models.fields.related.ForeignKey', [], { + 'to': "orm['contenttypes.ContentType']" + }), 'dynamic_fields': ('django_fields.fields.PickleField', [], {}), - 'group_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}), - 'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), - 'key': ('django.db.models.fields.CharField', [], {'max_length': '50'}), - 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}), - 'secondary_object_id': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0', 'db_index': 'True'}) + 'group_object_id': ('django.db.models.fields.PositiveIntegerField', [], { + 'db_index': 'True' + }), + 'id': ('django.db.models.fields.AutoField', [], { + 'primary_key': 'True' + }), + 'key': ('django.db.models.fields.CharField', [], { + 'max_length': '50' + }), + 'name': ('django.db.models.fields.CharField', [], { + 'max_length': '100' + }), + 'secondary_object_id': + ('django.db.models.fields.PositiveIntegerField', [], { + 'default': '0', + 'db_index': 'True' + }) } } - complete_apps = ['dynamic_manipulation'] \ No newline at end of file + complete_apps = ['dynamic_manipulation'] diff --git a/dynamic_manipulation/models.py b/dynamic_manipulation/models.py index 21e48a2..3a94ae3 100644 --- a/dynamic_manipulation/models.py +++ b/dynamic_manipulation/models.py @@ -12,7 +12,9 @@ class ManipulationLog(models.Model): trigger_model_id = models.PositiveIntegerField(db_index=True) trigger_model = generic.GenericForeignKey(fk_field='trigger_model_id', ct_field='trigger_content_type') - side_effect_content_type = models.ForeignKey('contenttypes.ContentType', related_name="manipulation_side_effects", null=True, blank=True) + side_effect_content_type = models.ForeignKey( + 'contenttypes.ContentType', related_name="manipulation_side_effects", null=True, blank=True + ) side_effect_model_id = models.PositiveIntegerField(db_index=True, null=True, blank=True) side_effect_model = generic.GenericForeignKey(fk_field='side_effect_model_id', ct_field='side_effect_content_type') @@ -22,4 +24,4 @@ class ManipulationLog(models.Model): def clean(self): if not self.side_effect_uri and not self.side_effect_model: - raise ValidationError("Side effect URI -or- Model is required.") \ No newline at end of file + raise ValidationError("Side effect URI -or- Model is required.") diff --git a/dynamic_manipulation/tests/test_dynamic_actions.py b/dynamic_manipulation/tests/test_dynamic_actions.py index ce33bcb..213739e 100644 --- a/dynamic_manipulation/tests/test_dynamic_actions.py +++ b/dynamic_manipulation/tests/test_dynamic_actions.py @@ -1,13 +1,11 @@ - import mock from django.utils import unittest from dynamic_manipulation.dynamic_actions import BaseDynamicManipulation from dynamic_manipulation import models -__all__ = ( - 'BaseDynamicManipulationTests', -) +__all__ = ('BaseDynamicManipulationTests', ) + class BaseDynamicManipulationTests(unittest.TestCase): @@ -51,14 +49,18 @@ def test_clear_existing_calls_clear_side_effect_for_each_log(self, get_by_rule, get_by_rule.return_value = logs self.manipulation.clear_existing() - self.assertEqual([ - ((log_one.side_effect_model,), {}), - ((log_two.side_effect_model,), {}), - ], clear_side_effect.call_args_list) + self.assertEqual( + [ + ((log_one.side_effect_model, ), {}), + ((log_two.side_effect_model, ), {}), + ], clear_side_effect.call_args_list + ) @mock.patch.object(BaseDynamicManipulation, 'clear_side_effect_uri') @mock.patch('dynamic_manipulation.models.ManipulationLog.objects.get_by_rule') - def test_clear_existing_calls_clear_side_effect_uri_when_side_effect_uri_and_no_model(self, get_by_rule, clear_side_effect): + def test_clear_existing_calls_clear_side_effect_uri_when_side_effect_uri_and_no_model( + self, get_by_rule, clear_side_effect + ): log_one = models.ManipulationLog(side_effect_uri='one') log_two = models.ManipulationLog(side_effect_uri='two') logs = mock.MagicMock() @@ -67,15 +69,19 @@ def test_clear_existing_calls_clear_side_effect_uri_when_side_effect_uri_and_no_ get_by_rule.return_value = logs self.manipulation.clear_existing() - self.assertEqual([ - ((log_one.side_effect_uri,), {}), - ((log_two.side_effect_uri,), {}), - ], clear_side_effect.call_args_list) + self.assertEqual( + [ + ((log_one.side_effect_uri, ), {}), + ((log_two.side_effect_uri, ), {}), + ], clear_side_effect.call_args_list + ) @mock.patch.object(BaseDynamicManipulation, 'clear_side_effect_model') @mock.patch.object(BaseDynamicManipulation, 'clear_side_effect_uri') @mock.patch('dynamic_manipulation.models.ManipulationLog.objects.get_by_rule') - def test_clear_existing_calls_clear_side_effect_uri_and_model_when_both_exist(self, get_by_rule, clear_uri, clear_model): + def test_clear_existing_calls_clear_side_effect_uri_and_model_when_both_exist( + self, get_by_rule, clear_uri, clear_model + ): log_one = models.ManipulationLog(side_effect_uri='one') log_two = mock.Mock(spec_set=models.ManipulationLog()) log_two.side_effect_uri = "" @@ -86,10 +92,10 @@ def test_clear_existing_calls_clear_side_effect_uri_and_model_when_both_exist(se self.manipulation.clear_existing() self.assertEqual([ - ((log_one.side_effect_uri,), {}), + ((log_one.side_effect_uri, ), {}), ], clear_uri.call_args_list) self.assertEqual([ - ((log_two.side_effect_model,), {}), + ((log_two.side_effect_model, ), {}), ], clear_model.call_args_list) def test_clear_side_effect_model_calls_delete_on_model(self): @@ -108,7 +114,8 @@ def test_log_manipulation_logs_manipulation_with_rule_trigger_model_and_side_eff create_log.assert_called_once_with( rule=self.rule_model, trigger_model=self.trigger_model, - side_effect_model=side_effect_model,) + side_effect_model=side_effect_model, + ) @mock.patch.object(models.ManipulationLog.objects, 'create') def test_log_manipulation_logs_manipulation_with_rule_trigger_model_and_side_effect_uri(self, create_log): @@ -116,7 +123,8 @@ def test_log_manipulation_logs_manipulation_with_rule_trigger_model_and_side_eff create_log.assert_called_once_with( rule=self.rule_model, trigger_model=self.trigger_model, - side_effect_uri="asdf",) + side_effect_uri="asdf", + ) def test_clear_side_effect_uri_raises_not_implemented(self): with self.assertRaises(NotImplementedError): diff --git a/dynamic_manipulation/tests/unit/model_tests.py b/dynamic_manipulation/tests/unit/model_tests.py index 69721ec..7e8a163 100644 --- a/dynamic_manipulation/tests/unit/model_tests.py +++ b/dynamic_manipulation/tests/unit/model_tests.py @@ -10,8 +10,7 @@ def test_requires_side_effect_model_or_uri(self): log = ManipulationLog() with self.assertRaises(ValidationError) as error_context: log.clean() - self.assertEqual(["Side effect URI -or- Model is required."], - error_context.exception.messages) + self.assertEqual(["Side effect URI -or- Model is required."], error_context.exception.messages) def test_valid_when_side_effect_uri(self): log = ManipulationLog(side_effect_uri="foo") @@ -24,5 +23,5 @@ def test_valid_when_side_effect_model(self): log = ManipulationLog() log.side_effect_model = side_effect_model with self.assertRaises(AssertionError): - with self.assertRaises(ValidationError) as e: + with self.assertRaises(ValidationError): log.clean() diff --git a/example/manage.py b/example/manage.py deleted file mode 100755 index 3e4eedc..0000000 --- a/example/manage.py +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env python -from django.core.management import execute_manager -import imp -try: - imp.find_module('settings') # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n" % __file__) - sys.exit(1) - -import settings - -if __name__ == "__main__": - execute_manager(settings) diff --git a/example/pycharm_settings.py b/example/pycharm_settings.py deleted file mode 100644 index 33a6ed9..0000000 --- a/example/pycharm_settings.py +++ /dev/null @@ -1,3 +0,0 @@ -from example.settings import * - -TEST_RUNNER = 'pycharm_testrunner.PyCharmTestSuiteRunner' diff --git a/example/sample/dynamic_actions.py b/example/sample/dynamic_actions.py index 0017cb9..7f48baa 100644 --- a/example/sample/dynamic_actions.py +++ b/example/sample/dynamic_actions.py @@ -1,4 +1,3 @@ - from django import forms from dynamic_rules import site @@ -6,21 +5,21 @@ from dynamic_manipulation.dynamic_actions import BaseDynamicManipulation from sample import models + @site.register class FreeShippingPromotion(BaseDynamicManipulation): key = "free_shipping_promo" trigger_model_name = 'shopping_cart' fields = { - 'cart_total':forms.DecimalField(), - 'shipping_charge':forms.DecimalField(), + 'cart_total': forms.DecimalField(), + 'shipping_charge': forms.DecimalField(), } def do_manipulations(self, *args, **kwargs): if self.shopping_cart.total < self.rule_model.dynamic_fields['cart_total']: shipping_charge_amount = self.rule_model.dynamic_fields['shipping_charge'] - shipping_item = models.Item.objects.create(name="shipping charge", amount=shipping_charge_amount, cart=self.shopping_cart) + shipping_item = models.Item.objects.create( + name="shipping charge", amount=shipping_charge_amount, cart=self.shopping_cart + ) self.log_manipulation(shipping_item) - - - diff --git a/example/sample/features/manipulation_steps.py b/example/sample/features/manipulation_steps.py index 515712c..0145e9f 100644 --- a/example/sample/features/manipulation_steps.py +++ b/example/sample/features/manipulation_steps.py @@ -1,31 +1,36 @@ - from decimal import Decimal from hamcrest import assert_that, equal_to from lettuce import step, world from sample import models + @step(u'Given a shopping cart named "(.*)"') def given_a_shopping_cart_named(step, cart_name): world.cart = models.Cart.objects.create(name=cart_name) + @step(u'(?:And|When) I add an item with a name of "(.*)" and price of "(.*)" dollars') def given_a_shopping_cart_with_a_total_of_amount(step, item_name, amount): models.Item.objects.create(name=item_name, amount=amount, cart=world.cart) + @step(u'And I view my shopping cart') def view_shopping_cart(step): world.cart.view_cart() + @step(u'Then I expect the cart total to be "(.*)" dollars') def then_i_expect_a_discount_to_be_applied_to_the_shopping_cart(step, amount): assert_that(world.cart.total, equal_to(Decimal(amount))) + @step(u'Given I have a shopping cart with a total of "(.*)" dollars') def given_i_have_a_shopping_cart_with_a_total(step, cart_total): world.cart = models.Cart.objects.create(name="new cart") models.Item.objects.create(name='new item', amount=cart_total, cart=world.cart) + @step(u'And I have a "(.*)" dollar shipping charge') def and_i_have_a_shipping_charge(step, shipping_charge): world.cart.view_cart() diff --git a/example/sample/features/terrain.py b/example/sample/features/terrain.py index aadb6ab..1bb7d13 100644 --- a/example/sample/features/terrain.py +++ b/example/sample/features/terrain.py @@ -8,17 +8,21 @@ from sample import dynamic_actions from south.management.commands import patch_for_test_db_setup + @before.all def setup_test_database(): patch_for_test_db_setup() connection.creation.create_test_db(verbosity=1, autoclobber=True) + @before.each_scenario def clean_db(scenario): call_command('flush', interactive=False) current_site = site_models.Site.objects.get_current() - rule_models.Rule.objects.create(group_object=current_site, - name="Free Shipping on orders over $10", - key=dynamic_actions.FreeShippingPromotion.key, - dynamic_fields=dict(cart_total=10, shipping_charge=2)) + rule_models.Rule.objects.create( + group_object=current_site, + name="Free Shipping on orders over $10", + key=dynamic_actions.FreeShippingPromotion.key, + dynamic_fields=dict(cart_total=10, shipping_charge=2) + ) diff --git a/example/sample/models.py b/example/sample/models.py index 8ff6a48..e5a6892 100644 --- a/example/sample/models.py +++ b/example/sample/models.py @@ -3,6 +3,7 @@ from dynamic_rules import models as rule_models from django.contrib.sites import models as site_models + class Cart(models.Model): name = models.CharField(max_length=30) @@ -17,8 +18,8 @@ def view_cart(self): def total(self): return sum(i.amount for i in self.items.all()) + class Item(models.Model): cart = models.ForeignKey(Cart, related_name="items") name = models.CharField(max_length=30) amount = models.DecimalField(decimal_places=2, max_digits=10) - \ No newline at end of file diff --git a/example/settings.py b/example/settings.py index 62cf8be..fc7b306 100644 --- a/example/settings.py +++ b/example/settings.py @@ -23,19 +23,13 @@ ROOT_URLCONF = 'urls' -TEMPLATE_DIRS = ( - abspath(join(parent, 'templates')), -) +TEMPLATE_DIRS = (abspath(join(parent, 'templates')), ) SITE_ID = 1 -LETTUCE_APPS = ( - 'sample', -) +LETTUCE_APPS = ('sample', ) -PROJECT_APPS = ( - 'dynamic_manipulation', -) +PROJECT_APPS = ('dynamic_manipulation', ) INSTALLED_APPS = ( 'django.contrib.auth', @@ -44,9 +38,7 @@ 'django.contrib.admin', 'django.contrib.sites', 'django.contrib.staticfiles', - 'lettuce.django', - 'dynamic_manipulation.tests.test_app', 'dynamic_rules', 'djadmin_ext', @@ -54,7 +46,7 @@ ) + LETTUCE_APPS + PROJECT_APPS try: - import south + import south # noqa F401 INSTALLED_APPS = ('south', ) + INSTALLED_APPS SOUTH_TESTS_MIGRATE = False except ImportError: diff --git a/example/urls.py b/example/urls.py index 964bcf2..c9e8265 100644 --- a/example/urls.py +++ b/example/urls.py @@ -1,11 +1,7 @@ -from django.conf.urls.defaults import patterns, include, url - +from django.conf.urls.defaults import patterns from django.contrib import admin -admin.autodiscover() - import dynamic_rules -dynamic_rules.autodiscover() -urlpatterns = patterns('', - # url(r'^admin/', include(admin.site.urls)), -) +admin.autodiscover() +dynamic_rules.autodiscover() +urlpatterns = patterns('', ) diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..2605e37 --- /dev/null +++ b/manage.py @@ -0,0 +1,10 @@ +#!/usr/bin/env python +import os +import sys + +if __name__ == "__main__": + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "example.settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/requirements/ci.txt b/requirements/ci.txt index 870ed09..bad895e 100644 --- a/requirements/ci.txt +++ b/requirements/ci.txt @@ -1,4 +1,4 @@ -r dev.txt -pep8 -pyflakes -nosexcover +pep8>=1.6.2,<2 +pyflakes>=1.0.0,<2 +nosexcover>=1.0.10,<2 diff --git a/requirements/dev.txt b/requirements/dev.txt index 577661c..378a0e2 100644 --- a/requirements/dev.txt +++ b/requirements/dev.txt @@ -1,7 +1,7 @@ -r dist.txt -mock -lettuce -pyhamcrest -django_nose -pycharm_testrunner -bpython \ No newline at end of file +mock>=1.0.1,<2 +lettuce>=0.2.20,<1 +pyhamcrest>=1.8.0,<2 +django-nose==1.4.3 +pycharm-testrunner>=0.0.1,<1 +bpython>=0.12,<1 diff --git a/requirements/dist.txt b/requirements/dist.txt index 9d6bcae..73aec04 100644 --- a/requirements/dist.txt +++ b/requirements/dist.txt @@ -1,2 +1,2 @@ django<1.5.0 -django-dynamic-rules>=0.2.0 +django-dynamic-rules>=0.2.0,<1 diff --git a/setup.py b/setup.py index 11b16b7..a543bbd 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,6 @@ from setuptools import find_packages from dynamic_manipulation import VERSION - setup( name="django-dynamic-manipulation", version=VERSION, @@ -15,7 +14,7 @@ install_requires=file('requirements/dist.txt', 'r').read(), zip_safe=False, include_package_data=True, - classifiers = [ + classifiers=[ "Development Status :: 5 - Production/Stable", "Environment :: Web Environment", "Framework :: Django", @@ -27,4 +26,3 @@ "Topic :: Software Development :: Libraries :: Application Frameworks", ] ) -