Skip to content

Commit f87fa9f

Browse files
committed
added runtests
1 parent 77441e5 commit f87fa9f

File tree

7 files changed

+119
-1
lines changed

7 files changed

+119
-1
lines changed

martor/tests/__init__.py

Whitespace-only changes.

martor/tests/models.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
2+
from django.db import models
3+
4+
from martor.models import MartorField
5+
6+
7+
class Post(models.Model):
8+
description = MartorField()
9+
wiki = MartorField()
10+
11+
class Meta:
12+
app_label = 'Post'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!DOCTYPE html>
2+
<html lang="en-us">
3+
<head>
4+
<title>Martor</title>
5+
</head>
6+
<body>
7+
<div class="ui container main-container">
8+
<div class="ui segment">
9+
<form class="ui form" method="post">{% csrf_token %}
10+
<div class="field">
11+
{{ form.description }}
12+
</div>
13+
<div class="field">
14+
{{ form.wiki }}
15+
</div>
16+
<div class="field">
17+
<div class="ui clearing segment">
18+
<button class="ui right floated positive button">
19+
<i class="save icon"></i> Save Post
20+
</button>
21+
</div>
22+
</div>
23+
</div>
24+
</div>
25+
</div>
26+
</body>
27+
</html>

martor/tests.py renamed to martor/tests/tests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
class SimpleTest(TestCase):
66

77
def test_me(self):
8-
response = self.client.get('/', follow=True)
8+
response = self.client.get('/test-form-view/')
99
self.assertEqual(response.status_code, 200)

martor/tests/urls.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
import django
3+
4+
from .views import TestFormView
5+
6+
7+
if django.VERSION >= (2, 0):
8+
from django.urls import path, include
9+
urlpatterns = [
10+
path('test-form-view/', TestFormView.as_view()),
11+
path('martor/', include('martor.urls')),
12+
]
13+
else:
14+
from django.conf.urls import url, include
15+
urlpatterns = [
16+
url(r'^test-form-view/$', TestFormView.as_view()),
17+
url(r'^martor/', include('martor.urls')),
18+
]

martor/tests/views.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
from django.views.generic.edit import CreateView
3+
4+
from .models import Post
5+
6+
7+
class TestFormView(CreateView):
8+
template_name = 'test_form_view.html'
9+
model = Post
10+
fields = ['description', 'wiki']

runtests.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import django
2+
import sys
3+
import os
4+
from django.conf import settings
5+
6+
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
7+
8+
settings.configure(
9+
DEBUG=True,
10+
DATABASES={
11+
'default': {
12+
'NAME': ':memory:',
13+
'ENGINE': 'django.db.backends.sqlite3',
14+
}
15+
},
16+
TEMPLATES=[{
17+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
18+
'DIRS': [
19+
os.path.join(BASE_DIR, 'django-markdown-editor/martor/templates'),
20+
os.path.join(BASE_DIR, 'django-markdown-editor/martor/tests/templates'),
21+
],
22+
'APP_DIRS': True,
23+
'OPTIONS': {
24+
'context_processors': [
25+
'django.template.context_processors.debug',
26+
'django.template.context_processors.request',
27+
'django.contrib.auth.context_processors.auth',
28+
'django.contrib.messages.context_processors.messages',
29+
],
30+
},
31+
}],
32+
ROOT_URLCONF='martor.tests.urls',
33+
INSTALLED_APPS=['django.contrib.auth',
34+
'django.contrib.contenttypes',
35+
'django.contrib.sessions',
36+
'django.contrib.admin',
37+
'martor'])
38+
39+
try:
40+
# Django <= 1.8
41+
from django.test.simple import DjangoTestSuiteRunner
42+
test_runner = DjangoTestSuiteRunner(verbosity=1)
43+
except ImportError:
44+
# Django >= 1.8
45+
django.setup()
46+
from django.test.runner import DiscoverRunner
47+
test_runner = DiscoverRunner(verbosity=1)
48+
49+
failures = test_runner.run_tests(['martor'])
50+
if failures:
51+
sys.exit(failures)

0 commit comments

Comments
 (0)