Skip to content

Commit fad6178

Browse files
committed
convert demo test to front end tests
1 parent c084a40 commit fad6178

File tree

6 files changed

+35
-44
lines changed

6 files changed

+35
-44
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ $ python manage.py runserver
6666
```
6767

6868
## Testing
69+
Install [PhantomJS](http://phantomjs.org/)
6970
```bash
7071
$ python demo/manage.py behave
7172
```

circle.yml

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
machine:
2-
timezone:
3-
America/Los_Angeles
4-
python:
5-
version:
6-
2.7.11
2+
pre:
3+
- sudo curl --output /usr/local/bin/phantomjs https://s3.amazonaws.com/circle-downloads/phantomjs-2.1.1
74

85
dependencies:
96
pre:

demo/requirements.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ behave-django==0.3.0
66
enum34==1.1.6
77
parse==1.6.6
88
parse-type==0.3.4
9+
selenium==3.0.1
910
setuptools==25.1.2
11+
splinter==0.7.5
1012
coverage==4.2
1113
codecov==2.0.5
1214
requests==2.10.0

features/environment.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
from splinter.browser import Browser
2+
3+
4+
def before_all(context):
5+
context.browser = Browser('phantomjs')
6+
7+
def after_all(context):
8+
context.browser.quit()
9+
context.browser = None

features/steps/contact_view.py

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,26 @@
66

77
@given('that a user fills in the contact form with valid input')
88
def step_impl(context):
9-
context.values = {
10-
"sender_email": "test@example.bike",
11-
"subject": "just saying hello",
12-
"message": "Hi bob, havn't talk in a while. All the Best, --Joe",
13-
}
9+
context.browser.visit(context.get_url('contact'))
10+
context.browser.fill('sender_email', 'bob@example.com')
11+
context.browser.fill('subject', 'just saying hello')
12+
context.browser.fill('message', 'Hi bob, havn\'t talk in a while. All the Best, --Joe')
1413

1514
@when('the user submits the contact form')
1615
def step_impl(context):
17-
context.response = context.test.client.post(
18-
context.get_url('/contact/'),
19-
context.values,
20-
follow=True,
21-
)
16+
context.browser.find_by_css('input[type=submit]').first.click()
2217

2318
@then('the contact form is successfully submitted')
2419
def step_impl(context):
25-
context.test.assertRedirects(context.response, context.get_url('contact_sent'))
20+
assert context.browser.url == context.get_url('contact_sent')
2621

2722
@given('that a user fills in the contact form with an invalid email')
2823
def step_impl(context):
29-
context.values = {
30-
"sender_email": "",
31-
"subject": "just saying hello",
32-
"message": "Hi bob, havn't talk in a while. All the Best, --Joe",
33-
}
24+
context.browser.visit(context.get_url('contact'))
25+
context.browser.fill('subject', 'just saying hello')
26+
context.browser.fill('message', 'Hi bob, havn\'t talk in a while. All the Best, --Joe')
3427

3528
@then('the contact form is not successfully submitted')
3629
def step_impl(context):
37-
for context in context.response.context:
38-
assert context['forms']['user_form'].errors
30+
assert context.browser.url == context.get_url('contact')
31+
assert context.browser.is_element_present_by_css('.errorlist')

features/steps/record_form_view.py

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,29 @@
88

99
@given('that a user fills in the form with valid input')
1010
def step_impl(context):
11-
image = open('test.png', 'r')
12-
13-
context.values = {
14-
"title": "Test title",
15-
"description": "Test description",
16-
"tag": Photo.UNKNOWN,
17-
"image": image,
18-
}
11+
context.browser.visit(context.get_url('records_new'))
12+
context.browser.fill('title', 'Test title')
13+
context.browser.fill('description', 'Test description')
14+
context.browser.attach_file('image', 'test.png')
15+
context.browser.choose('tag', Photo.UNKNOWN)
1916

2017
@when('the user submits the form')
2118
def step_impl(context):
22-
context.response = context.test.client.post(
23-
context.get_url('/records/new/'),
24-
context.values,
25-
follow=True,
26-
)
19+
context.browser.find_by_css('input[type=submit]').first.click()
2720

2821
@then('a Record and Photo instance are created')
2922
def step_impl(context):
30-
assert context.response.status_code == 200
3123
assert Photo.objects.count() == 1
3224
assert Record.objects.count() == 1
3325

3426
@given('that a user fills in the form without uploading an image')
3527
def step_impl(context):
36-
context.values = {
37-
"title": "Test title",
38-
"description": "Test description",
39-
"tag": Photo.UNKNOWN,
40-
"image": None,
41-
}
28+
context.browser.visit(context.get_url('records_new'))
29+
context.browser.fill('title', 'Test title')
30+
context.browser.fill('description', 'Test description')
31+
context.browser.choose('tag', Photo.UNKNOWN)
4232

4333
@then('a Record and Photo instance are not created')
4434
def step_impl(context):
45-
assert context.response.status_code == 200
4635
assert Photo.objects.count() == 0
4736
assert Record.objects.count() == 0

0 commit comments

Comments
 (0)