Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • dev
  • master
2 results

Target

Select target project
  • tddd96-grupp11/teknikattan-scoring-system
1 result
Select Git revision
  • dev
  • master
2 results
Show changes
from app.core import bcrypt, db from app.core import bcrypt, db
from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property from sqlalchemy.ext.hybrid import hybrid_method, hybrid_property
from sqlalchemy.orm import backref
STRING_SIZE = 254 STRING_SIZE = 254
...@@ -90,10 +91,13 @@ class Competition(db.Model): ...@@ -90,10 +91,13 @@ class Competition(db.Model):
year = db.Column(db.Integer, nullable=False, default=2020) year = db.Column(db.Integer, nullable=False, default=2020)
city_id = db.Column(db.Integer, db.ForeignKey("city.id"), nullable=False) city_id = db.Column(db.Integer, db.ForeignKey("city.id"), nullable=False)
background_image_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=True)
slides = db.relationship("Slide", backref="competition") slides = db.relationship("Slide", backref="competition")
teams = db.relationship("Team", backref="competition") teams = db.relationship("Team", backref="competition")
background_image = db.relationship("Media", uselist=False)
def __init__(self, name, year, city_id): def __init__(self, name, year, city_id):
self.name = name self.name = name
self.year = year self.year = year
...@@ -123,7 +127,8 @@ class Slide(db.Model): ...@@ -123,7 +127,8 @@ class Slide(db.Model):
settings = db.Column(db.Text, nullable=False, default="{}") settings = db.Column(db.Text, nullable=False, default="{}")
competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"), nullable=False) competition_id = db.Column(db.Integer, db.ForeignKey("competition.id"), nullable=False)
questions = db.relationship("Question", backref="slide") background_image_id = db.Column(db.Integer, db.ForeignKey("media.id"), nullable=True)
background_image = db.relationship("Media", uselist=False)
def __init__(self, order, competition_id): def __init__(self, order, competition_id):
self.order = order self.order = order
...@@ -138,6 +143,7 @@ class Question(db.Model): ...@@ -138,6 +143,7 @@ class Question(db.Model):
type_id = db.Column(db.Integer, db.ForeignKey("question_type.id"), nullable=False) type_id = db.Column(db.Integer, db.ForeignKey("question_type.id"), nullable=False)
slide_id = db.Column(db.Integer, db.ForeignKey("slide.id"), nullable=False) slide_id = db.Column(db.Integer, db.ForeignKey("slide.id"), nullable=False)
slide = db.relationship("Slide", backref="questions")
question_answers = db.relationship("QuestionAnswer", backref="question") question_answers = db.relationship("QuestionAnswer", backref="question")
alternatives = db.relationship("QuestionAlternative", backref="question") alternatives = db.relationship("QuestionAlternative", backref="question")
......
import os
from datetime import timedelta from datetime import timedelta
class Config: class Config:
DEBUG = False DEBUG = False
TESTING = False TESTING = False
BUNDLE_ERRORS = True
SQLALCHEMY_DATABASE_URI = "sqlite:///database.db" SQLALCHEMY_DATABASE_URI = "sqlite:///database.db"
SQLALCHEMY_TRACK_MODIFICATIONS = False
JWT_SECRET_KEY = "super-secret" JWT_SECRET_KEY = "super-secret"
JWT_BLACKLIST_ENABLED = True JWT_BLACKLIST_ENABLED = True
JWT_BLACKLIST_TOKEN_CHECKS = ["access", "refresh"] JWT_BLACKLIST_TOKEN_CHECKS = ["access", "refresh"]
BUNDLE_ERRORS = True
JWT_ACCESS_TOKEN_EXPIRES = timedelta(days=2) JWT_ACCESS_TOKEN_EXPIRES = timedelta(days=2)
JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30) JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=30)
SQLALCHEMY_TRACK_MODIFICATIONS = False UPLOADED_PHOTOS_DEST = "static/images" # os.getcwd()
SECRET_KEY = os.urandom(24)
class DevelopmentConfig(Config): class DevelopmentConfig(Config):
DEBUG = True DEBUG = True
SQLALCHEMY_DATABASE_URI = "sqlite:///database.db" SQLALCHEMY_DATABASE_URI = "sqlite:///database.db"
SQLALCHEMY_ECHO = True
class TestingConfig(Config): class TestingConfig(Config):
......
from sqlalchemy.sql.expression import true from sqlalchemy.sql.expression import true
import app.core.controller as dbc import app.database.controller as dbc
from app import create_app, db from app import create_app, db
from app.core.models import City, Competition, MediaType, QuestionType, Role from app.database.models import City, Competition, MediaType, QuestionType, Role
def _add_items(): def _add_items():
......
File suppressed by a .gitattributes entry or the file's encoding is unsupported.
import app.core.http_codes as codes import app.core.http_codes as codes
from app.core.models import Slide from app.database.models import Slide
from tests import app, client, db from tests import app, client, db
from tests.test_helpers import add_default_values, change_order_test, delete, get, post, put from tests.test_helpers import (add_default_values, change_order_test, delete,
get, post, put)
def test_misc_api(client): def test_misc_api(client):
...@@ -301,7 +302,7 @@ def test_slide_api(client): ...@@ -301,7 +302,7 @@ def test_slide_api(client):
SID = body["items"][i]["id"] SID = body["items"][i]["id"]
order = body["items"][i]["order"] order = body["items"][i]["order"]
response, _ = put(client, f"/api/competitions/{CID}/slides/{SID}/order", {"order": order}, headers=headers) response, _ = put(client, f"/api/competitions/{CID}/slides/{SID}/order", {"order": order}, headers=headers)
assert response.status_code == codes.BAD_REQUEST assert response.status_code == codes.OK
# Changes the order # Changes the order
change_order_test(client, CID, SID, order + 1, headers) change_order_test(client, CID, SID, order + 1, headers)
...@@ -330,6 +331,7 @@ def test_question_api(client): ...@@ -330,6 +331,7 @@ def test_question_api(client):
num_questions = 3 num_questions = 3
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
print(body)
assert body["count"] == num_questions assert body["count"] == num_questions
# # Get specific question # # Get specific question
...@@ -368,7 +370,7 @@ def test_question_api(client): ...@@ -368,7 +370,7 @@ def test_question_api(client):
assert item_question["name"] == name assert item_question["name"] == name
# # assert item_question["total_score"] == total_score # # assert item_question["total_score"] == total_score
assert item_question["type"]["id"] == type_id assert item_question["type"]["id"] == type_id
assert item_question["slide"]["id"] == slide_id assert item_question["slide_id"] == slide_id
# Checks number of questions # Checks number of questions
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
...@@ -413,7 +415,7 @@ def test_question_api(client): ...@@ -413,7 +415,7 @@ def test_question_api(client):
assert item_question["name"] != name assert item_question["name"] != name
# assert item_question["total_score"] != total_score # assert item_question["total_score"] != total_score
assert item_question["type"]["id"] != type_id assert item_question["type"]["id"] != type_id
assert item_question["slide"]["id"] != slide_id assert item_question["slide_id"] != slide_id
response, item_question = put( response, item_question = put(
client, client,
f"/api/competitions/{CID}/questions/{QID}", f"/api/competitions/{CID}/questions/{QID}",
...@@ -425,7 +427,7 @@ def test_question_api(client): ...@@ -425,7 +427,7 @@ def test_question_api(client):
assert item_question["name"] == name assert item_question["name"] == name
# # assert item_question["total_score"] == total_score # # assert item_question["total_score"] == total_score
assert item_question["type"]["id"] == type_id assert item_question["type"]["id"] == type_id
assert item_question["slide"]["id"] == slide_id assert item_question["slide_id"] == slide_id
# Checks number of questions # Checks number of questions
response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers) response, body = get(client, f"/api/competitions/{CID}/questions", headers=headers)
assert response.status_code == codes.OK assert response.status_code == codes.OK
......
import app.core.controller as dbc import app.database.controller as dbc
from app.core.models import City, Competition, Media, MediaType, Question, QuestionType, Role, Slide, Team, User from app.database.models import City, Competition, Media, MediaType, Question, QuestionType, Role, Slide, Team, User
from tests import app, client, db from tests import app, client, db
from tests.test_helpers import add_default_values, assert_exists, assert_insert_fail from tests.test_helpers import add_default_values, assert_exists, assert_insert_fail
...@@ -40,6 +40,7 @@ def test_media(client): ...@@ -40,6 +40,7 @@ def test_media(client):
assert item_media.upload_by.email == "test@test.se" assert item_media.upload_by.email == "test@test.se"
"""
def test_question(client): def test_question(client):
add_default_values() add_default_values()
item_user = User.query.filter_by(email="test@test.se").first() item_user = User.query.filter_by(email="test@test.se").first()
...@@ -168,3 +169,4 @@ def test_slide(client): ...@@ -168,3 +169,4 @@ def test_slide(client):
aux = dbc.get.search_slide(slide_order=1, competition_id=item_comp.id) aux = dbc.get.search_slide(slide_order=1, competition_id=item_comp.id)
item_slide = aux[0][0] item_slide = aux[0][0]
dbc.delete.slide(item_slide) dbc.delete.slide(item_slide)
"""
import json import json
import app.core.controller as dbc
import app.core.http_codes as codes import app.core.http_codes as codes
import app.database.controller as dbc
from app.core import db from app.core import db
from app.core.models import City, Role from app.database.models import City, Role
def add_default_values(): def add_default_values():
......