Skip to content

Commit

Permalink
Fix Flake8 errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jwarren116 committed Sep 15, 2017
1 parent 249bbaf commit 02a3d75
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 28 deletions.
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ universal = 1

[flake8]
exclude=waffle/migrations/*,waffle/south_migrations/*
ignore=E731
10 changes: 7 additions & 3 deletions waffle/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,23 @@ def enable_for_all(ma, request, qs):
for f in qs.all():
f.everyone = True
f.save()
enable_for_all.short_description = 'Enable selected flags for everyone.'


def disable_for_all(ma, request, qs):
# Iterate over all objects to cause cache invalidation.
for f in qs.all():
f.everyone = False
f.save()
disable_for_all.short_description = 'Disable selected flags for everyone.'


def delete_individually(ma, request, qs):
# Iterate over all objects to cause cache invalidation.
for f in qs.all():
f.delete()


enable_for_all.short_description = 'Enable selected flags for everyone.'
disable_for_all.short_description = 'Disable selected flags for everyone.'
delete_individually.short_description = 'Delete selected.'


Expand All @@ -49,13 +51,15 @@ def enable_switches(ma, request, qs):
for switch in qs:
switch.active = True
switch.save()
enable_switches.short_description = 'Enable the selected switches.'


def disable_switches(ma, request, qs):
for switch in qs:
switch.active = False
switch.save()


enable_switches.short_description = 'Enable the selected switches.'
disable_switches.short_description = 'Disable the selected switches.'


Expand Down
1 change: 0 additions & 1 deletion waffle/decorators.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,3 @@ def get_response_to_redirect(view):
return redirect(reverse(view)) if view else None
except NoReverseMatch:
return None

4 changes: 3 additions & 1 deletion waffle/management/commands/waffle_sample.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ def handle(self, *args, **options):
percent = options['positionals'][1]

if not (sample_name and percent):
raise CommandError('You need to specify a sample name and percentage.')
raise CommandError(
'You need to specify a sample name and percentage.'
)

try:
percent = float(percent)
Expand Down
14 changes: 10 additions & 4 deletions waffle/management/commands/waffle_switch.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def handle(self, *args, **options):
if options['list_switches']:
self.stdout.write('Switches:')
for switch in Switch.objects.iterator():
self.stdout.write('%s: %s' % (switch.name, 'on' if switch.active else 'off'))
self.stdout.write(
'%s: %s' % (switch.name, 'on' if switch.active else 'off')
)
self.stdout.write('')
return

Expand All @@ -35,17 +37,21 @@ def handle(self, *args, **options):
raise CommandError('You need to specify a switch name and state.')

if state not in ['on', 'off']:
raise CommandError('You need to specify state of switch with "on" or "off".')
raise CommandError(
'You need to specify state of switch with "on" or "off".'
)

active = state == "on"
defaults = {'active': active}

if options['create']:
switch, created = Switch.objects.get_or_create(name=switch_name, defaults=defaults)
switch, created = Switch.objects.get_or_create(name=switch_name,
defaults=defaults)
if created:
self.stdout.write('Creating switch: %s' % switch_name)
else:
try:
switch = Switch.objects.update_or_create(name=switch_name, defaults=defaults)
switch = Switch.objects.update_or_create(name=switch_name,
defaults=defaults)
except Switch.DoesNotExist:
raise CommandError("This switch doesn't exist.")
41 changes: 28 additions & 13 deletions waffle/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,17 @@ class Flag(BaseModel):
Flags are active (or not) on a per-request basis.
"""

name = models.CharField(max_length=100, unique=True,
help_text='The human/computer readable name.')
everyone = models.NullBooleanField(blank=True, help_text=(
'Flip this flag on (Yes) or off (No) for everyone, overriding all '
'other settings. Leave as Unknown to use normally.'))
percent = models.DecimalField(max_digits=3, decimal_places=1, null=True,
blank=True, help_text=(
'A number between 0.0 and 99.9 to indicate a percentage of users for '
'whom this flag will be active.'))
percent = models.DecimalField(
max_digits=3, decimal_places=1, null=True, blank=True,
help_text=('A number between 0.0 and 99.9 to indicate a percentage of '
'users for whom this flag will be active.')
)
testing = models.BooleanField(default=False, help_text=(
'Allow this flag to be set for a session for user testing.'))
superusers = models.BooleanField(default=True, help_text=(
Expand All @@ -126,14 +128,18 @@ class Flag(BaseModel):
'separated list)'))
groups = models.ManyToManyField(Group, blank=True, help_text=(
'Activate this flag for these user groups.'))
users = models.ManyToManyField(settings.AUTH_USER_MODEL, blank=True,
help_text=('Activate this flag for these users.'))
users = models.ManyToManyField(
settings.AUTH_USER_MODEL, blank=True,
help_text=('Activate this flag for these users.')
)
rollout = models.BooleanField(default=False, help_text=(
'Activate roll-out mode?'))
note = models.TextField(blank=True, help_text=(
'Note where this Flag is used.'))
created = models.DateTimeField(default=datetime.now, db_index=True,
help_text=('Date when this Flag was created.'))
created = models.DateTimeField(
default=datetime.now, db_index=True,
help_text=('Date when this Flag was created.')
)
modified = models.DateTimeField(default=datetime.now, help_text=(
'Date when this Flag was last modified.'))

Expand Down Expand Up @@ -274,14 +280,17 @@ class Switch(BaseModel):
Switches are active, or inactive, globally.
"""

name = models.CharField(max_length=100, unique=True,
help_text='The human/computer readable name.')
active = models.BooleanField(default=False, help_text=(
'Is this switch active?'))
note = models.TextField(blank=True, help_text=(
'Note where this Switch is used.'))
created = models.DateTimeField(default=datetime.now, db_index=True,
help_text=('Date when this Switch was created.'))
created = models.DateTimeField(
default=datetime.now, db_index=True,
help_text=('Date when this Switch was created.')
)
modified = models.DateTimeField(default=datetime.now, help_text=(
'Date when this Switch was last modified.'))

Expand All @@ -300,18 +309,24 @@ def is_active(self):


class Sample(BaseModel):
"""A sample is true some percentage of the time, but is not connected
"""A sample of users.
A sample is true some percentage of the time, but is not connected
to users or requests.
"""

name = models.CharField(max_length=100, unique=True,
help_text='The human/computer readable name.')
percent = models.DecimalField(max_digits=4, decimal_places=1, help_text=(
'A number between 0.0 and 100.0 to indicate a percentage of the time '
'this sample will be active.'))
note = models.TextField(blank=True, help_text=(
'Note where this Sample is used.'))
created = models.DateTimeField(default=datetime.now, db_index=True,
help_text=('Date when this Sample was created.'))
created = models.DateTimeField(
default=datetime.now, db_index=True,
help_text=('Date when this Sample was created.')
)
modified = models.DateTimeField(default=datetime.now, help_text=(
'Date when this Sample was last modified.'))

Expand Down
11 changes: 9 additions & 2 deletions waffle/tests/test_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,15 @@ def test_django_tags(self):
self.assertContains(response, 'window.waffle =')

def test_get_nodes_by_type(self):
"""WaffleNode.get_nodes_by_type() should correctly find all child nodes"""
test_template = Template('{% load waffle_tags %}{% switch "x" %}{{ a }}{% else %}{{ b }}{% endswitch %}')
"""WaffleNode.get_nodes_by_type() should find all child nodes."""
test_template = Template(
'{% load waffle_tags %}'
'{% switch "x" %}'
'{{ a }}'
'{% else %}'
'{{ b }}'
'{% endswitch %}'
)
children = test_template.nodelist.get_nodes_by_type(VariableNode)
self.assertEqual(len(children), 2)

Expand Down
8 changes: 4 additions & 4 deletions waffle/tests/test_waffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,7 +298,7 @@ def test_switch_active_from_cache(self):
assert waffle.switch_is_active(switch.name)
queries = len(connection.queries)
assert waffle.switch_is_active(switch.name)
self.assertEqual(queries, len(connection.queries), 'We should only make one query.')
self.assertEqual(queries, len(connection.queries))

def test_switch_inactive_from_cache(self):
"""Do not make two queries for an existing inactive switch."""
Expand All @@ -307,7 +307,7 @@ def test_switch_inactive_from_cache(self):
assert not waffle.switch_is_active(switch.name)
queries = len(connection.queries)
assert not waffle.switch_is_active(switch.name)
self.assertEqual(queries, len(connection.queries), 'We should only make one query.')
self.assertEqual(queries, len(connection.queries))

def test_undefined(self):
assert not waffle.switch_is_active('foo')
Expand All @@ -322,10 +322,10 @@ def test_no_query(self):
assert not Switch.objects.filter(name='foo').exists()
queries = len(connection.queries)
assert not waffle.switch_is_active('foo')
assert len(connection.queries) > queries, 'We should make one query.'
assert len(connection.queries) > queries
queries = len(connection.queries)
assert not waffle.switch_is_active('foo')
self.assertEqual(queries, len(connection.queries), 'We should only make one query.')
self.assertEqual(queries, len(connection.queries))


class SampleTests(TestCase):
Expand Down

0 comments on commit 02a3d75

Please sign in to comment.