├── .gitignore ├── .travis.yml ├── Dockerfile ├── README.md ├── airlines ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── docker-compose.yml ├── flights ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ ├── 0002_auto_20200430_2040.py │ ├── 0003_auto_20200430_2103.py │ ├── 0004_passenger.py │ ├── 0005_auto_20200430_2229.py │ └── __init__.py ├── models.py ├── static │ └── flights │ │ └── styles.css ├── templates │ └── flights │ │ ├── base.html │ │ ├── error.html │ │ ├── flight.html │ │ └── index.html ├── tests.py ├── urls.py └── views.py ├── manage.py ├── pythonTests ├── assert0.py ├── prime.py ├── test0.py ├── test0.sh └── test1.py └── requirements.txt /.gitignore: -------------------------------------------------------------------------------- 1 | .vscode/ -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: 3 | - "3.7" 4 | # command to install dependencies 5 | install: 6 | - pip install -r requirements.txt 7 | # command to run tests 8 | script: 9 | - python manage.py test 10 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM python:3.7 2 | WORKDIR /usr/src/app 3 | ADD requirements.txt /usr/src/app 4 | RUN pip install -r requirements.txt 5 | ADD . /usr/src/app 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # unitest-django 2 | -------------------------------------------------------------------------------- /airlines/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saedyousef/unitest-django/e79babfcdcf0db3a0b6f2bb26b9ce498b377b599/airlines/__init__.py -------------------------------------------------------------------------------- /airlines/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for airlines 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.0/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', 'airlines.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /airlines/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for airlines project. 3 | 4 | Generated by 'django-admin startproject' using Django 3.0.5. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/3.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/3.0/ref/settings/ 11 | """ 12 | 13 | import os 14 | 15 | # Build paths inside the project like this: os.path.join(BASE_DIR, ...) 16 | BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) 17 | 18 | 19 | # Quick-start development settings - unsuitable for production 20 | # See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/ 21 | 22 | # SECURITY WARNING: keep the secret key used in production secret! 23 | SECRET_KEY = 'tx-f%(w(8qu#iewud#kugu4lku6^ub&08nuimo@)n3o2^i-x(i' 24 | 25 | # SECURITY WARNING: don't run with debug turned on in production! 26 | DEBUG = True 27 | 28 | ALLOWED_HOSTS = ['0.0.0.0'] 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 | 'flights.apps.FlightsConfig' 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 = 'airlines.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 = 'airlines.wsgi.application' 72 | 73 | 74 | # Database 75 | # https://docs.djangoproject.com/en/3.0/ref/settings/#databases 76 | 77 | DATABASES = { 78 | 'default': { 79 | 'ENGINE': 'django.db.backends.postgresql', 80 | 'NAME': 'postgres', 81 | 'USER': 'postgres', 82 | 'HOST': 'db', 83 | 'PORT': 5432, 84 | } 85 | } 86 | 87 | 88 | # Password validation 89 | # https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators 90 | 91 | AUTH_PASSWORD_VALIDATORS = [ 92 | { 93 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 94 | }, 95 | { 96 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 97 | }, 98 | { 99 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 100 | }, 101 | { 102 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 103 | }, 104 | ] 105 | 106 | 107 | # Internationalization 108 | # https://docs.djangoproject.com/en/3.0/topics/i18n/ 109 | 110 | LANGUAGE_CODE = 'en-us' 111 | 112 | TIME_ZONE = 'UTC' 113 | 114 | USE_I18N = True 115 | 116 | USE_L10N = True 117 | 118 | USE_TZ = True 119 | 120 | 121 | # Static files (CSS, JavaScript, Images) 122 | # https://docs.djangoproject.com/en/3.0/howto/static-files/ 123 | 124 | STATIC_URL = '/static/' 125 | -------------------------------------------------------------------------------- /airlines/urls.py: -------------------------------------------------------------------------------- 1 | """airlines URL Configuration 2 | 3 | The `urlpatterns` list routes URLs to views. For more information please see: 4 | https://docs.djangoproject.com/en/3.0/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, include 18 | 19 | urlpatterns = [ 20 | path('', include('flights.urls')), 21 | path('admin/', admin.site.urls), 22 | ] 23 | -------------------------------------------------------------------------------- /airlines/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for airlines 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.0/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', 'airlines.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | version: '3' 2 | services: 3 | db: 4 | image: postgres 5 | environment: 6 | POSTGRES_DB: "db" 7 | POSTGRES_HOST_AUTH_METHOD: "trust" 8 | migration: 9 | build: . 10 | command: python3 manage.py migrate 11 | volumes: 12 | - .:/usr/src/app 13 | depends_on: 14 | - db 15 | web: 16 | build: . 17 | command: python3 manage.py runserver 0.0.0.0:8000 18 | volumes: 19 | - .:/usr/src/app 20 | ports: 21 | - "8000:8000" 22 | depends_on: 23 | - db 24 | - migration 25 | -------------------------------------------------------------------------------- /flights/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saedyousef/unitest-django/e79babfcdcf0db3a0b6f2bb26b9ce498b377b599/flights/__init__.py -------------------------------------------------------------------------------- /flights/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | 3 | from .models import Airport, Flight, Passenger 4 | # Register your models here. 5 | 6 | class PassengerInline(admin.StackedInline): 7 | model = Passenger.flights.through 8 | extra = 1 9 | 10 | class FlightAdmin(admin.ModelAdmin): 11 | inlines = [PassengerInline] 12 | 13 | class PassengerAdmin(admin.ModelAdmin): 14 | filter_horizontal = ('flights',) 15 | 16 | admin.site.register(Airport) 17 | admin.site.register(Flight, FlightAdmin) 18 | admin.site.register(Passenger, PassengerAdmin) -------------------------------------------------------------------------------- /flights/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class FlightsConfig(AppConfig): 5 | name = 'flights' 6 | -------------------------------------------------------------------------------- /flights/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-30 20:38 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='Flight', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('origin', models.CharField(max_length=64)), 19 | ('destination', models.IntegerField()), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /flights/migrations/0002_auto_20200430_2040.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-30 20:40 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('flights', '0001_initial'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AddField( 14 | model_name='flight', 15 | name='duration', 16 | field=models.IntegerField(default=1), 17 | preserve_default=False, 18 | ), 19 | migrations.AlterField( 20 | model_name='flight', 21 | name='destination', 22 | field=models.CharField(max_length=64), 23 | ), 24 | ] 25 | -------------------------------------------------------------------------------- /flights/migrations/0003_auto_20200430_2103.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-30 21:03 2 | 3 | from django.db import migrations, models 4 | import django.db.models.deletion 5 | 6 | 7 | class Migration(migrations.Migration): 8 | 9 | dependencies = [ 10 | ('flights', '0002_auto_20200430_2040'), 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='Airport', 16 | fields=[ 17 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('code', models.CharField(max_length=3)), 19 | ('city', models.CharField(max_length=64)), 20 | ], 21 | ), 22 | migrations.AlterField( 23 | model_name='flight', 24 | name='destination', 25 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='arrivals', to='flights.Airport'), 26 | ), 27 | migrations.AlterField( 28 | model_name='flight', 29 | name='origin', 30 | field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='departures', to='flights.Airport'), 31 | ), 32 | ] 33 | -------------------------------------------------------------------------------- /flights/migrations/0004_passenger.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-30 22:23 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('flights', '0003_auto_20200430_2103'), 10 | ] 11 | 12 | operations = [ 13 | migrations.CreateModel( 14 | name='Passenger', 15 | fields=[ 16 | ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 17 | ('first', models.CharField(max_length=64)), 18 | ('last', models.CharField(max_length=64)), 19 | ('flights', models.ManyToManyField(blank=True, related_name='passenger', to='flights.Flight')), 20 | ], 21 | ), 22 | ] 23 | -------------------------------------------------------------------------------- /flights/migrations/0005_auto_20200430_2229.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 3.0.5 on 2020-04-30 22:29 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | dependencies = [ 9 | ('flights', '0004_passenger'), 10 | ] 11 | 12 | operations = [ 13 | migrations.AlterField( 14 | model_name='passenger', 15 | name='flights', 16 | field=models.ManyToManyField(blank=True, related_name='passengers', to='flights.Flight'), 17 | ), 18 | ] 19 | -------------------------------------------------------------------------------- /flights/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/saedyousef/unitest-django/e79babfcdcf0db3a0b6f2bb26b9ce498b377b599/flights/migrations/__init__.py -------------------------------------------------------------------------------- /flights/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | # Create your models here. 4 | 5 | class Airport(models.Model): 6 | code = models.CharField(max_length=3) 7 | city = models.CharField(max_length=64) 8 | 9 | def __str__(self): 10 | return f"{self.city} ({self.code})" 11 | 12 | class Flight(models.Model): 13 | origin = models.ForeignKey(Airport, on_delete = models.CASCADE, related_name="departures") 14 | destination = models.ForeignKey(Airport, on_delete = models.CASCADE, related_name="arrivals") 15 | duration = models.IntegerField() 16 | 17 | def is_valid_flight(self): 18 | return (self.origin != self.destination) and (self.duration >= 0) 19 | 20 | def __str__(self): 21 | return f"{self.id} - {self.origin} to {self.destination} lasting {self.duration} minutes" 22 | 23 | class Passenger(models.Model): 24 | first = models.CharField(max_length=64) 25 | last = models.CharField(max_length=64) 26 | flights = models.ManyToManyField(Flight, blank=True, related_name="passengers") 27 | 28 | def __str__(self): 29 | return f"{self.first} {self.last}" -------------------------------------------------------------------------------- /flights/static/flights/styles.css: -------------------------------------------------------------------------------- 1 | body { 2 | color: black; 3 | } -------------------------------------------------------------------------------- /flights/templates/flights/base.html: -------------------------------------------------------------------------------- 1 | {% load static %} 2 | 3 | 4 | 5 | {% block title %}{% endblock %} 6 | 7 | 8 | 9 | {% block body %} 10 | {% endblock %} 11 | 12 | -------------------------------------------------------------------------------- /flights/templates/flights/error.html: -------------------------------------------------------------------------------- 1 | Erros -------------------------------------------------------------------------------- /flights/templates/flights/flight.html: -------------------------------------------------------------------------------- 1 | {% extends "flights/base.html" %} 2 | 3 | {% block title%} 4 | Flight {{flight.id}} 5 | {% endblock %} 6 | 7 | {% block body %} 8 |

