Browse Source

Init test project.

pull/192/head
rh-ee-symartin 3 years ago
parent
commit
4680b5ed41
16 changed files with 17 additions and 438 deletions
  1. +0
    -1
      project/settings.py
  2. +0
    -3
      project/urls.py
  3. +0
    -0
      test/__init__.py
  4. +3
    -0
      test/admin.py
  5. +5
    -0
      test/apps.py
  6. +0
    -0
      test/migrations/__init__.py
  7. +3
    -0
      test/models.py
  8. +3
    -0
      test/tests.py
  9. +3
    -0
      test/views.py
  10. +0
    -11
      welcome/admin.py
  11. +0
    -22
      welcome/database.py
  12. +0
    -21
      welcome/migrations/0001_initial.py
  13. +0
    -7
      welcome/models.py
  14. +0
    -322
      welcome/templates/welcome/index.html
  15. +0
    -27
      welcome/tests.py
  16. +0
    -24
      welcome/views.py

+ 0
- 1
project/settings.py View File

@ -43,7 +43,6 @@ INSTALLED_APPS = [
'django.contrib.messages', 'django.contrib.messages',
'django.contrib.staticfiles', 'django.contrib.staticfiles',
'debug_toolbar', 'debug_toolbar',
'welcome',
] ]
MIDDLEWARE = [ MIDDLEWARE = [


+ 0
- 3
project/urls.py View File

@ -2,15 +2,12 @@ from django.conf import settings
from django.conf.urls import include, url from django.conf.urls import include, url
from django.contrib import admin from django.contrib import admin
from welcome.views import index, health
urlpatterns = [ urlpatterns = [
# Examples: # Examples:
# url(r'^$', 'project.views.home', name='home'), # url(r'^$', 'project.views.home', name='home'),
# url(r'^blog/', include('blog.urls')), # url(r'^blog/', include('blog.urls')),
url(r'^$', index), url(r'^$', index),
url(r'^health$', health),
url(r'^admin/', include(admin.site.urls)), url(r'^admin/', include(admin.site.urls)),
] ]


welcome/__init__.py → test/__init__.py View File


+ 3
- 0
test/admin.py View File

@ -0,0 +1,3 @@
from django.contrib import admin
# Register your models here.

+ 5
- 0
test/apps.py View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class TestConfig(AppConfig):
name = 'test'

welcome/migrations/__init__.py → test/migrations/__init__.py View File


+ 3
- 0
test/models.py View File

@ -0,0 +1,3 @@
from django.db import models
# Create your models here.

+ 3
- 0
test/tests.py View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

+ 3
- 0
test/views.py View File

@ -0,0 +1,3 @@
from django.shortcuts import render
# Create your views here.

+ 0
- 11
welcome/admin.py View File

@ -1,11 +0,0 @@
from django.contrib import admin
from .models import PageView
# Register your models here.
class PageViewAdmin(admin.ModelAdmin):
list_display = ['hostname', 'timestamp']
admin.site.register(PageView, PageViewAdmin)

+ 0
- 22
welcome/database.py View File

@ -1,22 +0,0 @@
from django.conf import settings
def info():
db_settings = settings.DATABASES['default']
if 'postgres' in db_settings['ENGINE']:
engine = 'PostgreSQL'
url = '{HOST}:{PORT}/{NAME}'.format(**db_settings)
elif 'mysql' in db_settings['ENGINE']:
engine = 'MySQL'
url = '{HOST}:{PORT}/{NAME}'.format(**db_settings)
elif 'sqlite' in db_settings['ENGINE']:
engine = 'SQLite'
url = '{NAME}'.format(**db_settings)
else:
engine = 'unknown'
url = ''
return {
'engine': engine,
'url': url,
'is_sqlite': engine == 'SQLite',
}

+ 0
- 21
welcome/migrations/0001_initial.py View File

@ -1,21 +0,0 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
]
operations = [
migrations.CreateModel(
name='PageView',
fields=[
('id', models.AutoField(verbose_name='ID', auto_created=True, serialize=False, primary_key=True)),
('hostname', models.CharField(max_length=32)),
('timestamp', models.DateTimeField(auto_now_add=True)),
],
),
]

+ 0
- 7
welcome/models.py View File

@ -1,7 +0,0 @@
from django.db import models
# Create your models here.
class PageView(models.Model):
hostname = models.CharField(max_length=32)
timestamp = models.DateTimeField(auto_now_add=True)

+ 0
- 322
welcome/templates/welcome/index.html
File diff suppressed because it is too large
View File


+ 0
- 27
welcome/tests.py View File

@ -1,27 +0,0 @@
import os
from .models import PageView
from .database import info
from django.test import TestCase
# These basic tests are to be used as an example for running tests in S2I
# and OpenShift when building an application image.
class PageViewModelTest(TestCase):
def test_viewpage_model(self):
pageview = PageView.objects.create(hostname='localhost')
pagetest = PageView.objects.get(hostname='localhost')
self.assertEqual(pagetest.hostname, 'localhost')
class PageViewTest(TestCase):
def test_index(self):
resp = self.client.get('/')
self.assertEqual(resp.status_code, 200)
class DbEngine(TestCase):
def setUp(self):
os.environ['ENGINE'] = 'SQLite'
def test_engine_setup(self):
settings = info()
self.assertEqual(settings['engine'], 'SQLite')
self.assertEqual(settings['is_sqlite'], True)

+ 0
- 24
welcome/views.py View File

@ -1,24 +0,0 @@
import os
from django.shortcuts import render
from django.conf import settings
from django.http import HttpResponse
from . import database
from .models import PageView
# Create your views here.
def index(request):
"""Takes an request object as a parameter and creates an pageview object then responds by rendering the index view."""
hostname = os.getenv('HOSTNAME', 'unknown')
PageView.objects.create(hostname=hostname)
return render(request, 'welcome/index.html', {
'hostname': hostname,
'database': database.info(),
'count': PageView.objects.count()
})
def health(request):
"""Takes an request as a parameter and gives the count of pageview objects as reponse"""
return HttpResponse(PageView.objects.count())

Loading…
Cancel
Save