Commit f5bd0e95 authored by lizonr1's avatar lizonr1

Add peb8 tests

parent f357a71b
from django.contrib import admin
# Register your models here.
from App.loyaltyMe.models import Beacon
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
......@@ -15,5 +14,6 @@ class Command(BaseCommand):
print("Creating Beacons")
for beacon in beacons:
print('Create {0}'.format(beacon[1]))
new_beacon = Beacon.objects.create(uuid=beacon[0], name=beacon[1], description=beacon[2], major=beacon[3], minor=beacon[4])
new_beacon = Beacon.objects.create(uuid=beacon[0], name=beacon[1], description=beacon[2], major=beacon[3],
minor=beacon[4])
new_beacon.save()
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Offer, Product, Localization
from App.loyaltyMe.models import Localization
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
localizations = [
['0.0000', '10.0000', 'Kraków', 'Makowicka', '55' ],
['10.0000', '0.0000', 'Kraków', 'Rynek', '15' ],
['0.0000', '10.0000', 'Kraków', 'Makowicka', '55'],
['10.0000', '0.0000', 'Kraków', 'Rynek', '15'],
]
print("Creating Localizations")
for localization in localizations:
print('Create {0}'.format(localization[0]))
new_localization = Localization.objects.create(latitude=localization[0], longitude=localization[1], city=localization[2], road=localization[3], road_number =localization[4])
new_localization = Localization.objects.create(latitude=localization[0], longitude=localization[1],
city=localization[2], road=localization[3],
road_number=localization[4])
new_localization.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import Offer, Product
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
offers = [
#'name',products
['Oferta1', ['Kawa Latte', 'Herbata'] ],
['Oferta2', ['Ciasto', 'Espresso'] ],
# 'name',products
['Oferta1', ['Kawa Latte', 'Herbata']],
['Oferta2', ['Ciasto', 'Espresso']],
]
print("Creating Offers")
for offer in offers:
......
from App.loyaltyMe.models import Place, Offer, Promotion, PromotionSet, Localization, Beacon
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Place, Offer, PromotionSet, Localization, Beacon
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
places = [
#['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1' , 'Makowicka', 'hPUL'],
['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2' ,'Makowicka', 'CeH3'],
['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Rynek', None],
['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta1', 'Promocja1', 'Makowicka', None ],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description', 'Oferta2', 'Promocja2', 'Rynek', None],
# ['name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotions'],
['Kocia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta1', 'Promocja1', 'Makowicka', 'hPUL'],
['Kafcia u Olczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta2', 'Promocja2', 'Makowicka', 'CeH3'],
['Psia Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta1', 'Promocja1', 'Rynek', None],
['Kafcia u Iwczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta2', 'Promocja2', 'Rynek', None],
['Lemingowa Kawiarnia', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta1', 'Promocja1', 'Makowicka', None],
['Kafcia u Ewelinczaka', 'Cafeteria', '/static/img/photo_1.jpg', '/static/img/photo_1.jpg', 'description',
'Oferta2', 'Promocja2', 'Rynek', None],
]
print("Creating Places")
for place in places:
......@@ -25,6 +31,8 @@ class Command(BaseCommand):
if place[8]:
beacon = Beacon.objects.filter(name=place[8])[0]
else:
beacon=None
new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3], description=place[4], offer=offer, promotion=promotion_set, localization=localization, beacon=beacon)
beacon = None
new_place = Place.objects.create(name=place[0], type=place[1], screen_img=place[2], logo_img=place[3],
description=place[4], offer=offer, promotion=promotion_set,
localization=localization, beacon=beacon)
new_place.save()
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Product
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
products = [
#['name', 'description', 'price', 'img' ],
# ['name', 'description', 'price', 'img' ],
['Kawa Latte', 'Z nutą czekolady', '7 zł', '/static/img/photo_1.jpg'],
['Herbata', 'Z nutą czekolady', '4 zł', '/static/img/photo_1.jpg'],
['Ciasto', 'Z nutą czekolady', '5 zł', '/static/img/photo_1.jpg'],
......@@ -17,5 +17,6 @@ class Command(BaseCommand):
print("Creating Products")
for product in products:
print('Create {0}'.format(product[0]))
new_product = Product.objects.create(name=product[0], description=product[1], price=product[2], img=product[3])
new_product = Product.objects.create(name=product[0], description=product[1], price=product[2],
img=product[3])
new_product.save()
from App.loyaltyMe.models import Promotion
from datetime import datetime
from django.core.management.base import BaseCommand
from App.loyaltyMe.models import Promotion
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
promotions = [
#[name, description, code, img, status]
['10%', 'Zniżka 10%', '5ac5','/static/img/photo_1.jpg' , 'New', '200', None, None],
['20%', 'Zniżka 20%', '5ac6','/static/img/photo_1.jpg' , 'New', None, None, None],
['50%', 'Zniżka 50%', '5ac7','/static/img/photo_1.jpg' , 'New', '0', datetime(2016, 5, 22, 11, 30, 59), datetime(2017, 12, 22, 11, 30, 59)],
# [name, description, code, img, status]
['10%', 'Zniżka 10%', '5ac5', '/static/img/photo_1.jpg', 'New', '200', None, None],
['20%', 'Zniżka 20%', '5ac6', '/static/img/photo_1.jpg', 'New', None, None, None],
['50%', 'Zniżka 50%', '5ac7', '/static/img/photo_1.jpg', 'New', '0', datetime(2016, 5, 22, 11, 30, 59),
datetime(2017, 12, 22, 11, 30, 59)],
]
print("Creating Promotions")
for promotion in promotions:
print('Create {0}'.format(promotion[0]))
new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2], img=promotion[3], status=promotion[4], left_number=promotion[5], start_date=promotion[6], end_date=promotion[7])
new_promotion = Promotion.objects.create(name=promotion[0], description=promotion[1], code=promotion[2],
img=promotion[3], status=promotion[4], left_number=promotion[5],
start_date=promotion[6], end_date=promotion[7])
new_promotion.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import PromotionSet, Promotion
from django.core.management.base import BaseCommand
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
promotion_sets = [
#'name',products
['Promocja1', ['10%', '20%'] ],
['Promocja2', ['20%', '50%'] ],
# 'name',products
['Promocja1', ['10%', '20%']],
['Promocja2', ['20%', '50%']],
]
print("Creating PromotionSets")
for promotion_set in promotion_sets:
......
......@@ -31,12 +31,13 @@ class PromotionSet(models.Model):
name = models.CharField(max_length=50)
promotions = models.ManyToManyField(Promotion, default='')
class Localization(models.Model):
latitude = models.CharField(max_length=50,)
longitude = models.CharField(max_length=50,)
city = models.CharField(max_length=50,)
road = models.CharField(max_length=50,)
road_number = models.CharField(max_length=50,)
latitude = models.CharField(max_length=50, )
longitude = models.CharField(max_length=50, )
city = models.CharField(max_length=50, )
road = models.CharField(max_length=50, )
road_number = models.CharField(max_length=50, )
class Beacon(models.Model):
......@@ -47,10 +48,9 @@ class Beacon(models.Model):
description = models.CharField(max_length=300, null=True)
class Place(models.Model):
name = models.CharField(max_length=50, unique=True)
type = models.CharField(max_length=50,)
type = models.CharField(max_length=50, )
screen_img = models.ImageField()
logo_img = models.ImageField()
description = models.CharField(max_length=50)
......@@ -58,4 +58,3 @@ class Place(models.Model):
promotion = models.ForeignKey(PromotionSet, null=True, blank=True)
localization = models.ForeignKey(Localization, null=True, blank=True)
beacon = models.ForeignKey(Beacon, null=True, blank=True)
......@@ -42,6 +42,7 @@ class BeaconSerializer(serializers.HyperlinkedModelSerializer):
model = Beacon
fields = ('url', 'id', 'uuid', 'major', 'minor', 'name', 'description')
class PlaceSerializer(serializers.HyperlinkedModelSerializer):
offer = OfferSerializer()
promotion = PromotionSetSerializer()
......@@ -50,4 +51,6 @@ class PlaceSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Place
fields = ('url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization' ,'beacon')
fields = (
'url', 'id', 'name', 'type', 'screen_img', 'logo_img', 'description', 'offer', 'promotion', 'localization',
'beacon')
from django.test import TestCase
# Create your tests here.
from django.shortcuts import render
from rest_framework import viewsets, permissions
from rest_framework.decorators import list_route
from App.loyaltyMe.models import Product, Offer, Promotion, Place, PromotionSet, Localization, Beacon
from App.loyaltyMe.serializers import ProductSerializer, OfferSerializer, PromotionSerializer, PlaceSerializer, \
......@@ -15,6 +13,7 @@ class ProductViewSet(viewsets.ModelViewSet):
serializer_class = ProductSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class OfferViewSet(viewsets.ModelViewSet):
"""
API for articles
......@@ -23,6 +22,7 @@ class OfferViewSet(viewsets.ModelViewSet):
serializer_class = OfferSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PromotionViewSet(viewsets.ModelViewSet):
"""
API for articles
......@@ -31,6 +31,7 @@ class PromotionViewSet(viewsets.ModelViewSet):
serializer_class = PromotionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PromotionSetViewSet(viewsets.ModelViewSet):
"""
API for articles
......@@ -40,7 +41,6 @@ class PromotionSetViewSet(viewsets.ModelViewSet):
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class PlaceViewSet(viewsets.ModelViewSet):
"""
API for articles
......@@ -58,6 +58,7 @@ class LocalizationViewSet(viewsets.ModelViewSet):
serializer_class = LocalizationSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
class BeaconViewSet(viewsets.ModelViewSet):
"""
API for articles
......
from django.contrib import admin
# Register your models here.
from django.db import models
# Create your models here.
import sys
from io import StringIO
from django.test import TestCase
from flake8.engine import get_style_guide
from KawowyDzienniczek.settings import BASE_DIR
EXCLUDE_FROM_PEP8_TESTS = ['manage.py', '__init__.py']
# core/tests/io.py
class CaptureStdout(object):
"""
Capture STDOUT as self.value when used as a context manager.
Example:
class PrintingTestCase(SimpleTestCase):
def test_printing(self):
with CaptureStdout() as stdout:
print('oh hi')
self.assertEqual(str(stdout), 'oh hi\n')
"""
def __init__(self):
self.value = ''
self.old_stdout = None
def __str__(self):
return self.value
def __enter__(self):
self.old_stdout = sys.stdout
sys.stdout = StringIO()
return self
def __exit__(self, *exc_info):
self.value = sys.stdout.getvalue()
sys.stdout.close()
sys.stdout = self.old_stdout
# Create your tests here.
class Flake8ConformanceTestCase(TestCase):
def test_flake8_conformance(self):
with CaptureStdout() as stdout:
flake8_style = get_style_guide(paths=[BASE_DIR])
report = flake8_style.check_files()
if report.total_errors > 0:
self.fail(
'Got some flake8 errors:\n{0}'.format(stdout),
)
from django.shortcuts import render
# Create your views here.
def coming_soon_page(request):
return render(request, 'page/index.html', {})
def main_page(request):
return render(request, 'main_page/index.html', {})
from django.contrib import admin
# Register your models here.
from django.contrib.auth.models import User
from django.core.management import call_command
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = ''
......@@ -16,6 +16,3 @@ class Command(BaseCommand):
call_command('init_promotionsets')
call_command('init_localizations')
call_command('init_places')
call_command('init_userpromotions')
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
from App.user.models import UserProfile
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
class Command(BaseCommand):
def handle(self, *args, **options):
data = [
['admin', '/static/img/users/photos/default_avatar.png',],
['Antek', '/static/img/users/photos/antek.jpg',],
['admin', '/static/img/users/photos/default_avatar.png', ],
['Antek', '/static/img/users/photos/antek.jpg', ],
['Rafal', '/static/img/users/photos/rafal.jpg'],
['Klaudia', '/static/img/users/photos/klaudia.jpg'],
]
......@@ -22,4 +19,3 @@ class Command(BaseCommand):
user = User.objects.filter(username=user_data[0])[0]
new_userapi = UserProfile.objects.create(user=user, photo=user_data[1])
new_userapi.save()
from django.contrib.auth.models import User
from App.loyaltyMe.models import Place, Promotion
from App.user.models import UserPromotion
__author__ = 'Rafal'
from django.core.management.base import BaseCommand
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
def handle(self, *args, **options):
user_promotions = [
# user = models.ForeignKey(User, related_name='user_promotion',
# blank=False, null=False, default=None)
# place = models.ForeignKey(Place)
# promotion = models.ForeignKey(Promotion)
# status = models.CharField(max_length=30)
# code = models.CharField(max_length=20)
['Klaudia', 'Kocia Kawiarnia', '10%', 'used' ,'abcd'],
['Klaudia', 'Kafcia u Olczaka', '20%', 'in_progress', None],
['Antek', 'Kafcia u Olczaka', '50%', 'in_progress', None],
['admin', 'Kafcia u Olczaka', '10%', 'in_progress', None],
]
print("Creating Awards")
for user_promotion in user_promotions:
print('Create {0}'.format(user_promotion[0]))
user = User.objects.filter(username=user_promotion[0])[0]
place = Place.objects.filter(name=user_promotion[1])[0]
promotion = Promotion.objects.filter(name=user_promotion[2])[0]
new_user_promotion = UserPromotion.objects.create(user=user, place=place, promotion=promotion, status=user_promotion[3], code=user_promotion[4])
new_user_promotion.save()
\ No newline at end of file
from django.contrib.auth.models import User
from django.core.management.base import BaseCommand
__author__ = 'Rafal'
from django.core.management.base import BaseCommand, CommandError
class Command(BaseCommand):
help = 'Closes the specified poll for voting'
......@@ -10,12 +9,13 @@ class Command(BaseCommand):
users = [
['admin', 'admin', 'admin@gmail.com', ],
['Antek', 'Antek', 'antek@gmail.com'],
['Rafal','Rafal', 'rafal@gmail.com'],
['Klaudia','Klaudia', 'klaudia@gmail.com']
['Rafal', 'Rafal', 'rafal@gmail.com'],
['Klaudia', 'Klaudia', 'klaudia@gmail.com']
]
print("Creating Users")
for user in users:
print('Create {0}'.format(user[0]))
new_user = User.objects.create(username=user[0], password=user[1], email=user[2],is_active=True, is_superuser=True, is_staff=True,)
new_user = User.objects.create(username=user[0], password=user[1], email=user[2], is_active=True,
is_superuser=True, is_staff=True, )
new_user.set_password(user[1])
new_user.save()
......@@ -13,11 +13,13 @@ def create_auth_token(sender, instance=None, created=False, **kwargs):
if created:
Token.objects.create(user=instance)
class UserProfile(models.Model):
user = models.ForeignKey(User, related_name='user_profile',
blank=False, null=False, default=None)
photo = models.ImageField()
class UserPromotion(models.Model):
user = models.ForeignKey(User, related_name='user_promotion',
blank=False, null=False, default=None)
......@@ -25,5 +27,3 @@ class UserPromotion(models.Model):
promotion = models.ForeignKey(Promotion)
status = models.CharField(max_length=30)
code = models.CharField(max_length=20, null=True)
from django.contrib.auth import authenticate
from django.contrib.auth.models import User
from django.shortcuts import get_object_or_404
from rest_framework import serializers
from django.utils.translation import ugettext_lazy as _
from rest_framework import serializers
from App.loyaltyMe.serializers import PlaceSerializer, PromotionSerializer
from App.user.models import UserProfile, UserPromotion
......@@ -16,6 +15,7 @@ class UserSerializer(serializers.HyperlinkedModelSerializer):
class UserProfileSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
class Meta:
model = UserProfile
fields = ('url', 'id', 'user', 'photo')
......@@ -50,6 +50,7 @@ class AuthTokenSerializerByEmail(serializers.Serializer):
attrs['user'] = user
return attrs
class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
user = UserSerializer()
place = PlaceSerializer()
......@@ -58,4 +59,3 @@ class UserPromotionSerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = UserPromotion
fields = ('url', 'id', 'user', 'place', 'promotion', 'status', 'code')
from django.test import TestCase
# Create your tests here.
from xml import parsers
import rest_framework
from django.contrib.auth.models import User
from django.shortcuts import render
# Create your views here.
from rest_framework import viewsets
from rest_framework.authtoken.models import Token
from rest_framework.authtoken.serializers import AuthTokenSerializer
from rest_framework.decorators import list_route, detail_route
from rest_framework.decorators import list_route
from rest_framework.response import Response
from rest_framework import viewsets, permissions
from rest_framework.views import APIView
from App.loyaltyMe.models import Place
from App.loyaltyMe.serializers import LocalizationSerializer
from App.user.models import UserProfile, UserPromotion
from App.user.serializers import UserSerializer, AuthTokenSerializerByEmail, UserProfileSerializer, \
UserPromotionSerializer
......@@ -95,17 +88,3 @@ class UserPromotionViewSet(viewsets.ModelViewSet):
page = self.paginate_queryset(queryset)
serializer = UserPromotionSerializer(page, many=True, context={'request': request})
return self.get_paginated_response(serializer.data)
class PlaceUserPromotionsViewSet(viewsets.ModelViewSet):
base_name = "place_user_promotions"
queryset = UserPromotion.objects.all()
serializer_class = UserPromotionSerializer
permission_classes = (permissions.IsAuthenticatedOrReadOnly,)
def retrieve(self, request, pk):
place = Place.objects.filter(pk=pk)[0]
user_promotions = request.user.user_promotion.filter(place=place)
page = self.paginate_queryset(user_promotions)
serializer = UserPromotionSerializer(page, many=True, context={'request': request})
return self.get_paginated_response(serializer.data)
......@@ -10,4 +10,3 @@ DATABASES = {
'PORT': '5432',
}
}
......@@ -14,20 +14,17 @@ Including another URLconf
2. Add a URL to urlpatterns: url(r'^blog/', include('blog.urls'))
"""
from django.conf.urls import url, include
from django.conf.urls.static import static
from django.contrib import admin
from rest_framework import routers
from App.loyaltyMe import views as loyalty_views
from App.page.views import coming_soon_page, main_page
from App.user import views as user_views
from App.loyaltyMe import views as loyalty_views
router = routers.DefaultRouter()
router.register(r'user', user_views.UserViewSet)
router.register(r'user_profile', user_views.UserProfileViewSet)
router.register(r'user_promotions', user_views.UserPromotionViewSet, base_name='user_promotions')
router.register(r'place_user_promotions', user_views.PlaceUserPromotionsViewSet)
router.register(r'products', loyalty_views.ProductViewSet)
router.register(r'offers', loyalty_views.OfferViewSet)
router.register(r'promotions', loyalty_views.PromotionViewSet)
......
# setup.cfg
[flake8]
exclude = migrations,local_settings.py,production_settings.py
max-complexity = 10
max-line-length = 120
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment