Skip to content

Commit

Permalink
Merge branch 'master' of github.com:maxolasersquad/orthosie
Browse files Browse the repository at this point in the history
  • Loading branch information
maxolasersquad committed Mar 14, 2015
2 parents f091c84 + fbe6623 commit 7648bb8
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 81 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.pyc
orthosie/orthosie.db
*.nja
5 changes: 5 additions & 0 deletions inventory/models.py
Expand Up @@ -17,6 +17,7 @@

from django.db import models


class Vendor(models.Model):
name = models.CharField(max_length=50, unique=True)

Expand All @@ -29,6 +30,7 @@ def natural_key(self):
class Meta:
ordering = ['name']


class Item(models.Model):
name = models.CharField(max_length=30)
price = models.DecimalField(max_digits=17, decimal_places=2)
Expand All @@ -41,16 +43,19 @@ def __unicode__(self):
class Meta:
ordering = ['name']


class Grocery(Item):
upc = models.CharField(max_length=30, unique=True)
vendor = models.ForeignKey(Vendor, default=None, blank=True, null=True)


class Produce(Item):
plu = models.IntegerField(max_length=5, unique=True)
variety = models.CharField(max_length=100)
size = models.CharField(max_length=30, null=True)
botanical = models.CharField(max_length=100, null=True)


class Upc:
def __init__(self, upc):
self.upc = upc
Expand Down
26 changes: 22 additions & 4 deletions inventory/tests.py
Expand Up @@ -19,38 +19,56 @@
from inventory.models import Vendor
from inventory.models import Grocery
from inventory.models import Upc
from inventory.models import Produce


class VendorTest(TestCase):
def setUp(self):
self.vendor = Vendor(name='Brand X')

def test_vendor_name(self):
self.assertEqual(self.vendor.name, 'Brand X')


class GroceryTest(TestCase):
def setUp(self):
self.vendor = Vendor(name='Brand X')
self.grocery = Grocery(upc='12345', name='Product X', vendor=self.vendor)
self.grocery = Grocery(
upc='12345',
name='Product X',
vendor=self.vendor
)

def test_grocery_upc(self):
self.assertEqual(self.grocery.upc, '12345')

def test_grocery_name(self):
self.assertEqual(self.grocery.name, 'Product X')

def test_grocery_vendor(self):
self.assertEqual(self.grocery.vendor.name, 'Brand X')


class ProduceTest(TestCase):
def setUp(self):
self.produce = Produce(name='Kumquat', plu=4303, botanical='Fortunella spp.')
self.produce = Produce(
name='Kumquat',
plu=4303,
botanical='Fortunella spp.'
)


class UpcTest(TestCase):
def test_verify_correct_check_digit(self):
self.test_upc = Upc('008274000061')
self.assertEqual(self.test_upc.get_check_digit(), 1)
self.test_upc = Upc('090341100019')
self.assertEqual(self.test_upc.get_check_digit(), 9)

def test_verify_check_digit_passes(self):
self.test_upc = Upc('008274000061')
self.assertTrue(self.test_upc.verify_check_digit())

def test_verify_check_digit_fails(self):
self.test_upc = Upc('008274000065')
self.assertFalse(self.test_upc.verify_check_digit())
self.assertFalse(self.test_upc.verify_check_digit())
26 changes: 24 additions & 2 deletions orthosie/serializers.py
Expand Up @@ -19,27 +19,49 @@
from register.models import Shift, Transaction, LineItem
from rest_framework import serializers


class ItemSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Item
fields = ('url', 'upc', 'name', 'price', 'scalable', 'taxable', 'vendor')
fields = (
'url',
'upc',
'name',
'price',
'scalable',
'taxable',
'vendor'
)


class VendorSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Vendor
fields = ('url', 'name')


class ShiftSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Shift
fields = ('url', 'begin_date', 'finish_date')


class TransactionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Transaction
fields = ('url', 'shift', 'begin_date', 'finish_date', 'status')


class LineItemSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = LineItem
fields = ('url', 'transaction', 'upc', 'quantity', 'scale', 'description', 'price', 'item')
fields = (
'url',
'transaction',
'upc',
'quantity',
'scale',
'description',
'price',
'item'
)
6 changes: 3 additions & 3 deletions orthosie/settings.py
Expand Up @@ -66,7 +66,7 @@

# Additional locations of static files
STATICFILES_DIRS = (
os.path.join(os.path.dirname(__file__), '../static').replace('\\','/'),
os.path.join(os.path.dirname(__file__), '../static').replace('\\', '/'),
# Put strings here, like "/home/html/static" or "C:/www/django/static".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
Expand Down Expand Up @@ -106,8 +106,8 @@
WSGI_APPLICATION = 'orthosie.wsgi.application'

TEMPLATE_DIRS = (
os.path.join(os.path.dirname(__file__), '../templates').replace('\\','/'),
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
os.path.join(os.path.dirname(__file__), '../templates').replace('\\', '/'),
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".s
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Expand Down
23 changes: 19 additions & 4 deletions orthosie/urls.py
Expand Up @@ -13,18 +13,33 @@
url(r'^items/$', ItemList.as_view(), name='item-list'),
url(r'^items/(?P<pk>\d+)/$', ItemDetail.as_view(), name='item-detail'),
url(r'^vendors/$', VendorList.as_view(), name='vendor-list'),
url(r'^vendors/(?P<pk>\d+)/$', VendorDetail.as_view(), name='vendor-detail'),
url(
r'^vendors/(?P<pk>\d+)/$',
VendorDetail.as_view(),
name='vendor-detail'
),
url(r'^shifts/$', ShiftList.as_view(), name='shift-list'),
url(r'^shifts/(?P<pk>\d+)/$', ShiftDetail.as_view(), name='shift-detail'),
url(r'^transactions/$', TransactionList.as_view(), name='transaction-list'),
url(r'^transactions/(?P<pk>\d+)/$', TransactionDetail.as_view(), name='transaction-detail'),
url(
r'^transactions/(?P<pk>\d+)/$',
TransactionDetail.as_view(),
name='transaction-detail'
),
url(r'^line_items/$', LineItemList.as_view(), name='lineitem-list'),
url(r'^line_items/(?P<pk>\d+)/$', LineItemDetail.as_view(), name='lineitem-detail'),
url(
r'^line_items/(?P<pk>\d+)/$',
LineItemDetail.as_view(),
name='lineitem-detail'
),

)

urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json', 'api'])

urlpatterns += patterns('',
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
url(
r'^api-auth/',
include('rest_framework.urls', namespace='rest_framework')
)
)
13 changes: 12 additions & 1 deletion orthosie/views.py
Expand Up @@ -23,6 +23,7 @@
from rest_framework.response import Response
from orthosie.serializers import ItemSerializer, VendorSerializer, ShiftSerializer, TransactionSerializer, LineItemSerializer


@api_view(['GET'])
def api_root(request, format=None):
"""
Expand All @@ -36,72 +37,82 @@ def api_root(request, format=None):
'lineitem': reverse('lineitem-list', request=request),
})


class ItemList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of items.
"""
model = Item
serializer_class = ItemSerializer


class ItemDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single item.
"""
model = Item
serializer_class = ItemSerializer


class VendorList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of vendors.
"""
model = Vendor
serializer_class = VendorSerializer


class VendorDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single vendor.
"""
model = Vendor
serializer_class = VendorSerializer


class ShiftList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of shift.
"""
model = Shift
serializer_class = ShiftSerializer


class ShiftDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single vendor.
"""
model = Shift
serializer_class = ShiftSerializer


class TransactionList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of transaction.
"""
model = Transaction
serializer_class = TransactionSerializer


class TransactionDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single transaction.
"""
model = Transaction
serializer_class = TransactionSerializer


class LineItemList(generics.ListCreateAPIView):
"""
API endpoint that represents a list of line items.
"""
model = LineItem
serializer_class = LineItemSerializer


class LineItemDetail(generics.RetrieveUpdateDestroyAPIView):
"""
API endpoint that represents a single line items.
"""
model = LineItem
serializer_class = LineItemSerializer
serializer_class = LineItemSerializer

0 comments on commit 7648bb8

Please sign in to comment.