Skip to content

Commit

Permalink
added import-name test
Browse files Browse the repository at this point in the history
  • Loading branch information
Mudiwa Matanda authored and Mudiwa Matanda committed Feb 14, 2024
1 parent 03ccfc9 commit f9ada25
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 0 deletions.
41 changes: 41 additions & 0 deletions home/tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import json
import queue
from pathlib import Path
from bs4 import BeautifulSoup


import pytest
from wagtail import blocks
from django.test import Client
from pytest_django.asserts import assertTemplateUsed


from home.content_import_export import import_content
from home.models import (
Expand All @@ -28,6 +33,14 @@
from .utils import create_page


#use this to access the admin interface
@pytest.fixture()
def admin_client(client, django_user_model):
creds = {"username": "test", "password": "test"}
django_user_model.objects.create_superuser(**creds)
client.login(**creds)
return client

@pytest.fixture()
def uclient(client, django_user_model):
creds = {"username": "test", "password": "test"}
Expand Down Expand Up @@ -88,6 +101,34 @@ def create_test_data(self):
tags=["self_help"],
)


def test_import_button_text(self, admin_client):

page = ContentPage.objects.first()
page_id = page.id
url = f"/admin/pages/{page_id}/edit/"
response = admin_client.get(url)

assert response.status_code == 200
content_str = response.content.decode("utf-8")

# Use BeautifulSoup to parse the HTML content
soup = BeautifulSoup(content_str, 'html.parser')

#confirm the correct template is rendered
assertTemplateUsed(response, 'wagtail_content_import/picker_buttons_base.html')

# Find the div with the specified class
div_element = soup.find('div', class_='content-import button button-longrunning dropdown-toggle')

# Check if the text is present in the div's contents
assert div_element and "Import web from doc" in div_element.get_text(strip=True), "Text not found on the page."






def test_login_required(self, client):
"""
Users that aren't logged in shouldn't be allowed to access the API
Expand Down
6 changes: 6 additions & 0 deletions home/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,12 @@


class ContentPageTests(TestCase):

def test_sample(self):
page = create_page()
print(page)
self.assertEqual(page.page_rating, "(no ratings yet)")

def test_page_and_revision_rating(self):
page = create_page()

Expand Down

0 comments on commit f9ada25

Please sign in to comment.