Formatted with black and reached 100% coverage

This commit is contained in:
Thu Trang Pham
2020-11-08 09:51:49 -08:00
parent c586100098
commit a95383cfa2
17 changed files with 465 additions and 179 deletions
+2 -3
View File
@@ -9,7 +9,7 @@ class ItemFactory(factory.django.DjangoModelFactory):
class Meta:
model = Item
name = factory.Faker('name')
name = factory.Faker("name")
price = factory.LazyAttribute(lambda _: randint(5, 500))
currency = factory.LazyAttribute(lambda _: choice(Item.VALID_CURRENCIES))
@@ -18,7 +18,7 @@ class ShopFactory(factory.django.DjangoModelFactory):
class Meta:
model = Shop
name = factory.Faker('name')
name = factory.Faker("name")
class InventoryFactory(factory.django.DjangoModelFactory):
@@ -28,4 +28,3 @@ class InventoryFactory(factory.django.DjangoModelFactory):
shop = factory.SubFactory(ShopFactory)
item = factory.SubFactory(ItemFactory)
quantity = factory.Sequence(lambda n: n)
+2 -2
View File
@@ -5,7 +5,7 @@ import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_project.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
@@ -17,5 +17,5 @@ def main():
execute_from_command_line(sys.argv)
if __name__ == '__main__':
if __name__ == "__main__":
main()
+4 -4
View File
@@ -6,19 +6,19 @@ from .models import Item, Inventory, Shop
class ItemAdmin(AdminConfirmMixin, admin.ModelAdmin):
list_display = ('name', 'price', 'currency')
list_display = ("name", "price", "currency")
confirm_change = True
class InventoryAdmin(AdminConfirmMixin, admin.ModelAdmin):
list_display = ('shop', 'item', 'quantity')
list_display = ("shop", "item", "quantity")
confirm_change = True
confirm_add = True
confirmation_fields = ['shop']
confirmation_fields = ["quantity"]
class ShopAdmin(AdminConfirmMixin, admin.ModelAdmin):
confirmation_fields = ['name']
confirmation_fields = ["name"]
admin.site.register(Item, ItemAdmin)
+1 -1
View File
@@ -2,4 +2,4 @@ from django.apps import AppConfig
class MarketConfig(AppConfig):
name = 'market'
name = "market"
+38 -11
View File
@@ -8,25 +8,52 @@ class Migration(migrations.Migration):
initial = True
dependencies = [
]
dependencies = []
operations = [
migrations.CreateModel(
name='Item',
name="Item",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=120)),
('price', models.DecimalField(decimal_places=2, max_digits=5)),
('currency', models.CharField(choices=[('CAD', 'CAD'), ('USD', 'USD')], max_length=3)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=120)),
("price", models.DecimalField(decimal_places=2, max_digits=5)),
(
"currency",
models.CharField(
choices=[("CAD", "CAD"), ("USD", "USD")], max_length=3
),
),
],
),
migrations.CreateModel(
name='Stock',
name="Stock",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField()),
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='all_stock', to='market.Item')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("quantity", models.PositiveIntegerField()),
(
"item",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="all_stock",
to="market.Item",
),
),
],
),
]
@@ -7,38 +7,63 @@ import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('market', '0001_initial'),
("market", "0001_initial"),
]
operations = [
migrations.CreateModel(
name='Inventory',
name="Inventory",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('quantity', models.PositiveIntegerField()),
('item', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='market.Item')),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("quantity", models.PositiveIntegerField()),
(
"item",
models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE, to="market.Item"
),
),
],
options={
'ordering': ['shop', 'item__name'],
"ordering": ["shop", "item__name"],
},
),
migrations.CreateModel(
name='Shop',
name="Shop",
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('name', models.CharField(max_length=120)),
(
"id",
models.AutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("name", models.CharField(max_length=120)),
],
),
migrations.DeleteModel(
name='Stock',
name="Stock",
),
migrations.AddField(
model_name='inventory',
name='shop',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='inventory', to='market.Shop'),
model_name="inventory",
name="shop",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="inventory",
to="market.Shop",
),
),
migrations.AlterUniqueTogether(
name='inventory',
unique_together={('shop', 'item')},
name="inventory",
unique_together={("shop", "item")},
),
]
@@ -0,0 +1,25 @@
# Generated by Django 3.0.10 on 2020-11-08 17:17
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("market", "0002_auto_20201031_2057"),
]
operations = [
migrations.AlterModelOptions(
name="inventory",
options={
"ordering": ["shop", "item__name"],
"verbose_name_plural": "Inventory",
},
),
migrations.AlterField(
model_name="inventory",
name="quantity",
field=models.PositiveIntegerField(blank=True, default=0, null=True),
),
]
+9 -7
View File
@@ -3,8 +3,8 @@ from django.db import models
class Item(models.Model):
VALID_CURRENCIES = (
('CAD', 'CAD'),
('USD', 'USD'),
("CAD", "CAD"),
("USD", "USD"),
)
name = models.CharField(max_length=120)
price = models.DecimalField(max_digits=5, decimal_places=2)
@@ -23,10 +23,12 @@ class Shop(models.Model):
class Inventory(models.Model):
class Meta:
unique_together = ['shop', 'item']
ordering = ['shop', 'item__name']
verbose_name_plural = 'Inventory'
unique_together = ["shop", "item"]
ordering = ["shop", "item__name"]
verbose_name_plural = "Inventory"
shop = models.ForeignKey(to=Shop, on_delete=models.CASCADE, related_name='inventory')
shop = models.ForeignKey(
to=Shop, on_delete=models.CASCADE, related_name="inventory"
)
item = models.ForeignKey(to=Item, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField()
quantity = models.PositiveIntegerField(default=0, null=True, blank=True)
+38 -40
View File
@@ -19,67 +19,65 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '=yddl-40388w3e2hl$e8)revce=n67_idi8pfejtn3!+2%!_qt'
SECRET_KEY = "=yddl-40388w3e2hl$e8)revce=n67_idi8pfejtn3!+2%!_qt"
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['127.0.0.1']
ALLOWED_HOSTS = ["127.0.0.1"]
# Application definition
INSTALLED_APPS = [
'admin_confirm',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'tests.market',
"admin_confirm",
"django.contrib.admin",
"django.contrib.auth",
"django.contrib.contenttypes",
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"tests.market",
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
"django.middleware.security.SecurityMiddleware",
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
]
ROOT_URLCONF = 'tests.test_project.urls'
ROOT_URLCONF = "tests.test_project.urls"
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": [],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": [
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
],
},
},
]
WSGI_APPLICATION = 'tests.test_project.wsgi.application'
WSGI_APPLICATION = "tests.test_project.wsgi.application"
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}
@@ -89,16 +87,16 @@ DATABASES = {
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
]
@@ -106,9 +104,9 @@ AUTH_PASSWORD_VALIDATORS = [
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
LANGUAGE_CODE = "en-us"
TIME_ZONE = 'UTC'
TIME_ZONE = "UTC"
USE_I18N = True
@@ -120,4 +118,4 @@ USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
STATIC_URL = "/static/"
+1 -1
View File
@@ -2,5 +2,5 @@ from django.contrib import admin
from django.urls import path
urlpatterns = [
path('admin/', admin.site.urls),
path("admin/", admin.site.urls),
]
+1 -1
View File
@@ -2,6 +2,6 @@ import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'test_project.settings')
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "test_project.settings")
application = get_wsgi_application()