Skip to content

Commit

Permalink
Add a field for default beer color inside the style model
Browse files Browse the repository at this point in the history
  • Loading branch information
drewbrew committed May 29, 2019
1 parent 2d7b11d commit 3116317
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 2 deletions.
18 changes: 18 additions & 0 deletions beers/migrations/0028_style_default_color.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.1 on 2019-05-18 13:41

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('beers', '0027_add_alt_innerspace_names'),
]

operations = [
migrations.AddField(
model_name='style',
name='default_color',
field=models.CharField(blank=True, max_length=9, verbose_name='HTML color (in hex) to use if the beer has no known color'),
),
]
5 changes: 5 additions & 0 deletions beers/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

class Style(models.Model):
name = CITextField(unique=True)
default_color = models.CharField(
'HTML color (in hex) to use if the beer has no known color',
max_length=9, # #00112233 -> RGBA
blank=True,
)

def merge_from(self, other_styles):
alt_names = []
Expand Down
1 change: 1 addition & 0 deletions beers/test/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
class StyleFactory(factory.django.DjangoModelFactory):

name = factory.Sequence(lambda n: 'style %d' % n)
default_color = factory.Sequence(lambda n: '#{:0>6X}'.format(n))

class Meta:
model = Style
Expand Down
10 changes: 8 additions & 2 deletions beers/test/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from hsv_dot_beer.users.test.factories import UserFactory
from taps.test.factories import TapFactory
from beers.serializers import ManufacturerSerializer
from .factories import ManufacturerFactory, BeerFactory
from .factories import ManufacturerFactory, BeerFactory, StyleFactory

fake = Faker()

Expand Down Expand Up @@ -62,7 +62,8 @@ def test_patch(self):

class BeerDetailTestCase(APITestCase):
def setUp(self):
self.beer = BeerFactory()
self.style = StyleFactory()
self.beer = BeerFactory(style=self.style)
self.url = reverse(
'beer-detail', kwargs={'pk': self.beer.pk},
)
Expand All @@ -71,6 +72,11 @@ def setUp(self):
HTTP_AUTHORIZATION=f'Token {self.user.auth_token}'
)

def test_style_embedded(self):
response = self.client.get(self.url)
eq_(response.status_code, 200)
eq_(response.data['style']['default_color'], self.style.default_color)

def test_patch(self):
data = {
'name': 'a beer',
Expand Down

0 comments on commit 3116317

Please sign in to comment.