Flight {{ flight_id }}

9 | 16 |

Passengers

17 | 24 |
25 |

Add a Passenger

26 | {% if non_passengers %} 27 |
28 | {% csrf_token %} 29 | 34 | 35 |
36 | {% else %} 37 |
No passengers to add
38 | {% endif %} 39 |
40 | Back to full listing 41 | {% endblock %} -------------------------------------------------------------------------------- /flights/templates/flights/index.html: -------------------------------------------------------------------------------- 1 | {% extends "flights/base.html" %} 2 | 3 | {% block title%} 4 | Flights 5 | {% endblock %} 6 | 7 | {% block body %} 8 |

Flights ...

9 | 16 | {% endblock %} -------------------------------------------------------------------------------- /flights/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase, Client 2 | from .models import Airport, Flight, Passenger 3 | from django.db.models import Max 4 | # Create your tests here. 5 | 6 | # Models teses goes here. 7 | class ModelsTestCase(TestCase): 8 | 9 | def setUp(self): 10 | 11 | # Create airports. 12 | a1 = Airport.objects.create(code="AAA", city="City A") 13 | a2 = Airport.objects.create(code="BBB", city="City B") 14 | 15 | # Create flights. 16 | Flight.objects.create(origin=a1, destination=a2, duration=100) 17 | Flight.objects.create(origin=a1, destination=a1, duration=200) 18 | 19 | def test_departures_count(self): 20 | a = Airport.objects.get(code="AAA") 21 | self.assertEqual(a.departures.count(), 2) 22 | 23 | def test_arrivals_count(self): 24 | a = Airport.objects.get(code="AAA") 25 | self.assertEqual(a.arrivals.count(), 1) 26 | 27 | def test_valid_flight(self): 28 | a1 = Airport.objects.get(code="AAA") 29 | a2 = Airport.objects.get(code="BBB") 30 | f = Flight.objects.get(origin=a1, destination=a2, duration=100) 31 | self.assertTrue(f.is_valid_flight()) 32 | 33 | def test_invalid_flight_destination(self): 34 | a1 = Airport.objects.get(code="AAA") 35 | f = Flight.objects.get(origin=a1, destination=a1) 36 | self.assertFalse(f.is_valid_flight()) 37 | 38 | def test_invalid_flight_duration(self): 39 | a1 = Airport.objects.get(code="AAA") 40 | a2 = Airport.objects.get(code="BBB") 41 | f = Flight.objects.get(origin=a1, destination=a2) 42 | f.duration = -100 43 | self.assertFalse(f.is_valid_flight()) 44 | 45 | def test_index(self): 46 | c = Client() 47 | response = c.get('/') 48 | self.assertEqual(response.status_code, 200) 49 | self.assertEqual(response.context['flights'].count(), 2) 50 | 51 | def test_valid_flight(self): 52 | a1 = Airport.objects.get(code="AAA") 53 | f = Flight.objects.get(origin=a1, destination=a1) 54 | 55 | c = Client() 56 | response = c.get(f"/{f.id}") 57 | self.assertEqual(response.status_code, 200) 58 | 59 | def test_invalid_flight(self): 60 | max_id = Flight.objects.aggregate(Max('id'))['id__max'] 61 | c = Client() 62 | response = c.get(f"/{max_id + 1}") 63 | self.assertEqual(response.status_code, 404) 64 | 65 | def test_flight_page_passengers(self): 66 | f = Flight.objects.get(pk=1) 67 | p = Passenger.objects.create(first="Saed", last="Yousef") 68 | f.passengers.add(p) 69 | 70 | c = Client() 71 | response = c.get(f"/{f.id}") 72 | self.assertEqual(response.status_code, 200) 73 | self.assertEqual(response.context['passengers'].count(), 1) 74 | 75 | def test_flight_page_non_passengers(self): 76 | f = Flight.objects.get(pk=1) 77 | p = Passenger.objects.create(first="Saed", last="Yousef") 78 | 79 | c = Client() 80 | response = c.get(f"/{f.id}") 81 | self.assertEqual(response.status_code, 200) 82 | self.assertEqual(response.context['non_passengers'].count(), 1) 83 | -------------------------------------------------------------------------------- /flights/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from . import views 3 | 4 | urlpatterns = [ 5 | path('', views.index, name='index'), 6 | path('', views.flight, name='flight'), 7 | path('/book', views.book, name='book'), 8 | ] -------------------------------------------------------------------------------- /flights/views.py: -------------------------------------------------------------------------------- 1 | from django.http import HttpResponse, Http404, HttpResponseRedirect 2 | from django.shortcuts import render 3 | from django.urls import reverse 4 | 5 | from .models import Flight, Passenger 6 | # Create your views here. 7 | def index(request): 8 | context = { 9 | 'flights' : Flight.objects.all() 10 | } 11 | return render(request, 'flights/index.html', context) 12 | 13 | def flight(request, flight_id): 14 | try: 15 | flight = Flight.objects.get(pk=flight_id) 16 | except Flight.DoesNotExist: 17 | raise Http404('Flight does not exist.') 18 | context = { 19 | 'flight' : flight, 20 | 'passengers' : flight.passengers.all(), 21 | 'non_passengers': Passenger.objects.exclude(flights=flight).all() 22 | } 23 | return render(request, 'flights/flight.html', context) 24 | 25 | def book(request, flight_id): 26 | try: 27 | passenger_id = int(request.POST['passenger']) 28 | passenger = Passenger.objects.get(pk=passenger_id) 29 | flight = Flight.objects.get(pk=flight_id) 30 | except KeyError: 31 | return render(request, 'flights/error.html', {'message' : 'No selections.'}) 32 | except Passenger.DoesNotExist: 33 | return render(request, 'flights/error.html', {'message' : 'No passenger.'}) 34 | except Flight.DoesNotExist: 35 | return render(request, 'flights/error.html', {'message' : 'No flight.'}) 36 | passenger.flights.add(flight) 37 | return HttpResponseRedirect(reverse('flight', args=[flight_id])) 38 | -------------------------------------------------------------------------------- /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 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'airlines.settings') 9 | try: 10 | from django.core.management import execute_from_command_line 11 | except ImportError as exc: 12 | raise ImportError( 13 | "Couldn't import Django. Are you sure it's installed and " 14 | "available on your PYTHONPATH environment variable? Did you " 15 | "forget to activate a virtual environment?" 16 | ) from exc 17 | execute_from_command_line(sys.argv) 18 | 19 | 20 | if __name__ == '__main__': 21 | main() 22 | -------------------------------------------------------------------------------- /pythonTests/assert0.py: -------------------------------------------------------------------------------- 1 | def square(x): 2 | return x * x 3 | 4 | assert square(10) == 100 -------------------------------------------------------------------------------- /pythonTests/prime.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | def is_prime(n): 4 | """ Detrmines if non-negative integer is prime. """ 5 | if n < 2: 6 | return False 7 | for i in range(2, int(math.sqrt(n)) + 1): 8 | if n % i == 0: 9 | return False 10 | return True -------------------------------------------------------------------------------- /pythonTests/test0.py: -------------------------------------------------------------------------------- 1 | from prime import is_prime 2 | 3 | def test_prime(n, expected): 4 | if is_prime(n) != expected: 5 | print(f"Error on is_prime({n}), expected {expected} ") 6 | else: 7 | print(f"is_prime({n}) passed the test Successfully!") 8 | -------------------------------------------------------------------------------- /pythonTests/test0.sh: -------------------------------------------------------------------------------- 1 | python3 -c "from test0 import test_prime; test_prime(1, False)" 2 | python3 -c "from test0 import test_prime; test_prime(2, True)" 3 | python3 -c "from test0 import test_prime; test_prime(8, False)" 4 | python3 -c "from test0 import test_prime; test_prime(11, True)" 5 | python3 -c "from test0 import test_prime; test_prime(25, False)" 6 | python3 -c "from test0 import test_prime; test_prime(28, False)" 7 | -------------------------------------------------------------------------------- /pythonTests/test1.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | from prime import is_prime 3 | 4 | class Tests(unittest.TestCase): 5 | 6 | def test_1(self): 7 | """ Check that 1 is not Prime. """ 8 | self.assertFalse(is_prime(1)) 9 | 10 | 11 | def test_2(self): 12 | """ Check that 2 is Prime. """ 13 | self.assertTrue(is_prime(2)) 14 | 15 | def test_11(self): 16 | """ Check that 11 is Prime. """ 17 | self.assertTrue(is_prime(11)) 18 | 19 | def test_25(self): 20 | """ Check that 25 is not Prime. """ 21 | self.assertFalse(is_prime(25)) 22 | 23 | def test_28(self): 24 | """ Check that 28 is not Prime. """ 25 | self.assertFalse(is_prime(28)) 26 | 27 | if __name__ == "__main__": 28 | unittest.main() 29 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | asgiref==3.2.7 2 | Django==3.1.14 3 | pytz==2020.1 4 | sqlparse==0.4.4 5 | psycopg2-binary==2.8.5 6 | --------------------------------------------------------------------------------