import from kontor-flask
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
from flask_testing import TestCase
|
||||
from kontor import create_app
|
||||
from kontor.models import User
|
||||
|
||||
|
||||
class TestBase(TestCase):
|
||||
|
||||
def create_app(self):
|
||||
|
||||
# pass in test configuration
|
||||
config_name = 'testing'
|
||||
app = create_app(config_name)
|
||||
return app
|
||||
|
||||
def setUp(self):
|
||||
"""
|
||||
Will be called before every test
|
||||
"""
|
||||
# create test admin user
|
||||
admin = User()
|
||||
admin.username="admin"
|
||||
admin.password="admin2016"
|
||||
admin.is_admin=True
|
||||
admin.save()
|
||||
|
||||
# create test non-admin user
|
||||
employee = User()
|
||||
employee.username="test_user"
|
||||
employee.password="test2016"
|
||||
employee.save()
|
||||
|
||||
def tearDown(self):
|
||||
"""
|
||||
Will be called after every test
|
||||
"""
|
||||
users = User.objects.all()
|
||||
for user in users:
|
||||
user.delete()
|
||||
@@ -0,0 +1,51 @@
|
||||
"""
|
||||
This module cantains tests for the comic data model
|
||||
"""
|
||||
import unittest
|
||||
from . import TestBase
|
||||
from kontor.comics.models import Artist, Comic, Publisher
|
||||
|
||||
|
||||
class TestComicsModel(TestBase):
|
||||
"""This TestCase contains tests for comic data model."""
|
||||
|
||||
def setUp(self):
|
||||
publisher = Publisher()
|
||||
publisher.name = "Publisher1"
|
||||
publisher.save()
|
||||
artist = Artist()
|
||||
artist.name = "Artist1"
|
||||
artist.save()
|
||||
comic = Comic()
|
||||
comic.title = "Title1"
|
||||
comic.save()
|
||||
|
||||
def tearDown(self):
|
||||
for comic in Comic.objects.all():
|
||||
comic.delete()
|
||||
for artist in Artist.objects.all():
|
||||
artist.delete()
|
||||
for publisher in Publisher.objects.all():
|
||||
publisher.delete()
|
||||
|
||||
def test_comic_model(self):
|
||||
comic_list = Comic.objects.all()
|
||||
self.assertEqual(comic_list.count(), 1)
|
||||
|
||||
def test_publisher_model(self):
|
||||
self.assertEqual(Publisher.objects.all().count(), 1)
|
||||
|
||||
def test_artist_model(self):
|
||||
self.assertEqual(Artist.objects.all().count(), 1)
|
||||
|
||||
def test_assign_publisher(self):
|
||||
comic = Comic.objects.first()
|
||||
publisher = Publisher.objects.first()
|
||||
comic.publisher = publisher
|
||||
comic.save()
|
||||
self.assertEqual(publisher.name, comic.publisher.name)
|
||||
self.assertEqual(publisher.comics.count(), 1)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,44 @@
|
||||
"""This module contains tests for Comic related urls."""
|
||||
import unittest
|
||||
from flask import url_for
|
||||
from . import TestBase
|
||||
|
||||
|
||||
class TestComicsViews(TestBase):
|
||||
|
||||
def test_comics_index(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('comic.list_comics')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_comics_artist(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('comic.list_artists')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_comics_publisher(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('comic.list_publishers')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,4 @@
|
||||
# instance/config.py
|
||||
|
||||
SECRET_KEY = 'p9Bv<3Eid9%$i01'
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
"""
|
||||
This module cantains tests for the general Kontor data model.
|
||||
"""
|
||||
from . import TestBase
|
||||
from kontor.models import User
|
||||
|
||||
|
||||
class TestKontorModel(TestBase):
|
||||
"""This TestCase contains tests for users."""
|
||||
def test_user_model(self):
|
||||
"""
|
||||
Test number of records in User collection
|
||||
"""
|
||||
self.assertEqual(User.objects.all().count(), 2)
|
||||
@@ -0,0 +1,58 @@
|
||||
"""This module contains tests for Comic related urls."""
|
||||
import unittest
|
||||
from flask import url_for
|
||||
from . import TestBase
|
||||
|
||||
|
||||
class TestKontorViews(TestBase):
|
||||
|
||||
def test_homepage_view(self):
|
||||
"""
|
||||
Test that homepage is accessible without login
|
||||
"""
|
||||
response = self.client.get(url_for('home.homepage'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_login_view(self):
|
||||
"""
|
||||
Test that login page is accessible without login
|
||||
"""
|
||||
response = self.client.get(url_for('auth.login'))
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
def test_logout_view(self):
|
||||
"""
|
||||
Test that logout link is inaccessible without login
|
||||
and redirects to login page then to logout
|
||||
"""
|
||||
target_url = url_for('auth.logout')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_dashboard_view(self):
|
||||
"""
|
||||
Test that dashboard is inaccessible without login
|
||||
and redirects to login page then to dashboard
|
||||
"""
|
||||
target_url = url_for('home.dashboard')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_admin_dashboard_view(self):
|
||||
"""
|
||||
Test that dashboard is inaccessible without login
|
||||
and redirects to login page then to dashboard
|
||||
"""
|
||||
target_url = url_for('home.admin_dashboard')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,49 @@
|
||||
"""
|
||||
This module cantains tests for the comic data model
|
||||
"""
|
||||
import unittest
|
||||
from . import TestBase
|
||||
from kontor.library.models import Author, Publisher, Book
|
||||
|
||||
|
||||
class TestComicsModel(TestBase):
|
||||
"""This TestCase contains tests for comic data model."""
|
||||
|
||||
def setUp(self):
|
||||
publisher = Publisher()
|
||||
publisher.name = "Publisher1"
|
||||
publisher.save()
|
||||
author = Author()
|
||||
author.name = "Autor1"
|
||||
author.save()
|
||||
book = Book()
|
||||
book.title = "Title1"
|
||||
book.save()
|
||||
|
||||
def tearDown(self):
|
||||
for book in Book.objects.all():
|
||||
book.delete()
|
||||
for author in Author.objects.all():
|
||||
author.delete()
|
||||
for publisher in Publisher.objects.all():
|
||||
publisher.delete()
|
||||
|
||||
def test_comic_model(self):
|
||||
book_list = Book.objects.all()
|
||||
self.assertEqual(book_list.count(), 1)
|
||||
|
||||
def test_publisher_model(self):
|
||||
self.assertEqual(Publisher.objects.all().count(), 1)
|
||||
|
||||
def test_artist_model(self):
|
||||
self.assertEqual(Author.objects.all().count(), 1)
|
||||
|
||||
def test_assign_publisher(self):
|
||||
book = Book.objects.first()
|
||||
publisher = Publisher.objects.first()
|
||||
book.publisher = publisher
|
||||
book.save()
|
||||
self.assertEqual(publisher.name, book.publisher.name)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,44 @@
|
||||
"""This module contains tests for Comic related urls."""
|
||||
import unittest
|
||||
from flask import url_for
|
||||
from . import TestBase
|
||||
|
||||
|
||||
class TestLibraryViews(TestBase):
|
||||
|
||||
def test_library_index(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('library.list_books')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_library_author(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('library.list_authors')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_library_publisher(self):
|
||||
"""
|
||||
Test that comics page is inaccessible without login
|
||||
and redirects to login page then to comics page
|
||||
"""
|
||||
target_url = url_for('library.list_publishers')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,53 @@
|
||||
"""
|
||||
This module cantains tests for the TYSC data model
|
||||
"""
|
||||
import unittest
|
||||
from . import TestBase
|
||||
from kontor.tysc import initialize_model
|
||||
from kontor.tysc.models import Sport, Position, Team, Player
|
||||
from kontor.tysc.models import Manufacturer, CardSet, ParallelSet, InsertSet, Card
|
||||
|
||||
|
||||
class TestTYSCModel(TestBase):
|
||||
"""
|
||||
This TestCase contains tests for TYSC data model.
|
||||
"""
|
||||
_initialize_db_ = True
|
||||
|
||||
def setUp(self):
|
||||
if self._initialize_db_:
|
||||
initialize_model()
|
||||
self._initialize_db_ = False
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
||||
def test_sport_model(self):
|
||||
self.assertEqual(Sport.objects.all().count(), 4)
|
||||
|
||||
def test_position_model(self):
|
||||
self.assertEqual(Position.objects.all().count(), 25)
|
||||
|
||||
def test_team_model(self):
|
||||
self.assertEqual(Team.objects.all().count(), 122)
|
||||
|
||||
def test_manufacturer_model(self):
|
||||
self.assertEqual(Manufacturer.objects.all().count(), 8)
|
||||
|
||||
def test_cardset_model(self):
|
||||
self.assertEqual(CardSet.objects.all().count(), 11)
|
||||
|
||||
def test_parallelset_model(self):
|
||||
self.assertEqual(ParallelSet.objects.all().count(), 3)
|
||||
|
||||
def test_insertset_model(self):
|
||||
self.assertEqual(InsertSet.objects.all().count(), 1)
|
||||
|
||||
def test_playerset_model(self):
|
||||
self.assertEqual(Player.objects.all().count(), 36)
|
||||
|
||||
def test_card_model(self):
|
||||
self.assertEqual(Card.objects.all().count(), 36)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
@@ -0,0 +1,110 @@
|
||||
"""This module contains tests for TradeYourSportsCards related urls."""
|
||||
import unittest
|
||||
from flask import url_for
|
||||
from . import TestBase
|
||||
|
||||
|
||||
class TestTYSCViews(TestBase):
|
||||
|
||||
def test_tysc_index(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_cards')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_sport(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_sports')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_team(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_teams')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_player(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_players')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_manufacturer(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_manufacturers')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_card_set(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_card_sets')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_parallel_set(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_parallel_sets')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_insert_set(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_insert_sets')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
def test_tysc_card(self):
|
||||
"""
|
||||
Test that TYSC page is inaccessible without login
|
||||
and redirects to login page then to TYSC page
|
||||
"""
|
||||
target_url = url_for('tysc.list_cards')
|
||||
redirect_url = url_for('auth.login', next=target_url)
|
||||
response = self.client.get(target_url)
|
||||
self.assertEqual(response.status_code, 302)
|
||||
self.assertRedirects(response, redirect_url)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user