-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
345 additions
and
27 deletions.
There are no files selected for viewing
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
from django.contrib import admin | ||
from shop_app.models import Product, Category, Brand | ||
from shop_app.models import Product, Category, Cart, Cart_product | ||
|
||
|
||
admin.site.register(Product) | ||
admin.site.register(Category) | ||
admin.site.register(Brand) | ||
admin.site.register(Cart_product) | ||
|
||
@admin.register(Cart) | ||
class CartAdmin(admin.ModelAdmin): | ||
list_display = ('user',) |
35 changes: 35 additions & 0 deletions
35
shop_app/migrations/0002_cart_cart_product_delete_brand.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# Generated by Django 4.1.1 on 2022-09-20 07:24 | ||
|
||
from django.conf import settings | ||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
migrations.swappable_dependency(settings.AUTH_USER_MODEL), | ||
('shop_app', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Cart', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('product', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product', to='shop_app.product')), | ||
('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='user', to=settings.AUTH_USER_MODEL)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name='Cart_product', | ||
fields=[ | ||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('cart_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='cart_id', to='shop_app.cart')), | ||
('product_id', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product_id', to='shop_app.product')), | ||
], | ||
), | ||
migrations.DeleteModel( | ||
name='Brand', | ||
), | ||
] |
33 changes: 33 additions & 0 deletions
33
shop_app/migrations/0003_remove_cart_product_cart_cart_products_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 4.1.1 on 2022-09-20 08:18 | ||
|
||
from django.db import migrations, models | ||
import django.db.models.deletion | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shop_app', '0002_cart_cart_product_delete_brand'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='cart', | ||
name='product', | ||
), | ||
migrations.AddField( | ||
model_name='cart', | ||
name='cart_products', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product', to='shop_app.cart_product'), | ||
), | ||
migrations.AlterField( | ||
model_name='cart_product', | ||
name='cart_id', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='cart', to='shop_app.cart'), | ||
), | ||
migrations.AlterField( | ||
model_name='cart_product', | ||
name='product_id', | ||
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='product', to='shop_app.product'), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Generated by Django 4.1.1 on 2022-09-20 08:24 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('shop_app', '0003_remove_cart_product_cart_cart_products_and_more'), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name='cart', | ||
name='cart_products', | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,66 @@ | ||
from django.test import TestCase | ||
from django.test import TestCase, Client | ||
from django.contrib.auth.models import User | ||
from shop_app.models import Product | ||
|
||
# Create your tests here. | ||
|
||
class TestProduct(TestCase): | ||
def test_should_allow_only_get(self): | ||
c = Client() | ||
response = c.get("http://127.0.0.1:8000/product/") | ||
assert response.status_code == 200 | ||
|
||
response = c.get("http://127.0.0.1:8000/add_to_cart_product") | ||
assert response.status_code == 200 | ||
|
||
response = c.post("http://127.0.0.1:8000/add_to_cart_productt") | ||
assert response.status_code == 201 | ||
|
||
response = c.get("http://127.0.0.1:8000/add_to_cart_product/2/") | ||
assert response.status_code == 200 | ||
|
||
response = c.put("http://127.0.0.1:8000/add_to_cart_product/2/") | ||
assert response.status_code == 200 | ||
|
||
response = c.delete("http://127.0.0.1:8000/add_to_cart_product/2/") | ||
assert response.status_code == 200 | ||
|
||
response = c.get("http://127.0.0.1:8000/add_to_cart") | ||
assert response.status_code == 200 | ||
|
||
response = c.post("http://127.0.0.1:8000/add_to_cart") | ||
assert response.status_code == 200 | ||
|
||
response = c.get("http://127.0.0.1:8000/add_to_cart/2/") | ||
assert response.status_code == 200 | ||
|
||
response = c.post("http://127.0.0.1:8000/add_to_cart/2/") | ||
assert response.status_code == 200 | ||
|
||
response = c.delete("http://127.0.0.1:8000/add_to_cart/2/") | ||
assert response.status_code == 200 | ||
|
||
|
||
class TestHomepage(TestCase): | ||
def test_open_homepage_should_be_success(self): | ||
c = Client() | ||
response = c.get("http://127.0.0.1:8000/") | ||
assert response.status_code == 404 | ||
|
||
|
||
# def test_create_product_with_user(self): | ||
# user = User( | ||
# username="test1", | ||
# email="[email protected]", | ||
# password="test1", | ||
# ) | ||
# user.save() | ||
# print(f"\n{user}\n") | ||
# p = Product( | ||
# name="яблоко", | ||
# price=100, | ||
# user=user | ||
# ) | ||
# p.save() | ||
# | ||
# assert user.id == p.user.id | ||
# print(f"\nour test done\n") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Oops, something went wrong.