├── LICENSE ├── Part-05 Pytest and Selenium Introduction ├── .vscode │ └── settings.json ├── conftest.py ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests │ │ │ └── tests.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini ├── requirements.txt └── tests │ ├── __pycache__ │ ├── factories.cpython-39.pyc │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ ├── test_ex3.cpython-39-pytest-6.2.3.pyc │ ├── test_ex4.cpython-39-pytest-6.2.3.pyc │ ├── test_ex5.cpython-39-pytest-6.2.3.pyc │ └── test_ex6.cpython-39-pytest-6.2.3.pyc │ ├── factories.py │ ├── test_ex1.py │ ├── test_ex2.py │ ├── test_ex3.py │ ├── test_ex4.py │ ├── test_ex5.py │ └── test_ex6.py ├── Part-06 Pytest and Selenium - Taking Screenshots ├── conftest.py ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests │ │ │ └── tests.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini ├── requirements.txt └── tests │ ├── __pycache__ │ ├── factories.cpython-39.pyc │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ ├── test_ex3.cpython-39-pytest-6.2.3.pyc │ ├── test_ex4.cpython-39-pytest-6.2.3.pyc │ ├── test_ex5.cpython-39-pytest-6.2.3.pyc │ ├── test_ex6.cpython-39-pytest-6.2.3.pyc │ └── test_ex7.cpython-39-pytest-6.2.3.pyc │ ├── factories.py │ ├── test_ex1.py │ ├── test_ex2.py │ ├── test_ex3.py │ ├── test_ex4.py │ ├── test_ex5.py │ ├── test_ex6.py │ └── test_ex7.py ├── Part-1 Set-up and Introduction ├── .coverage ├── .coveragerc ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ └── urls.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ └── views.py │ ├── app2 │ │ ├── __init__.py │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ └── __init__.py │ │ ├── models.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini └── tests │ ├── __pycache__ │ ├── test_app1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ └── test_ex3.cpython-39-pytest-6.2.3.pyc │ ├── test_ex1.py │ ├── test_ex2.py │ └── test_ex3.py ├── Part-2 Fixtures and Factories ├── conftest.py ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ └── urls.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests │ │ │ └── tests.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini └── tests │ ├── __pycache__ │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ ├── test_ex3.cpython-39-pytest-6.2.3.pyc │ └── test_ex4.cpython-39-pytest-6.2.3.pyc │ ├── test_ex1.py │ ├── test_ex2.py │ ├── test_ex3.py │ └── test_ex4.py ├── Part-3 Factory Boy ├── __pycache__ │ └── conftest.cpython-39-pytest-6.2.3.pyc ├── conftest.py ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests │ │ │ └── tests.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini ├── requirements.txt └── tests │ ├── __pycache__ │ ├── factories.cpython-39.pyc │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ ├── test_ex3.cpython-39-pytest-6.2.3.pyc │ └── test_ex4.cpython-39-pytest-6.2.3.pyc │ ├── factories.py │ ├── test_ex1.py │ ├── test_ex2.py │ ├── test_ex3.py │ └── test_ex4.py ├── Part-4 Parametrizing ├── .vscode │ └── settings.json ├── conftest.py ├── core │ ├── __init__.py │ ├── __pycache__ │ │ ├── __init__.cpython-39.pyc │ │ ├── settings.cpython-39.pyc │ │ ├── urls.cpython-39.pyc │ │ └── wsgi.cpython-39.pyc │ ├── app1 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-39.pyc │ │ │ ├── admin.cpython-39.pyc │ │ │ ├── apps.cpython-39.pyc │ │ │ └── models.cpython-39.pyc │ │ ├── admin.py │ │ ├── apps.py │ │ ├── migrations │ │ │ ├── 0001_initial.py │ │ │ ├── __init__.py │ │ │ └── __pycache__ │ │ │ │ ├── 0001_initial.cpython-39.pyc │ │ │ │ └── __init__.cpython-39.pyc │ │ ├── models.py │ │ ├── tests │ │ │ └── tests.py │ │ └── views.py │ ├── asgi.py │ ├── settings.py │ ├── urls.py │ └── wsgi.py ├── db.sqlite3 ├── manage.py ├── pytest.ini ├── requirements.txt └── tests │ ├── __pycache__ │ ├── factories.cpython-39.pyc │ ├── test_ex1.cpython-39-pytest-6.2.3.pyc │ ├── test_ex2.cpython-39-pytest-6.2.3.pyc │ ├── test_ex3.cpython-39-pytest-6.2.3.pyc │ ├── test_ex4.cpython-39-pytest-6.2.3.pyc │ └── test_ex5.cpython-39-pytest-6.2.3.pyc │ ├── factories.py │ ├── test_ex1.py │ ├── test_ex2.py │ ├── test_ex3.py │ ├── test_ex4.py │ └── test_ex5.py ├── README.md └── logo.svg /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Very Academy 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "python.pythonPath": "venv\\Scripts\\python.exe", 4 | "python.sortImports.args": [ 5 | "--profile=black", 6 | ], 7 | "python.formatting.provider": "black", 8 | "python.formatting.blackArgs": [ 9 | "--line-length=119" 10 | ], 11 | "[python]": { 12 | "editor.codeActionsOnSave": { 13 | "source.organizeImports": true 14 | } 15 | }, 16 | // Django Extension 17 | "files.associations": { 18 | "**/*.html": "html", 19 | "**/templates/**/*.html": "django-html", 20 | "**/templates/**/*": "django-txt", 21 | "**/requirements{/**,*}.{txt,in}": "pip-requirements" 22 | }, 23 | } -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium import webdriver 3 | 4 | # from pytest_factoryboy import register 5 | # from tests.factories import UserFactory, ProductFactory, CategoryFactory 6 | 7 | # register(UserFactory) 8 | # register(ProductFactory) 9 | # register(CategoryFactory) 10 | 11 | # @pytest.fixture 12 | # def new_user1(db, user_factory): 13 | # user = user_factory.create() 14 | # return user 15 | 16 | 17 | # @pytest.fixture(scope="class") 18 | # def chrome_driver_init(request): 19 | 20 | # options = webdriver.ChromeOptions() 21 | # options.add_argument("--headless") 22 | # chrome_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 23 | # request.cls.driver = chrome_driver 24 | # yield 25 | # chrome_driver.close() 26 | 27 | 28 | @pytest.fixture(params=["chrome", "firefox"], scope="class") 29 | def driver_init(request): 30 | if request.param == "chrome": 31 | options = webdriver.ChromeOptions() 32 | options.add_argument("--headless") 33 | web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 34 | if request.param == "firefox": 35 | options = webdriver.FirefoxOptions() 36 | options.add_argument("--headless") 37 | web_driver = webdriver.Firefox(executable_path=r"./geckodriver", options=options) 38 | request.cls.driver = web_driver 39 | yield 40 | web_driver.close() 41 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/__init__.py -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2 on 2021-04-15 10:56 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Category', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=255)), 20 | ], 21 | ), 22 | migrations.CreateModel( 23 | name='Product', 24 | fields=[ 25 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 26 | ('title', models.CharField(help_text='Required', max_length=255, verbose_name='title')), 27 | ('description', models.TextField(blank=True, help_text='Not Required', verbose_name='description')), 28 | ('slug', models.SlugField(max_length=255)), 29 | ('regular_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Regular price')), 30 | ('discount_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Discount price')), 31 | ('is_active', models.BooleanField(default=True, help_text='Change product visibility', verbose_name='Product visibility')), 32 | ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), 33 | ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')), 34 | ('category', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app1.category')), 35 | ], 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | 5 | class Category(models.Model): 6 | name = models.CharField( 7 | max_length=255, 8 | ) 9 | 10 | def __str__(self): 11 | return self.name 12 | 13 | 14 | class Product(models.Model): 15 | """ 16 | The Product table contining all product items. 17 | """ 18 | 19 | title = models.CharField( 20 | verbose_name=_("title"), 21 | help_text=_("Required"), 22 | max_length=255, 23 | ) 24 | category = models.ForeignKey(Category, on_delete=models.RESTRICT) 25 | description = models.TextField(verbose_name=_("description"), help_text=_("Not Required"), blank=True) 26 | slug = models.SlugField(max_length=255) 27 | regular_price = models.DecimalField( 28 | verbose_name=_("Regular price"), 29 | help_text=_("Maximum 999.99"), 30 | error_messages={ 31 | "name": { 32 | "max_length": _("The price must be between 0 and 999.99."), 33 | }, 34 | }, 35 | max_digits=5, 36 | decimal_places=2, 37 | ) 38 | discount_price = models.DecimalField( 39 | verbose_name=_("Discount price"), 40 | help_text=_("Maximum 999.99"), 41 | error_messages={ 42 | "name": { 43 | "max_length": _("The price must be between 0 and 999.99."), 44 | }, 45 | }, 46 | max_digits=5, 47 | decimal_places=2, 48 | ) 49 | is_active = models.BooleanField( 50 | verbose_name=_("Product visibility"), 51 | help_text=_("Change product visibility"), 52 | default=True, 53 | ) 54 | created_at = models.DateTimeField(_("Created at"), auto_now_add=True, editable=False) 55 | updated_at = models.DateTimeField(_("Updated at"), auto_now=True) 56 | 57 | # def clean(self): 58 | # if self.regular_price == "": 59 | # raise ValidationError({"website": "Joe must have a website"}) 60 | 61 | def __str__(self): 62 | return self.title 63 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/tests/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-u#gsa9x5f%1t8)6r^y*iimt=6@lv)dnibd@5ys7a7sa$m1e1=i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/db.sqlite3 -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = test_*.py 4 | 5 | markers = 6 | slow: slow running test -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | asgiref==3.3.4 3 | atomicwrites==1.4.0 4 | attrs==20.3.0 5 | black==20.8b1 6 | click==7.1.2 7 | colorama==0.4.4 8 | Django==3.2 9 | factory-boy==3.2.0 10 | Faker==8.1.0 11 | inflection==0.5.1 12 | iniconfig==1.1.1 13 | isort==5.8.0 14 | mypy-extensions==0.4.3 15 | packaging==20.9 16 | pathspec==0.8.1 17 | pluggy==0.13.1 18 | py==1.10.0 19 | pyparsing==2.4.7 20 | pytest==6.2.3 21 | pytest-django==4.2.0 22 | pytest-factoryboy==2.1.0 23 | python-dateutil==2.8.1 24 | pytz==2021.1 25 | regex==2021.4.4 26 | selenium==3.141.0 27 | six==1.15.0 28 | sqlparse==0.4.1 29 | text-unidecode==1.3 30 | toml==0.10.2 31 | typed-ast==1.4.3 32 | typing-extensions==3.7.4.3 33 | urllib3==1.26.4 34 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/factories.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/factories.cpython-39.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex6.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-05 Pytest and Selenium Introduction/tests/__pycache__/test_ex6.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/factories.py: -------------------------------------------------------------------------------- 1 | import factory 2 | from faker import Faker 3 | fake = Faker() 4 | 5 | from django.contrib.auth.models import User 6 | from core.app1 import models 7 | 8 | 9 | class UserFactory(factory.django.DjangoModelFactory): 10 | class Meta: 11 | model = User 12 | 13 | username = fake.name() 14 | is_staff = 'True' 15 | 16 | 17 | class CategoryFactory(factory.django.DjangoModelFactory): 18 | class Meta: 19 | model = models.Category 20 | 21 | name = 'django' 22 | 23 | 24 | class ProductFactory(factory.django.DjangoModelFactory): 25 | class Meta: 26 | model = models.Product 27 | 28 | title = 'product_title' 29 | category = factory.SubFactory(CategoryFactory) 30 | description = fake.text() 31 | slug = 'product_slug' 32 | regular_price = '9.99' 33 | discount_price = '4.99' -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # # function Run once per test 4 | # # class Run once per class of tests 5 | # # module Run once per module 6 | # # session Run once per session 7 | 8 | # @pytest.fixture(scope="session") 9 | # def fixture_1(): 10 | # print('run-fixture-1') 11 | # return 1 12 | 13 | # def test_example1(fixture_1): 14 | # print('run-example-1') 15 | # num = fixture_1 16 | # assert num == 1 17 | 18 | # def test_example2(fixture_1): 19 | # print('run-example-2') 20 | # num = fixture_1 21 | # assert num == 1 -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # @pytest.fixture 4 | # def yield_fixture(): 5 | # print('Start Test Phase') 6 | # yield 6 7 | # print('End Test Phase') 8 | 9 | # def test_example(yield_fixture): 10 | # print('run-example-1') 11 | # assert yield_fixture == 6 -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # from django.contrib.auth.models import User 4 | 5 | 6 | # @pytest.mark.django_db 7 | # def test_user_create(): 8 | # User.objects.create_user('test', 'test@test.com', 'test') 9 | # count = User.objects.all().count() 10 | # print(count) 11 | # assert User.objects.count() == 1 12 | 13 | 14 | # @pytest.mark.django_db 15 | # def test_user_create1(): 16 | # count = User.objects.all().count() 17 | # print(count) 18 | # assert count == 0 19 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex4.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | # from core.app1.models import Product 3 | # from django.contrib.auth.models import User 4 | 5 | # # from django.core.exceptions import ValidationError 6 | 7 | # # @pytest.fixture() 8 | # # def user_1(db): 9 | # # return User.objects.create_user("test-user") 10 | 11 | # # @pytest.mark.django_db 12 | # # def test_set_check_password(user_1): 13 | # # user_1.set_password("new-password") 14 | # # assert user_1.check_password("new-password") is True 15 | 16 | # # def test_set_check_password1(user_1): 17 | # # print('check-user1') 18 | # # assert user_1.username == "test-user" 19 | 20 | # # def test_set_check_password2(user_1): 21 | # # print('check-user2') 22 | # # assert user_1.username == "test-user" 23 | 24 | # # def test_new_user(new_user): 25 | # # print(new_user.first_name) 26 | # # assert new_user.first_name == "MyName" 27 | 28 | # # def test_new_user(new_user2): 29 | # # print(new_user2.is_staff) 30 | # # assert new_user2.is_staff 31 | 32 | # # def test_new_user(new_user1): 33 | # # print(new_user1.username) 34 | # # assert True 35 | 36 | 37 | # # def test_product(db, product_factory): 38 | # # product = product_factory.create() 39 | # # print(product.description) 40 | # # assert True 41 | 42 | 43 | # @pytest.mark.parametrize( 44 | # "title, category, description, slug, regular_price, discount_price, validity", 45 | # [ 46 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 47 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 48 | # ], 49 | # ) 50 | # def test_product_instance( 51 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 52 | # ): 53 | 54 | # test = product_factory( 55 | # title=title, 56 | # category_id=category, 57 | # description=description, 58 | # slug=slug, 59 | # regular_price=regular_price, 60 | # discount_price=discount_price, 61 | # ) 62 | 63 | # item = Product.objects.all().count() 64 | # print(test) 65 | # assert item == validity 66 | 67 | 68 | # @pytest.mark.parametrize( 69 | # "title, category, description, slug, regular_price, discount_price, validity", 70 | # [ 71 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 72 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 73 | # ], 74 | # ) 75 | # def test_product_instance( 76 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 77 | # ): 78 | 79 | # test = product_factory( 80 | # title=title, 81 | # category_id=category, 82 | # description=description, 83 | # slug=slug, 84 | # regular_price=regular_price, 85 | # discount_price=discount_price, 86 | # ) 87 | 88 | # item = Product.objects.all().count() 89 | # print(test) 90 | # assert item == validity 91 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex5.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | # from core.app1.models import Product 3 | 4 | 5 | # @pytest.mark.parametrize( 6 | # "title, category, description, slug, regular_price, discount_price, validity", 7 | # [ 8 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 9 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 10 | # ], 11 | # ) 12 | # def test_product_instance( 13 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 14 | # ): 15 | 16 | # test = product_factory( 17 | # title=title, 18 | # category_id=category, 19 | # description=description, 20 | # slug=slug, 21 | # regular_price=regular_price, 22 | # discount_price=discount_price, 23 | # ) 24 | 25 | # item = Product.objects.all().count() 26 | # print(item) 27 | # assert item == validity 28 | -------------------------------------------------------------------------------- /Part-05 Pytest and Selenium Introduction/tests/test_ex6.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from django.test import LiveServerTestCase 3 | from selenium import webdriver 4 | 5 | # Example 1 6 | # class TestBrowser1(LiveServerTestCase): 7 | # def test_example(self): 8 | # driver = webdriver.Chrome("./chromedriver") 9 | # driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 10 | # assert "Log in | Django site admin" in driver.title 11 | 12 | 13 | # Example 2 14 | # class TestBrowser2(LiveServerTestCase): 15 | # def test_example(self): 16 | # options = webdriver.ChromeOptions() 17 | # options.add_argument("--headless") 18 | # driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 19 | # driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 20 | # assert "Log in | Django site admin" in driver.title 21 | 22 | # Example 3 23 | # Fixture for Chrome 24 | # @pytest.fixture(scope="class") 25 | # def chrome_driver_init(request): 26 | 27 | # options = webdriver.ChromeOptions() 28 | # options.add_argument("--headless") 29 | # chrome_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 30 | # request.cls.driver = chrome_driver 31 | # yield 32 | # chrome_driver.close() 33 | 34 | 35 | # @pytest.mark.usefixtures("chrome_driver_init") 36 | # class Test_URL_Chrome(LiveServerTestCase): 37 | # def test_open_url(self): 38 | # self.driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 39 | # assert "Log in | Django site admin" in self.driver.title 40 | 41 | 42 | # @pytest.fixture(params=["chrome", "firefox"], scope="class") 43 | # def driver_init(request): 44 | # if request.param == "chrome": 45 | # options = webdriver.ChromeOptions() 46 | # options.add_argument("--headless") 47 | # web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 48 | # if request.param == "firefox": 49 | # options = webdriver.FirefoxOptions() 50 | # options.add_argument("--headless") 51 | # web_driver = webdriver.Firefox(executable_path=r"./geckodriver", options=options) 52 | # request.cls.driver = web_driver 53 | # yield 54 | # web_driver.close() 55 | 56 | 57 | @pytest.mark.usefixtures("driver_init") 58 | class Test_URL_Chrome: 59 | def test_open_url(self, live_server): 60 | self.driver.get(("%s%s" % (live_server.url, "/admin/"))) 61 | assert "Log in | Django site admin" in self.driver.title 62 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from selenium import webdriver 3 | 4 | # from pytest_factoryboy import register 5 | # from tests.factories import UserFactory, ProductFactory, CategoryFactory 6 | 7 | # register(UserFactory) 8 | # register(ProductFactory) 9 | # register(CategoryFactory) 10 | 11 | # @pytest.fixture 12 | # def new_user1(db, user_factory): 13 | # user = user_factory.create() 14 | # return user 15 | 16 | 17 | # @pytest.fixture(scope="class") 18 | # def chrome_driver_init(request): 19 | 20 | # options = webdriver.ChromeOptions() 21 | # options.add_argument("--headless") 22 | # chrome_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 23 | # request.cls.driver = chrome_driver 24 | # yield 25 | # chrome_driver.close() 26 | 27 | 28 | @pytest.fixture(params=["chrome", "firefox"], scope="class") 29 | def driver_init(request): 30 | if request.param == "chrome": 31 | options = webdriver.ChromeOptions() 32 | options.add_argument("--headless") 33 | web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 34 | if request.param == "firefox": 35 | options = webdriver.FirefoxOptions() 36 | options.add_argument("--headless") 37 | web_driver = webdriver.Firefox(executable_path=r"./geckodriver", options=options) 38 | request.cls.driver = web_driver 39 | yield 40 | web_driver.close() 41 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/__init__.py -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2 on 2021-04-15 10:56 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Category', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=255)), 20 | ], 21 | ), 22 | migrations.CreateModel( 23 | name='Product', 24 | fields=[ 25 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 26 | ('title', models.CharField(help_text='Required', max_length=255, verbose_name='title')), 27 | ('description', models.TextField(blank=True, help_text='Not Required', verbose_name='description')), 28 | ('slug', models.SlugField(max_length=255)), 29 | ('regular_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Regular price')), 30 | ('discount_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Discount price')), 31 | ('is_active', models.BooleanField(default=True, help_text='Change product visibility', verbose_name='Product visibility')), 32 | ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), 33 | ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')), 34 | ('category', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app1.category')), 35 | ], 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | 5 | class Category(models.Model): 6 | name = models.CharField( 7 | max_length=255, 8 | ) 9 | 10 | def __str__(self): 11 | return self.name 12 | 13 | 14 | class Product(models.Model): 15 | """ 16 | The Product table contining all product items. 17 | """ 18 | 19 | title = models.CharField( 20 | verbose_name=_("title"), 21 | help_text=_("Required"), 22 | max_length=255, 23 | ) 24 | category = models.ForeignKey(Category, on_delete=models.RESTRICT) 25 | description = models.TextField(verbose_name=_("description"), help_text=_("Not Required"), blank=True) 26 | slug = models.SlugField(max_length=255) 27 | regular_price = models.DecimalField( 28 | verbose_name=_("Regular price"), 29 | help_text=_("Maximum 999.99"), 30 | error_messages={ 31 | "name": { 32 | "max_length": _("The price must be between 0 and 999.99."), 33 | }, 34 | }, 35 | max_digits=5, 36 | decimal_places=2, 37 | ) 38 | discount_price = models.DecimalField( 39 | verbose_name=_("Discount price"), 40 | help_text=_("Maximum 999.99"), 41 | error_messages={ 42 | "name": { 43 | "max_length": _("The price must be between 0 and 999.99."), 44 | }, 45 | }, 46 | max_digits=5, 47 | decimal_places=2, 48 | ) 49 | is_active = models.BooleanField( 50 | verbose_name=_("Product visibility"), 51 | help_text=_("Change product visibility"), 52 | default=True, 53 | ) 54 | created_at = models.DateTimeField(_("Created at"), auto_now_add=True, editable=False) 55 | updated_at = models.DateTimeField(_("Updated at"), auto_now=True) 56 | 57 | # def clean(self): 58 | # if self.regular_price == "": 59 | # raise ValidationError({"website": "Joe must have a website"}) 60 | 61 | def __str__(self): 62 | return self.title 63 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/tests/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-u#gsa9x5f%1t8)6r^y*iimt=6@lv)dnibd@5ys7a7sa$m1e1=i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/db.sqlite3 -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = test_*.py 4 | python_classes = Screenshot Test_* 5 | python_functions = test_* screenshot_* 6 | 7 | markers = 8 | slow: slow running test -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | asgiref==3.3.4 3 | atomicwrites==1.4.0 4 | attrs==20.3.0 5 | black==20.8b1 6 | click==7.1.2 7 | colorama==0.4.4 8 | Django==3.2 9 | factory-boy==3.2.0 10 | Faker==8.1.0 11 | inflection==0.5.1 12 | iniconfig==1.1.1 13 | isort==5.8.0 14 | mypy-extensions==0.4.3 15 | packaging==20.9 16 | pathspec==0.8.1 17 | pluggy==0.13.1 18 | py==1.10.0 19 | pyparsing==2.4.7 20 | pytest==6.2.3 21 | pytest-django==4.2.0 22 | pytest-factoryboy==2.1.0 23 | python-dateutil==2.8.1 24 | pytz==2021.1 25 | regex==2021.4.4 26 | selenium==3.141.0 27 | six==1.15.0 28 | sqlparse==0.4.1 29 | text-unidecode==1.3 30 | toml==0.10.2 31 | typed-ast==1.4.3 32 | typing-extensions==3.7.4.3 33 | urllib3==1.26.4 34 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/factories.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/factories.cpython-39.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex6.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex6.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex7.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-06 Pytest and Selenium - Taking Screenshots/tests/__pycache__/test_ex7.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/factories.py: -------------------------------------------------------------------------------- 1 | import factory 2 | from faker import Faker 3 | fake = Faker() 4 | 5 | from django.contrib.auth.models import User 6 | from core.app1 import models 7 | 8 | 9 | class UserFactory(factory.django.DjangoModelFactory): 10 | class Meta: 11 | model = User 12 | 13 | username = fake.name() 14 | is_staff = 'True' 15 | 16 | 17 | class CategoryFactory(factory.django.DjangoModelFactory): 18 | class Meta: 19 | model = models.Category 20 | 21 | name = 'django' 22 | 23 | 24 | class ProductFactory(factory.django.DjangoModelFactory): 25 | class Meta: 26 | model = models.Product 27 | 28 | title = 'product_title' 29 | category = factory.SubFactory(CategoryFactory) 30 | description = fake.text() 31 | slug = 'product_slug' 32 | regular_price = '9.99' 33 | discount_price = '4.99' -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # # function Run once per test 4 | # # class Run once per class of tests 5 | # # module Run once per module 6 | # # session Run once per session 7 | 8 | # @pytest.fixture(scope="session") 9 | # def fixture_1(): 10 | # print('run-fixture-1') 11 | # return 1 12 | 13 | # def test_example1(fixture_1): 14 | # print('run-example-1') 15 | # num = fixture_1 16 | # assert num == 1 17 | 18 | # def test_example2(fixture_1): 19 | # print('run-example-2') 20 | # num = fixture_1 21 | # assert num == 1 -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # @pytest.fixture 4 | # def yield_fixture(): 5 | # print('Start Test Phase') 6 | # yield 6 7 | # print('End Test Phase') 8 | 9 | # def test_example(yield_fixture): 10 | # print('run-example-1') 11 | # assert yield_fixture == 6 -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # from django.contrib.auth.models import User 4 | 5 | 6 | # @pytest.mark.django_db 7 | # def test_user_create(): 8 | # User.objects.create_user('test', 'test@test.com', 'test') 9 | # count = User.objects.all().count() 10 | # print(count) 11 | # assert User.objects.count() == 1 12 | 13 | 14 | # @pytest.mark.django_db 15 | # def test_user_create1(): 16 | # count = User.objects.all().count() 17 | # print(count) 18 | # assert count == 0 19 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex4.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | # from core.app1.models import Product 3 | # from django.contrib.auth.models import User 4 | 5 | # # from django.core.exceptions import ValidationError 6 | 7 | # # @pytest.fixture() 8 | # # def user_1(db): 9 | # # return User.objects.create_user("test-user") 10 | 11 | # # @pytest.mark.django_db 12 | # # def test_set_check_password(user_1): 13 | # # user_1.set_password("new-password") 14 | # # assert user_1.check_password("new-password") is True 15 | 16 | # # def test_set_check_password1(user_1): 17 | # # print('check-user1') 18 | # # assert user_1.username == "test-user" 19 | 20 | # # def test_set_check_password2(user_1): 21 | # # print('check-user2') 22 | # # assert user_1.username == "test-user" 23 | 24 | # # def test_new_user(new_user): 25 | # # print(new_user.first_name) 26 | # # assert new_user.first_name == "MyName" 27 | 28 | # # def test_new_user(new_user2): 29 | # # print(new_user2.is_staff) 30 | # # assert new_user2.is_staff 31 | 32 | # # def test_new_user(new_user1): 33 | # # print(new_user1.username) 34 | # # assert True 35 | 36 | 37 | # # def test_product(db, product_factory): 38 | # # product = product_factory.create() 39 | # # print(product.description) 40 | # # assert True 41 | 42 | 43 | # @pytest.mark.parametrize( 44 | # "title, category, description, slug, regular_price, discount_price, validity", 45 | # [ 46 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 47 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 48 | # ], 49 | # ) 50 | # def test_product_instance( 51 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 52 | # ): 53 | 54 | # test = product_factory( 55 | # title=title, 56 | # category_id=category, 57 | # description=description, 58 | # slug=slug, 59 | # regular_price=regular_price, 60 | # discount_price=discount_price, 61 | # ) 62 | 63 | # item = Product.objects.all().count() 64 | # print(test) 65 | # assert item == validity 66 | 67 | 68 | # @pytest.mark.parametrize( 69 | # "title, category, description, slug, regular_price, discount_price, validity", 70 | # [ 71 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 72 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 73 | # ], 74 | # ) 75 | # def test_product_instance( 76 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 77 | # ): 78 | 79 | # test = product_factory( 80 | # title=title, 81 | # category_id=category, 82 | # description=description, 83 | # slug=slug, 84 | # regular_price=regular_price, 85 | # discount_price=discount_price, 86 | # ) 87 | 88 | # item = Product.objects.all().count() 89 | # print(test) 90 | # assert item == validity 91 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex5.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | # from core.app1.models import Product 3 | 4 | 5 | # @pytest.mark.parametrize( 6 | # "title, category, description, slug, regular_price, discount_price, validity", 7 | # [ 8 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 9 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 10 | # ], 11 | # ) 12 | # def test_product_instance( 13 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 14 | # ): 15 | 16 | # test = product_factory( 17 | # title=title, 18 | # category_id=category, 19 | # description=description, 20 | # slug=slug, 21 | # regular_price=regular_price, 22 | # discount_price=discount_price, 23 | # ) 24 | 25 | # item = Product.objects.all().count() 26 | # print(item) 27 | # assert item == validity 28 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex6.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from django.test import LiveServerTestCase 3 | from selenium import webdriver 4 | 5 | # Example 1 6 | # class TestBrowser1(LiveServerTestCase): 7 | # def test_example(self): 8 | # driver = webdriver.Chrome("./chromedriver") 9 | # driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 10 | # assert "Log in | Django site admin" in driver.title 11 | 12 | 13 | # Example 2 14 | # class TestBrowser2(LiveServerTestCase): 15 | # def test_example(self): 16 | # options = webdriver.ChromeOptions() 17 | # options.add_argument("--headless") 18 | # driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 19 | # driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 20 | # assert "Log in | Django site admin" in driver.title 21 | 22 | # Example 3 23 | # Fixture for Chrome 24 | # @pytest.fixture(scope="class") 25 | # def chrome_driver_init(request): 26 | 27 | # options = webdriver.ChromeOptions() 28 | # options.add_argument("--headless") 29 | # chrome_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 30 | # request.cls.driver = chrome_driver 31 | # yield 32 | # chrome_driver.close() 33 | 34 | 35 | # @pytest.mark.usefixtures("chrome_driver_init") 36 | # class Test_URL_Chrome(LiveServerTestCase): 37 | # def test_open_url(self): 38 | # self.driver.get(("%s%s" % (self.live_server_url, "/admin/"))) 39 | # assert "Log in | Django site admin" in self.driver.title 40 | 41 | 42 | # @pytest.fixture(params=["chrome", "firefox"], scope="class") 43 | # def driver_init(request): 44 | # if request.param == "chrome": 45 | # options = webdriver.ChromeOptions() 46 | # options.add_argument("--headless") 47 | # web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 48 | # if request.param == "firefox": 49 | # options = webdriver.FirefoxOptions() 50 | # options.add_argument("--headless") 51 | # web_driver = webdriver.Firefox(executable_path=r"./geckodriver", options=options) 52 | # request.cls.driver = web_driver 53 | # yield 54 | # web_driver.close() 55 | 56 | 57 | # @pytest.mark.usefixtures("driver_init") 58 | # class Test_URL_Chrome: 59 | # def test_open_url(self, live_server): 60 | # self.driver.get(("%s%s" % (live_server.url, "/admin/"))) 61 | # assert "Log in | Django site admin" in self.driver.title 62 | -------------------------------------------------------------------------------- /Part-06 Pytest and Selenium - Taking Screenshots/tests/test_ex7.py: -------------------------------------------------------------------------------- 1 | import os 2 | import time 3 | 4 | import pytest 5 | from selenium import webdriver 6 | 7 | 8 | def take_screenshot(driver, name): 9 | time.sleep(1) 10 | os.makedirs(os.path.join("screenshot", os.path.dirname(name)), exist_ok=True) 11 | driver.save_screenshot(os.path.join("screenshot", name)) 12 | 13 | 14 | # def test_example(live_server): 15 | # options = webdriver.ChromeOptions() 16 | # options.add_argument("--headless") 17 | # options.add_argument("--window-size=1920,1080") 18 | # chrome_driver = webdriver.Chrome("./chromedriver", options=options) 19 | # chrome_driver.get(("%s%s" % (live_server.url, "/admin/"))) 20 | # take_screenshot(chrome_driver, "admin/admin.png") 21 | 22 | 23 | @pytest.fixture(params=["chrome1920", "chrome411", "firefox"], scope="class") 24 | def driver_init(request): 25 | if request.param == "chrome1920": 26 | options = webdriver.ChromeOptions() 27 | options.add_argument("--headless") 28 | options.add_argument("--window-size=1920,1080") 29 | web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 30 | request.cls.browser = "Chrome1920x1080" 31 | if request.param == "chrome411": 32 | options = webdriver.ChromeOptions() 33 | options.add_argument("--headless") 34 | options.add_argument("--window-size=411,823") 35 | web_driver = webdriver.Chrome(executable_path=r"./chromedriver", options=options) 36 | request.cls.browser = "Chrome411x823" 37 | if request.param == "firefox": 38 | options = webdriver.FirefoxOptions() 39 | options.add_argument("--headless") 40 | web_driver = webdriver.Firefox(executable_path=r"./geckodriver", options=options) 41 | request.cls.browser = "Firefox" 42 | request.cls.driver = web_driver 43 | yield 44 | web_driver.close() 45 | 46 | 47 | @pytest.mark.usefixtures("driver_init") 48 | class Screenshot: 49 | def screenshot_admin(self, live_server): 50 | self.driver.get(("%s%s" % (live_server.url, "/admin/"))) 51 | take_screenshot(self.driver, "admin/" + "admin" + self.browser + ".png") 52 | assert "Log in | Django site admin" in self.driver.title 53 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/.coverage: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/.coverage -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/.coveragerc: -------------------------------------------------------------------------------- 1 | [run] 2 | omit = 3 | *venv/* 4 | conftest.py 5 | *tests* 6 | *settings.py* 7 | 8 | [report] 9 | omit = 10 | *venv/* 11 | conftest.py 12 | *tests* 13 | *__init__.py* 14 | *settings.py* -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/__init__.py -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2 on 2021-04-12 10:21 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Animal', 16 | fields=[ 17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('name', models.CharField(max_length=50)), 19 | ('sound', models.CharField(max_length=50)), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | 4 | class Animal(models.Model): 5 | name = models.CharField(max_length=50) 6 | sound = models.CharField(max_length=50) -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app2/__init__.py -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App2Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'app2' 7 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/core/app2/migrations/__init__.py -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/app2/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-1y=$rulo9su^juiyi6n0f69lmxq)niez^t-5ties8rvq^ep(w^' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/db.sqlite3 -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = tests.py test_*.py *_tests.py 4 | 5 | markers = 6 | slow: marks tests as slow (deselect with '-m "not slow"') -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/__pycache__/test_app1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/tests/__pycache__/test_app1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-1 Set-up and Introduction/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # from django.test import TestCase 2 | 3 | # class TestClass(TestCase): 4 | # def test_hello_world(self): 5 | # self.assertEqual("hello", "hello") 6 | 7 | # import pytest 8 | 9 | # @pytest.mark.slow 10 | # def test_hello_world(): 11 | # assert "hello" == "hello" -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # #https://docs.pytest.org/en/reorganize-docs/new-docs/user/assert_statements.html 2 | # # Assertions are the condition or boolean expression which are always supposed to be true 3 | # import pytest 4 | 5 | # def vowels(): 6 | # return set('aeiou') 7 | 8 | # @pytest.mark.skip 9 | # def test_vowels(): 10 | # result = vowels() 11 | # expected = set('aeiou') 12 | # print ("this test has run") 13 | # assert result == expected -------------------------------------------------------------------------------- /Part-1 Set-up and Introduction/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | from core.app1.models import Animal 3 | 4 | class AnimalTestCase(TestCase): 5 | def setUp(self): 6 | Animal.objects.create(name="lion", sound="roar") 7 | Animal.objects.create(name="cat", sound="meow") 8 | 9 | def test_animals_can_speak(self): 10 | """Animals that can speak are correctly identified""" 11 | lion = Animal.objects.get(name="lion") 12 | cat = Animal.objects.get(name="cat") 13 | self.assertEqual(lion.sound, 'roar') 14 | self.assertEqual(cat.sound, 'meow') -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from django.contrib.auth.models import User 4 | 5 | @pytest.fixture() 6 | def user_1(db): 7 | user = User.objects.create_user("test-user") 8 | print('create-user') 9 | return user 10 | 11 | @pytest.fixture 12 | def new_user_factory(db): 13 | def create_app_user( 14 | username: str, 15 | password: str = None, 16 | first_name: str = "firstname", 17 | last_name: str = "lastname", 18 | email: str = "test@test.com", 19 | is_staff: str = False, 20 | is_superuser: str = False, 21 | is_active: str = True, 22 | ): 23 | user = User.objects.create_user( 24 | username=username, 25 | password=password, 26 | first_name=first_name, 27 | last_name=last_name, 28 | email=email, 29 | is_staff=is_staff, 30 | is_superuser=is_superuser, 31 | is_active=is_active, 32 | ) 33 | return user 34 | return create_app_user 35 | 36 | @pytest.fixture 37 | def new_user1(db, new_user_factory): 38 | return new_user_factory("Test_user","password","MyName") 39 | 40 | @pytest.fixture 41 | def new_user2(db, new_user_factory): 42 | return new_user_factory("Test_user","password", "MyName", is_staff="True") -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/__init__.py -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/tests/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-u#gsa9x5f%1t8)6r^y*iimt=6@lv)dnibd@5ys7a7sa$m1e1=i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/db.sqlite3 -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = test_*.py 4 | 5 | markers = 6 | slow: slow running test -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-2 Fixtures and Factories/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # # function Run once per test 4 | # # class Run once per class of tests 5 | # # module Run once per module 6 | # # session Run once per session 7 | 8 | # @pytest.fixture(scope="session") 9 | # def fixture_1(): 10 | # print('run-fixture-1') 11 | # return 1 12 | 13 | # def test_example1(fixture_1): 14 | # print('run-example-1') 15 | # num = fixture_1 16 | # assert num == 1 17 | 18 | # def test_example2(fixture_1): 19 | # print('run-example-2') 20 | # num = fixture_1 21 | # assert num == 1 -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # @pytest.fixture 4 | # def yield_fixture(): 5 | # print('Start Test Phase') 6 | # yield 6 7 | # print('End Test Phase') 8 | 9 | # def test_example(yield_fixture): 10 | # print('run-example-1') 11 | # assert yield_fixture == 6 -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # from django.contrib.auth.models import User 4 | 5 | 6 | # @pytest.mark.django_db 7 | # def test_user_create(): 8 | # User.objects.create_user('test', 'test@test.com', 'test') 9 | # count = User.objects.all().count() 10 | # print(count) 11 | # assert User.objects.count() == 1 12 | 13 | 14 | # @pytest.mark.django_db 15 | # def test_user_create1(): 16 | # count = User.objects.all().count() 17 | # print(count) 18 | # assert count == 0 19 | -------------------------------------------------------------------------------- /Part-2 Fixtures and Factories/tests/test_ex4.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | # @pytest.fixture() 4 | # def user_1(db): 5 | # return User.objects.create_user("test-user") 6 | 7 | # @pytest.mark.django_db 8 | # def test_set_check_password(user_1): 9 | # user_1.set_password("new-password") 10 | # assert user_1.check_password("new-password") is True 11 | 12 | # def test_set_check_password1(user_1): 13 | # print('check-user1') 14 | # assert user_1.username == "test-user" 15 | 16 | # def test_set_check_password2(user_1): 17 | # print('check-user2') 18 | # assert user_1.username == "test-user" 19 | 20 | # def test_new_user(new_user): 21 | # print(new_user.first_name) 22 | # assert new_user.first_name == "MyName" 23 | 24 | def test_new_user(new_user2): 25 | print(new_user2.is_staff) 26 | assert new_user2.is_staff -------------------------------------------------------------------------------- /Part-3 Factory Boy/__pycache__/conftest.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/__pycache__/conftest.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pytest_factoryboy import register 4 | from tests.factories import UserFactory, ProductFactory, CategoryFactory 5 | 6 | register(UserFactory) 7 | register(ProductFactory) 8 | register(CategoryFactory) 9 | 10 | @pytest.fixture 11 | def new_user1(db, user_factory): 12 | user = user_factory.create() 13 | return user -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/__init__.py -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2 on 2021-04-15 10:56 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Category', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=255)), 20 | ], 21 | ), 22 | migrations.CreateModel( 23 | name='Product', 24 | fields=[ 25 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 26 | ('title', models.CharField(help_text='Required', max_length=255, verbose_name='title')), 27 | ('description', models.TextField(blank=True, help_text='Not Required', verbose_name='description')), 28 | ('slug', models.SlugField(max_length=255)), 29 | ('regular_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Regular price')), 30 | ('discount_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Discount price')), 31 | ('is_active', models.BooleanField(default=True, help_text='Change product visibility', verbose_name='Product visibility')), 32 | ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), 33 | ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')), 34 | ('category', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app1.category')), 35 | ], 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | class Category(models.Model): 5 | name = models.CharField( 6 | max_length=255, 7 | ) 8 | 9 | def __str__(self): 10 | return self.name 11 | 12 | class Product(models.Model): 13 | """ 14 | The Product table contining all product items. 15 | """ 16 | title = models.CharField( 17 | verbose_name=_("title"), 18 | help_text=_("Required"), 19 | max_length=255, 20 | ) 21 | category = models.ForeignKey(Category, on_delete=models.RESTRICT) 22 | description = models.TextField(verbose_name=_("description"), help_text=_("Not Required"), blank=True) 23 | slug = models.SlugField(max_length=255) 24 | regular_price = models.DecimalField( 25 | verbose_name=_("Regular price"), 26 | help_text=_("Maximum 999.99"), 27 | error_messages={ 28 | "name": { 29 | "max_length": _("The price must be between 0 and 999.99."), 30 | }, 31 | }, 32 | max_digits=5, 33 | decimal_places=2, 34 | ) 35 | discount_price = models.DecimalField( 36 | verbose_name=_("Discount price"), 37 | help_text=_("Maximum 999.99"), 38 | error_messages={ 39 | "name": { 40 | "max_length": _("The price must be between 0 and 999.99."), 41 | }, 42 | }, 43 | max_digits=5, 44 | decimal_places=2, 45 | ) 46 | is_active = models.BooleanField( 47 | verbose_name=_("Product visibility"), 48 | help_text=_("Change product visibility"), 49 | default=True, 50 | ) 51 | created_at = models.DateTimeField(_("Created at"), auto_now_add=True, editable=False) 52 | updated_at = models.DateTimeField(_("Updated at"), auto_now=True) 53 | 54 | def __str__(self): 55 | return self.title 56 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/tests/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-u#gsa9x5f%1t8)6r^y*iimt=6@lv)dnibd@5ys7a7sa$m1e1=i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/db.sqlite3 -------------------------------------------------------------------------------- /Part-3 Factory Boy/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = test_*.py 4 | 5 | markers = 6 | slow: slow running test -------------------------------------------------------------------------------- /Part-3 Factory Boy/requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.3.4 2 | atomicwrites==1.4.0 3 | attrs==20.3.0 4 | colorama==0.4.4 5 | Django==3.2 6 | factory-boy==3.2.0 7 | Faker==8.1.0 8 | inflection==0.5.1 9 | iniconfig==1.1.1 10 | packaging==20.9 11 | pluggy==0.13.1 12 | py==1.10.0 13 | pyparsing==2.4.7 14 | pytest==6.2.3 15 | pytest-django==4.2.0 16 | pytest-factoryboy==2.1.0 17 | python-dateutil==2.8.1 18 | pytz==2021.1 19 | six==1.15.0 20 | sqlparse==0.4.1 21 | text-unidecode==1.3 22 | toml==0.10.2 23 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/__pycache__/factories.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/tests/__pycache__/factories.cpython-39.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-3 Factory Boy/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/factories.py: -------------------------------------------------------------------------------- 1 | import factory 2 | from faker import Faker 3 | fake = Faker() 4 | 5 | from django.contrib.auth.models import User 6 | from core.app1 import models 7 | 8 | 9 | class UserFactory(factory.django.DjangoModelFactory): 10 | class Meta: 11 | model = User 12 | 13 | username = fake.name() 14 | is_staff = 'True' 15 | 16 | 17 | class CategoryFactory(factory.django.DjangoModelFactory): 18 | class Meta: 19 | model = models.Category 20 | 21 | name = 'django' 22 | 23 | 24 | class ProductFactory(factory.django.DjangoModelFactory): 25 | class Meta: 26 | model = models.Product 27 | 28 | title = 'product_title' 29 | category = factory.SubFactory(CategoryFactory) 30 | description = fake.text() 31 | slug = 'product_slug' 32 | regular_price = '9.99' 33 | discount_price = '4.99' -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # # function Run once per test 4 | # # class Run once per class of tests 5 | # # module Run once per module 6 | # # session Run once per session 7 | 8 | # @pytest.fixture(scope="session") 9 | # def fixture_1(): 10 | # print('run-fixture-1') 11 | # return 1 12 | 13 | # def test_example1(fixture_1): 14 | # print('run-example-1') 15 | # num = fixture_1 16 | # assert num == 1 17 | 18 | # def test_example2(fixture_1): 19 | # print('run-example-2') 20 | # num = fixture_1 21 | # assert num == 1 -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # @pytest.fixture 4 | # def yield_fixture(): 5 | # print('Start Test Phase') 6 | # yield 6 7 | # print('End Test Phase') 8 | 9 | # def test_example(yield_fixture): 10 | # print('run-example-1') 11 | # assert yield_fixture == 6 -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # from django.contrib.auth.models import User 4 | 5 | 6 | # @pytest.mark.django_db 7 | # def test_user_create(): 8 | # User.objects.create_user('test', 'test@test.com', 'test') 9 | # count = User.objects.all().count() 10 | # print(count) 11 | # assert User.objects.count() == 1 12 | 13 | 14 | # @pytest.mark.django_db 15 | # def test_user_create1(): 16 | # count = User.objects.all().count() 17 | # print(count) 18 | # assert count == 0 19 | -------------------------------------------------------------------------------- /Part-3 Factory Boy/tests/test_ex4.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from django.contrib.auth.models import User 3 | # @pytest.fixture() 4 | # def user_1(db): 5 | # return User.objects.create_user("test-user") 6 | 7 | # @pytest.mark.django_db 8 | # def test_set_check_password(user_1): 9 | # user_1.set_password("new-password") 10 | # assert user_1.check_password("new-password") is True 11 | 12 | # def test_set_check_password1(user_1): 13 | # print('check-user1') 14 | # assert user_1.username == "test-user" 15 | 16 | # def test_set_check_password2(user_1): 17 | # print('check-user2') 18 | # assert user_1.username == "test-user" 19 | 20 | # def test_new_user(new_user): 21 | # print(new_user.first_name) 22 | # assert new_user.first_name == "MyName" 23 | 24 | # def test_new_user(new_user2): 25 | # print(new_user2.is_staff) 26 | # assert new_user2.is_staff 27 | 28 | # def test_new_user(new_user1): 29 | # print(new_user1.username) 30 | # assert True 31 | 32 | def test_product(db, product_factory): 33 | product = product_factory.create() 34 | print(product.description) 35 | assert True -------------------------------------------------------------------------------- /Part-4 Parametrizing/.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "editor.formatOnSave": true, 3 | "python.pythonPath": "venv\\Scripts\\python.exe", 4 | "python.sortImports.args": [ 5 | "--profile=black", 6 | ], 7 | "python.formatting.provider": "black", 8 | "python.formatting.blackArgs": [ 9 | "--line-length=119" 10 | ], 11 | "[python]": { 12 | "editor.codeActionsOnSave": { 13 | "source.organizeImports": true 14 | } 15 | }, 16 | // Django Extension 17 | "files.associations": { 18 | "**/*.html": "html", 19 | "**/templates/**/*.html": "django-html", 20 | "**/templates/**/*": "django-txt", 21 | "**/requirements{/**,*}.{txt,in}": "pip-requirements" 22 | }, 23 | } -------------------------------------------------------------------------------- /Part-4 Parametrizing/conftest.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | 3 | from pytest_factoryboy import register 4 | from tests.factories import UserFactory, ProductFactory, CategoryFactory 5 | 6 | register(UserFactory) 7 | register(ProductFactory) 8 | register(CategoryFactory) 9 | 10 | @pytest.fixture 11 | def new_user1(db, user_factory): 12 | user = user_factory.create() 13 | return user -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/__init__.py -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/__pycache__/settings.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/__pycache__/settings.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/__pycache__/urls.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/__pycache__/urls.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/__pycache__/wsgi.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/__pycache__/wsgi.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/__init__.py -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/__pycache__/admin.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/__pycache__/admin.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/__pycache__/apps.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/__pycache__/apps.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/__pycache__/models.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/__pycache__/models.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | # Register your models here. 4 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class App1Config(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'core.app1' 7 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.2 on 2021-04-15 10:56 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | initial = True 10 | 11 | dependencies = [ 12 | ] 13 | 14 | operations = [ 15 | migrations.CreateModel( 16 | name='Category', 17 | fields=[ 18 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 19 | ('name', models.CharField(max_length=255)), 20 | ], 21 | ), 22 | migrations.CreateModel( 23 | name='Product', 24 | fields=[ 25 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 26 | ('title', models.CharField(help_text='Required', max_length=255, verbose_name='title')), 27 | ('description', models.TextField(blank=True, help_text='Not Required', verbose_name='description')), 28 | ('slug', models.SlugField(max_length=255)), 29 | ('regular_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Regular price')), 30 | ('discount_price', models.DecimalField(decimal_places=2, error_messages={'name': {'max_length': 'The price must be between 0 and 999.99.'}}, help_text='Maximum 999.99', max_digits=5, verbose_name='Discount price')), 31 | ('is_active', models.BooleanField(default=True, help_text='Change product visibility', verbose_name='Product visibility')), 32 | ('created_at', models.DateTimeField(auto_now_add=True, verbose_name='Created at')), 33 | ('updated_at', models.DateTimeField(auto_now=True, verbose_name='Updated at')), 34 | ('category', models.ForeignKey(on_delete=django.db.models.deletion.RESTRICT, to='app1.category')), 35 | ], 36 | ), 37 | ] 38 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/migrations/__init__.py -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/migrations/__pycache__/0001_initial.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/migrations/__pycache__/__init__.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/core/app1/migrations/__pycache__/__init__.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | from django.utils.translation import gettext_lazy as _ 3 | 4 | 5 | class Category(models.Model): 6 | name = models.CharField( 7 | max_length=255, 8 | ) 9 | 10 | def __str__(self): 11 | return self.name 12 | 13 | 14 | class Product(models.Model): 15 | """ 16 | The Product table contining all product items. 17 | """ 18 | 19 | title = models.CharField( 20 | verbose_name=_("title"), 21 | help_text=_("Required"), 22 | max_length=255, 23 | ) 24 | category = models.ForeignKey(Category, on_delete=models.RESTRICT) 25 | description = models.TextField(verbose_name=_("description"), help_text=_("Not Required"), blank=True) 26 | slug = models.SlugField(max_length=255) 27 | regular_price = models.DecimalField( 28 | verbose_name=_("Regular price"), 29 | help_text=_("Maximum 999.99"), 30 | error_messages={ 31 | "name": { 32 | "max_length": _("The price must be between 0 and 999.99."), 33 | }, 34 | }, 35 | max_digits=5, 36 | decimal_places=2, 37 | ) 38 | discount_price = models.DecimalField( 39 | verbose_name=_("Discount price"), 40 | help_text=_("Maximum 999.99"), 41 | error_messages={ 42 | "name": { 43 | "max_length": _("The price must be between 0 and 999.99."), 44 | }, 45 | }, 46 | max_digits=5, 47 | decimal_places=2, 48 | ) 49 | is_active = models.BooleanField( 50 | verbose_name=_("Product visibility"), 51 | help_text=_("Change product visibility"), 52 | default=True, 53 | ) 54 | created_at = models.DateTimeField(_("Created at"), auto_now_add=True, editable=False) 55 | updated_at = models.DateTimeField(_("Updated at"), auto_now=True) 56 | 57 | # def clean(self): 58 | # if self.regular_price == "": 59 | # raise ValidationError({"website": "Joe must have a website"}) 60 | 61 | def __str__(self): 62 | return self.title 63 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/tests/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/app1/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import render 2 | 3 | # Create your views here. 4 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for core project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for core project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.2. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.2/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | 15 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 16 | BASE_DIR = Path(__file__).resolve().parent.parent 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'django-insecure-u#gsa9x5f%1t8)6r^y*iimt=6@lv)dnibd@5ys7a7sa$m1e1=i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = [] 29 | 30 | 31 | # Application definition 32 | 33 | INSTALLED_APPS = [ 34 | 'django.contrib.admin', 35 | 'django.contrib.auth', 36 | 'django.contrib.contenttypes', 37 | 'django.contrib.sessions', 38 | 'django.contrib.messages', 39 | 'django.contrib.staticfiles', 40 | 'core.app1', 41 | ] 42 | 43 | MIDDLEWARE = [ 44 | 'django.middleware.security.SecurityMiddleware', 45 | 'django.contrib.sessions.middleware.SessionMiddleware', 46 | 'django.middleware.common.CommonMiddleware', 47 | 'django.middleware.csrf.CsrfViewMiddleware', 48 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 49 | 'django.contrib.messages.middleware.MessageMiddleware', 50 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 51 | ] 52 | 53 | ROOT_URLCONF = 'core.urls' 54 | 55 | TEMPLATES = [ 56 | { 57 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 58 | 'DIRS': [], 59 | 'APP_DIRS': True, 60 | 'OPTIONS': { 61 | 'context_processors': [ 62 | 'django.template.context_processors.debug', 63 | 'django.template.context_processors.request', 64 | 'django.contrib.auth.context_processors.auth', 65 | 'django.contrib.messages.context_processors.messages', 66 | ], 67 | }, 68 | }, 69 | ] 70 | 71 | WSGI_APPLICATION = 'core.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.2/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.sqlite3', 80 | 'NAME': BASE_DIR / 'db.sqlite3', 81 | } 82 | } 83 | 84 | 85 | # Password validation 86 | # https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators 87 | 88 | AUTH_PASSWORD_VALIDATORS = [ 89 | { 90 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 91 | }, 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 100 | }, 101 | ] 102 | 103 | 104 | # Internationalization 105 | # https://docs.djangoproject.com/en/3.2/topics/i18n/ 106 | 107 | LANGUAGE_CODE = 'en-us' 108 | 109 | TIME_ZONE = 'UTC' 110 | 111 | USE_I18N = True 112 | 113 | USE_L10N = True 114 | 115 | USE_TZ = True 116 | 117 | 118 | # Static files (CSS, JavaScript, Images) 119 | # https://docs.djangoproject.com/en/3.2/howto/static-files/ 120 | 121 | STATIC_URL = '/static/' 122 | 123 | # Default primary key field type 124 | # https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field 125 | 126 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 127 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/urls.py: -------------------------------------------------------------------------------- 1 | """core URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.2/topics/http/urls/ 5 | Examples: 6 | Function views 7 | 1. Add an import: from my_app import views 8 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 9 | Class-based views 10 | 1. Add an import: from other_app.views import Home 11 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 12 | Including another URLconf 13 | 1. Import the include() function: from django.urls import include, path 14 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 15 | """ 16 | from django.contrib import admin 17 | from django.urls import path 18 | 19 | urlpatterns = [ 20 | path('admin/', admin.site.urls), 21 | ] 22 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/core/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for core project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.2/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/db.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/db.sqlite3 -------------------------------------------------------------------------------- /Part-4 Parametrizing/manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'core.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/pytest.ini: -------------------------------------------------------------------------------- 1 | [pytest] 2 | DJANGO_SETTINGS_MODULE = core.settings 3 | python_files = test_*.py 4 | 5 | markers = 6 | slow: slow running test -------------------------------------------------------------------------------- /Part-4 Parametrizing/requirements.txt: -------------------------------------------------------------------------------- 1 | appdirs==1.4.4 2 | asgiref==3.3.4 3 | atomicwrites==1.4.0 4 | attrs==20.3.0 5 | black==20.8b1 6 | click==7.1.2 7 | colorama==0.4.4 8 | Django==3.2 9 | factory-boy==3.2.0 10 | Faker==8.1.0 11 | inflection==0.5.1 12 | iniconfig==1.1.1 13 | isort==5.8.0 14 | mypy-extensions==0.4.3 15 | packaging==20.9 16 | pathspec==0.8.1 17 | pluggy==0.13.1 18 | py==1.10.0 19 | pyparsing==2.4.7 20 | pytest==6.2.3 21 | pytest-django==4.2.0 22 | pytest-factoryboy==2.1.0 23 | python-dateutil==2.8.1 24 | pytz==2021.1 25 | regex==2021.4.4 26 | six==1.15.0 27 | sqlparse==0.4.1 28 | text-unidecode==1.3 29 | toml==0.10.2 30 | typed-ast==1.4.3 31 | typing-extensions==3.7.4.3 32 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/factories.cpython-39.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/factories.cpython-39.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/test_ex1.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/test_ex2.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/test_ex3.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/test_ex4.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/veryacademy/pytest-mastery-with-django/f308722641710ceb47d4fb70db1509086621f4e8/Part-4 Parametrizing/tests/__pycache__/test_ex5.cpython-39-pytest-6.2.3.pyc -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/factories.py: -------------------------------------------------------------------------------- 1 | import factory 2 | from faker import Faker 3 | fake = Faker() 4 | 5 | from django.contrib.auth.models import User 6 | from core.app1 import models 7 | 8 | 9 | class UserFactory(factory.django.DjangoModelFactory): 10 | class Meta: 11 | model = User 12 | 13 | username = fake.name() 14 | is_staff = 'True' 15 | 16 | 17 | class CategoryFactory(factory.django.DjangoModelFactory): 18 | class Meta: 19 | model = models.Category 20 | 21 | name = 'django' 22 | 23 | 24 | class ProductFactory(factory.django.DjangoModelFactory): 25 | class Meta: 26 | model = models.Product 27 | 28 | title = 'product_title' 29 | category = factory.SubFactory(CategoryFactory) 30 | description = fake.text() 31 | slug = 'product_slug' 32 | regular_price = '9.99' 33 | discount_price = '4.99' -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/test_ex1.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # # function Run once per test 4 | # # class Run once per class of tests 5 | # # module Run once per module 6 | # # session Run once per session 7 | 8 | # @pytest.fixture(scope="session") 9 | # def fixture_1(): 10 | # print('run-fixture-1') 11 | # return 1 12 | 13 | # def test_example1(fixture_1): 14 | # print('run-example-1') 15 | # num = fixture_1 16 | # assert num == 1 17 | 18 | # def test_example2(fixture_1): 19 | # print('run-example-2') 20 | # num = fixture_1 21 | # assert num == 1 -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/test_ex2.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # @pytest.fixture 4 | # def yield_fixture(): 5 | # print('Start Test Phase') 6 | # yield 6 7 | # print('End Test Phase') 8 | 9 | # def test_example(yield_fixture): 10 | # print('run-example-1') 11 | # assert yield_fixture == 6 -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/test_ex3.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | 3 | # from django.contrib.auth.models import User 4 | 5 | 6 | # @pytest.mark.django_db 7 | # def test_user_create(): 8 | # User.objects.create_user('test', 'test@test.com', 'test') 9 | # count = User.objects.all().count() 10 | # print(count) 11 | # assert User.objects.count() == 1 12 | 13 | 14 | # @pytest.mark.django_db 15 | # def test_user_create1(): 16 | # count = User.objects.all().count() 17 | # print(count) 18 | # assert count == 0 19 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/test_ex4.py: -------------------------------------------------------------------------------- 1 | # import pytest 2 | # from core.app1.models import Product 3 | # from django.contrib.auth.models import User 4 | 5 | # # from django.core.exceptions import ValidationError 6 | 7 | # # @pytest.fixture() 8 | # # def user_1(db): 9 | # # return User.objects.create_user("test-user") 10 | 11 | # # @pytest.mark.django_db 12 | # # def test_set_check_password(user_1): 13 | # # user_1.set_password("new-password") 14 | # # assert user_1.check_password("new-password") is True 15 | 16 | # # def test_set_check_password1(user_1): 17 | # # print('check-user1') 18 | # # assert user_1.username == "test-user" 19 | 20 | # # def test_set_check_password2(user_1): 21 | # # print('check-user2') 22 | # # assert user_1.username == "test-user" 23 | 24 | # # def test_new_user(new_user): 25 | # # print(new_user.first_name) 26 | # # assert new_user.first_name == "MyName" 27 | 28 | # # def test_new_user(new_user2): 29 | # # print(new_user2.is_staff) 30 | # # assert new_user2.is_staff 31 | 32 | # # def test_new_user(new_user1): 33 | # # print(new_user1.username) 34 | # # assert True 35 | 36 | 37 | # # def test_product(db, product_factory): 38 | # # product = product_factory.create() 39 | # # print(product.description) 40 | # # assert True 41 | 42 | 43 | # @pytest.mark.parametrize( 44 | # "title, category, description, slug, regular_price, discount_price, validity", 45 | # [ 46 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 47 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 48 | # ], 49 | # ) 50 | # def test_product_instance( 51 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 52 | # ): 53 | 54 | # test = product_factory( 55 | # title=title, 56 | # category_id=category, 57 | # description=description, 58 | # slug=slug, 59 | # regular_price=regular_price, 60 | # discount_price=discount_price, 61 | # ) 62 | 63 | # item = Product.objects.all().count() 64 | # print(test) 65 | # assert item == validity 66 | 67 | 68 | # @pytest.mark.parametrize( 69 | # "title, category, description, slug, regular_price, discount_price, validity", 70 | # [ 71 | # ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 72 | # ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 73 | # ], 74 | # ) 75 | # def test_product_instance( 76 | # db, product_factory, title, category, description, slug, regular_price, discount_price, validity 77 | # ): 78 | 79 | # test = product_factory( 80 | # title=title, 81 | # category_id=category, 82 | # description=description, 83 | # slug=slug, 84 | # regular_price=regular_price, 85 | # discount_price=discount_price, 86 | # ) 87 | 88 | # item = Product.objects.all().count() 89 | # print(test) 90 | # assert item == validity 91 | -------------------------------------------------------------------------------- /Part-4 Parametrizing/tests/test_ex5.py: -------------------------------------------------------------------------------- 1 | import pytest 2 | from core.app1.models import Product 3 | 4 | 5 | @pytest.mark.parametrize( 6 | "title, category, description, slug, regular_price, discount_price, validity", 7 | [ 8 | ("NewTitle", 1, "NewDescription", "slug", "4.99", "3.99", True), 9 | ("NewTitle", 1, "NewDescription", "slug", "", "3.99", False), 10 | ], 11 | ) 12 | def test_product_instance( 13 | db, product_factory, title, category, description, slug, regular_price, discount_price, validity 14 | ): 15 | 16 | test = product_factory( 17 | title=title, 18 | category_id=category, 19 | description=description, 20 | slug=slug, 21 | regular_price=regular_price, 22 | discount_price=discount_price, 23 | ) 24 | 25 | item = Product.objects.all().count() 26 | print(item) 27 | assert item == validity 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |  2 | 3 |