1
Fork 0

Cleanup base test case

This commit is contained in:
Jake Howard 2016-12-26 21:45:17 +00:00
parent aadbd8f14b
commit f0142fe42c

View file

@ -3,7 +3,6 @@ from .context import SETTINGS_KEYS
from django.conf import settings from django.conf import settings
from project.home.models import HomePage from project.home.models import HomePage
from wagtail.wagtailcore.models import Site, Page from wagtail.wagtailcore.models import Site, Page
from django.contrib.auth.models import User
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from rest_framework.test import APIClient from rest_framework.test import APIClient
from django.utils.text import slugify from django.utils.text import slugify
@ -11,43 +10,34 @@ from bs4 import BeautifulSoup
class BaseTestCase(WagtailPageTests): class BaseTestCase(WagtailPageTests):
USERNAME = 'test_user' client = APIClient()
EMAIL = 'test@example.com'
PASSWORD = 'test'
def setUp(self): def setUp(self):
super().setUp() super().setUp()
self.client = APIClient()
self.root = self.create_initial_homepage() self.root = self.create_initial_homepage()
self.user = User.objects.create_superuser(
self.USERNAME,
self.EMAIL,
self.PASSWORD
)
self.client.login(
username=self.USERNAME,
password=self.PASSWORD
)
def create_model(self, model, data={}): def create_model(self, model, data={}):
add_url = reverse('wagtailadmin_pages:add', args=[ add_url = reverse('wagtailadmin_pages:add', args=[
model._meta.app_label, model._meta.model_name, self.root.pk model._meta.app_label, model._meta.model_name, self.root.pk
]) ])
data['action-publish'] = 'action-publish' data.update({
data['body-count'] = 1 'action-publish': 'action-publish',
data['body-0-deleted'] = '' 'body-count': 1,
data['body-0-order'] = 0 'body-0-deleted': '',
data['body-0-type'] = 'raw_html' 'body-0-order': 0,
data['body-0-value'] = data['body'] 'body-0-type': 'raw_html',
data['slug'] = slugify(data['title']) 'body-0-value': data['body'],
'slug': slugify(data['title'])
})
return self.client.post(add_url, data) return self.client.post(add_url, data)
def create_test_user(self):
self.user = super().create_test_user()
return self.user
def parse_content(self, content): def parse_content(self, content):
parsed_content = BeautifulSoup(content, 'html.parser') return BeautifulSoup(content, 'html.parser')
for tag in parsed_content(["noscript"]): # Remove noscript tags
tag.extract()
return parsed_content
def create_initial_homepage(self): def create_initial_homepage(self):
""" """