-
Notifications
You must be signed in to change notification settings - Fork 19
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP Add selenium test for django admin page #50
Open
meshy
wants to merge
6
commits into
master
Choose a base branch
from
behave
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fb95c12
Add Django 2.1 to TravisCI build
meshy 063e78d
Update flake8 to fully support Python 3.7
meshy c79db31
Add selenium test for admin list page
meshy 7501bbc
Run the selenium tests in headless mode
meshy 68ed554
Add chrome addon, and install chromedriver
meshy f0d704d
Add second behaviour test
meshy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.contrib import admin | ||
|
||
from orderable.admin import OrderableAdmin | ||
from .models import Item | ||
|
||
|
||
admin.site.register(Item, OrderableAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# Generated by Django 2.1.2 on 2018-10-26 21:17 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
initial = True | ||
|
||
dependencies = [ | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Item', | ||
fields=[ | ||
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), | ||
('sort_order', models.IntegerField(blank=True, db_index=True)), | ||
], | ||
options={ | ||
'ordering': ['sort_order'], | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from orderable.models import Orderable | ||
|
||
|
||
class Item(Orderable): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import os | ||
|
||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
SECRET_KEY = 'r+n-oywnjf7&b*#(!@zx-wa4j=4_yy7a%j-lep&q8nx6^=lwf5' | ||
ROOT_URLCONF = 'bdd.urls' | ||
STATIC_URL = '/static/' | ||
DATABASES = {'default': { | ||
'ENGINE': 'django.db.backends.postgresql_psycopg2', | ||
'NAME': 'orderable', | ||
'HOST': 'localhost' | ||
}} | ||
|
||
INSTALLED_APPS = [ | ||
# Project. | ||
'bdd', | ||
|
||
# 3rd party. | ||
'behave_django', | ||
'orderable', | ||
|
||
# Django. | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
] | ||
|
||
MIDDLEWARE = [ | ||
'django.middleware.security.SecurityMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
] | ||
|
||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
from django.conf.urls import url | ||
from django.contrib import admin | ||
|
||
|
||
urlpatterns = [ | ||
url('^admin/', admin.site.urls), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == '__main__': | ||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'bdd.settings') | ||
try: | ||
from django.core.management import execute_from_command_line | ||
except ImportError: | ||
raise ImportError( | ||
"Couldn't import Django. Are you sure it's installed and " | ||
"available on your PYTHONPATH environment variable? Did you " | ||
"forget to activate a virtual environment?" | ||
) | ||
execute_from_command_line(sys.argv) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from selenium import webdriver | ||
|
||
|
||
chrome_options = webdriver.chrome.options.Options() | ||
chrome_options.add_argument("--headless") | ||
chrome_options.add_argument("--window-size=1024x768") | ||
|
||
|
||
class Browser(object): | ||
driver = webdriver.Chrome(chrome_options=chrome_options) | ||
driver.implicitly_wait(5) | ||
|
||
def close(context): | ||
context.driver.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from .browser import Browser | ||
from .pages import ItemListPage | ||
|
||
|
||
def before_all(context): | ||
context.browser = Browser() | ||
context.item_list_page = ItemListPage() | ||
|
||
|
||
def after_all(context): | ||
context.browser.close() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
Feature: Ordering on the list page | ||
|
||
Scenario: Move an item to the end of the list | ||
Given the following items: | ||
| pk | | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
And we are on the item list page | ||
When item 1 is moved to position 3 | ||
Then the items should be ordered thus: | ||
| pk | | ||
| 2 | | ||
| 3 | | ||
| 1 | | ||
|
||
Scenario: Move an item to the top of the list | ||
Given the following items: | ||
| pk | | ||
| 1 | | ||
| 2 | | ||
| 3 | | ||
And we are on the item list page | ||
When item 3 is moved to position 1 | ||
Then the items should be ordered thus: | ||
| pk | | ||
| 3 | | ||
| 1 | | ||
| 2 | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from browser import Browser | ||
from selenium.webdriver.common.action_chains import ActionChains | ||
|
||
|
||
class ItemListPage(Browser): | ||
def move_item(self, source, destination): | ||
|
||
template = '#neworder-{} .ui-sortable-handle' | ||
find = self.driver.find_element_by_css_selector | ||
offset = 2 if destination > source else -2 | ||
( | ||
ActionChains(self.driver) | ||
.click_and_hold(find(template.format(source))) | ||
.move_to_element(find(template.format(destination))) | ||
.move_by_offset(0, offset) | ||
.release() | ||
.perform() | ||
) | ||
|
||
def open(self, context): | ||
url = context.get_url('admin:bdd_item_changelist') | ||
self.driver.get(url) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import time | ||
|
||
from behave import given, then, when | ||
from django.contrib.auth.models import User | ||
from seleniumlogin import force_login | ||
|
||
from bdd.models import Item | ||
|
||
|
||
@given(u'the following items') | ||
def set_up_items(context): | ||
Item.objects.bulk_create([ | ||
Item(pk=row['pk'], sort_order=i) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This needs to be |
||
for i, row | ||
in enumerate(context.table) | ||
]) | ||
|
||
|
||
@given(u'we are on the item list page') | ||
def go_to_admin_page(context): | ||
user = User.objects.create_superuser( | ||
email='[email protected]', | ||
password='password', | ||
username='myuser', | ||
) | ||
force_login(user, context.browser.driver, context.test.live_server_url) | ||
context.item_list_page.open(context) | ||
|
||
|
||
@when(u'item {initial_position:d} is moved to position {new_position:d}') | ||
def move_items(context, initial_position, new_position): | ||
context.item_list_page.move_item(initial_position, new_position) | ||
time.sleep(.1) | ||
|
||
|
||
@then(u'the items should be ordered thus') | ||
def check_item_order(context): | ||
items = list(Item.objects.values_list('pk', flat=True)) | ||
expected = [] | ||
for row in context.table: | ||
expected.append(int(row['pk'])) | ||
|
||
assert items == expected, (items, expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import sys | ||
from argparse import ArgumentParser | ||
import sys | ||
|
||
import django | ||
from django.conf import settings | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
behave==1.2.6 | ||
behave_django==1.1.0 | ||
coverage==3.7.1 | ||
flake8==2.2.5 | ||
flake8-import-order==0.5.3 | ||
django-selenium-login==1.0.2 | ||
flake8==3.6.0 | ||
flake8-import-order==0.18 | ||
hypothesis==2.0.0 | ||
psycopg2==2.7.4 | ||
selenium==3.14.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests fail because this isn't an acceptable relative import.