瀏覽代碼

Add first tests

Colin Powell 3 年之前
父節點
當前提交
805fc4b175
共有 2 個文件被更改,包括 36 次插入4 次删除
  1. 11 3
      emus/settings.py
  2. 25 1
      games/tests.py

+ 11 - 3
emus/settings.py

@@ -1,5 +1,6 @@
 import dj_database_url
 import os
+import sys
 
 from django.utils.translation import gettext_lazy as _
 from dotenv import load_dotenv
@@ -23,11 +24,14 @@ BASE_DIR = Path(__file__).resolve().parent.parent
 # See https://docs.djangoproject.com/en/3.1/howto/deployment/checklist/
 
 # SECURITY WARNING: keep the secret key used in production secret!
-SECRET_KEY = "l2-2d4dmvb0un0s)=5z%c87t*tg_hu&bt6*o^ks9r7f-3(mp$$"
+SECRET_KEY = os.getenv("EMUS_SECRET_KEY", "not-a-secret-234lkjasdflj132")
+
 
 # SECURITY WARNING: don't run with debug turned on in production!
 DEBUG = os.getenv("EMUS_DEBUG", False)
 
+TESTING = len(sys.argv) > 1 and sys.argv[1] == "test"
+
 FEATURED_GAME_DURATION = os.getenv("EMUS_FEATURED_GAME_DURATION", 60 * 60 * 18)
 
 ALLOWED_HOSTS = ["*"]
@@ -98,11 +102,15 @@ TEMPLATES = [
 
 WSGI_APPLICATION = "emus.wsgi.application"
 
+
 DATABASES = {
     "default": dj_database_url.config(
         default=os.getenv("EMUS_DATABASE_URL", "sqlite:///db.sqlite3"), conn_max_age=600
-    )
+    ),
 }
+if TESTING:
+    DATABASES = {"default": dj_database_url.config(default="sqlite:///testdb.sqlite3")}
+
 
 CACHES = {
     "default": {
@@ -123,7 +131,7 @@ AUTHENTICATION_BACKENDS = [
 REST_FRAMEWORK = {
     "DEFAULT_PERMISSION_CLASSES": ("rest_framework.permissions.IsAuthenticated",),
     "DEFAULT_PAGINATION_CLASS": "rest_framework.pagination.PageNumberPagination",
-    'DEFAULT_FILTER_BACKENDS': ['django_filters.rest_framework.DjangoFilterBackend'],
+    "DEFAULT_FILTER_BACKENDS": ["django_filters.rest_framework.DjangoFilterBackend"],
     "PAGE_SIZE": 100,
 }
 

+ 25 - 1
games/tests.py

@@ -1,3 +1,27 @@
 from django.test import TestCase
+from games.models import GameSystem
 
-# Create your tests here.
+
+class GameSystemTestCase(TestCase):
+    def setUp(self):
+        GameSystem.objects.create(name="System with No Color")
+        GameSystem.objects.create(name="System with Custom Color", color="AACCAA")
+        GameSystem.objects.create(name="System with Default Color", retropie_slug="fds")
+        GameSystem.objects.create(
+            name="System with Default Color and Override",
+            color="000000",
+            retropie_slug="fds",
+        )
+
+    def test_get_color(self):
+        no_color = GameSystem.objects.get(name="System with No Color")
+        custom_color = GameSystem.objects.get(name="System with Custom Color")
+        default_color = GameSystem.objects.get(name="System with Default Color")
+        overriden_color = GameSystem.objects.get(
+            name="System with Default Color and Override"
+        )
+
+        self.assertEqual(None, no_color.get_color)
+        self.assertEqual("AACCAA", custom_color.get_color)
+        self.assertEqual("B70E30", default_color.get_color)
+        self.assertEqual("000000", overriden_color.get_color)