Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
updated navigation through tasks to require instructions first
  • Loading branch information
dtraviglia committed Mar 23, 2015
1 parent d26a2cc commit 37122365bc2a601383ce97a3577ed38d099a2d4b
Show file tree
Hide file tree
Showing 10 changed files with 200 additions and 113 deletions.
@@ -1,17 +1,50 @@
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from django.test import LiveServerTestCase
from django.contrib.auth.models import User
from django.conf import settings
from django.conf.urls.static import static

from op_tasks.models import Dataset, Product, OpTask, UserProfile, TaskListItem

import os
os.environ['DJANGO_LIVE_TEST_SERVER_ADDRESS'] = 'localhost:9000'

class NewVisitorTest(LiveServerTestCase):

def setUp(self):
self.browser = webdriver.Chrome()
# TODO find a way to call populate_db
test_tasks = [
{'name': 'Test-OT1',
'ot_survey_url': 'https://www.surveymonkey.com/s/LR37HZG',
'ot_exit_url': 'https://www.surveymonkey.com/s/VD8NQZT'},
{'name': 'Test-OT2',
'ot_survey_url': 'https://www.surveymonkey.com/s/LR37HZG',
'ot_exit_url': 'https://www.surveymonkey.com/s/VD8NQZT'}]

dataset = Dataset(name='Test-DS', version='v0.1')
dataset.save()

Product(dataset=dataset,
url='/static/testing/index.html',
instructions=settings.STATIC_URL + 'testing/instructions.html',
team='test-team',
name='test-product',
version='v0.1').save()

for task in test_tasks:
newtask = OpTask(dataset=dataset,
name=task['name'],
survey_url=task['ot_survey_url'],
exit_url=task['ot_exit_url']).save()

self.browser = webdriver.Firefox()
self.browser.implicitly_wait(3)

def tearDown(self):
self.browser.close()

def test_can_register_and_navigate_to_task_list(self):
def test_can_register_a_user_with_tasks(self):
# browse to online portal
self.browser.get(self.live_server_url)

@@ -22,10 +55,28 @@ def test_can_register_and_navigate_to_task_list(self):
self.browser.find_element_by_id("intro-complete").submit()

# register a new user
inputemail = self.browser.find_element_by_name("email")
inputemail = self.browser.find_element_by_name("username")
inputemail.send_keys("new@test.com")

inputpassword = self.browser.find_element_by_name("password")
inputemail.send_keys("dftnew@test.com")
inputpassword.send_keys("dft")
self.browser.find_element_by_name("submit").submit()
self.browser.implicitly_wait(5)
inputpassword.send_keys("new")

inputpassword2 = self.browser.find_element_by_name("password2")
inputpassword2.send_keys("new")

inputpassword2.submit()

saved_users = User.objects.all()
self.assertEqual(saved_users.count(), 1)
self.assertEqual(saved_users[0].username, 'new@test.com')

saved_task_list_items = TaskListItem.objects.all()
self.assertEqual(saved_task_list_items.count(), 2)
first_task = saved_task_list_items[0]
second_task = saved_task_list_items[1]
self.assertEqual(first_task.userprofile, second_task.userprofile)
self.assertEqual(first_task.userprofile.user.username, 'new@test.com')
self.assertEqual(second_task.userprofile.user.username, 'new@test.com')

# self.browser.implicitly_wait(25)

@@ -39,17 +39,12 @@ def _create_user(self):
matched_tasks = dataset.optask_set.filter(is_active=True).order_by('?')

for index, task in enumerate(matched_tasks[0:matched_tasks.count()]):
if index==0:
active=True
else:
active=False
exit_active=False
TaskListItem(userprofile=userprofile,
product=product,
op_task=task,
index=index,
task_active=active,
exit_active=exit_active).save()
task_active=False,
exit_active=False).save()

def _create_data(self):
dataset = Dataset(name='Test-DS', version='v0.1')
@@ -53,6 +53,11 @@ class UserProfile(models.Model):
def __unicode__(self):
return self.user.username

def read_instructions(self):
return self.exp_inst_complete and self.portal_inst_complete and self.task_inst_complete

# read_instructions = property(_read_instructions)

# The TaskListItem model is used to manage user navigation through the experiment
class TaskListItem(models.Model):
# knows which user it is assigned to
@@ -8,26 +8,47 @@ <h1>Instructions Home</h1>
<div class="instructions" >
<a href="/op_tasks/experiment_instructions">
<h3>
<span class="glyphicon glyphicon-book"></span>
Click here to review instructional materials for the experiment
{% if not user.userprofile.exp_inst_complete %}
<div class="task-current">
<span class="glyphicon glyphicon-unchecked"></span>
Experiment Information and Instructions
</div>
{% elif user.userprofile.exp_inst_complete %}
<span class="glyphicon glyphicon-check"></span>
Experiment Information and Instructions
{% endif %}
</h3>
</a>
</div>

<div class="instructions" >
<a href="/op_tasks/portal_instructions">
<h3>
<span class="glyphicon glyphicon-book"></span>
Click here to review instructional materials for this portal
{% if not user.userprofile.portal_inst_complete %}
<div class="task-current">
<span class="glyphicon glyphicon-unchecked"></span>
Portal Guide
</div>
{% elif user.userprofile.portal_inst_complete %}
<span class="glyphicon glyphicon-check"></span>
Portal Guide
{% endif %}
</h3>
</a>
</div>

<div class="instructions" >
<a href="/op_tasks/product_instructions">
<h3>
<span class="glyphicon glyphicon-book"></span>
Click here to review instructional materials for {{product.name}}
{% if not user.userprofile.task_inst_complete %}
<div class="task-current">
<span class="glyphicon glyphicon-unchecked"></span>
{{product.name}} Information and Instructions
</div>
{% elif user.userprofile.task_inst_complete %}
<span class="glyphicon glyphicon-check"></span>
{{product.name}} Information and Instructions
{% endif %}
</h3>
</a>
</div>
@@ -6,23 +6,35 @@ <h1>Registration</h1>
{% if registered %}
<h2>Thank you for registering!</h2>
{% else %}
<h2>Create an account</h2>
<h2 class="form-signin-heading">Create an account</h2>

<form role="form" id="user_form" method="post" action="/op_tasks/register" enctype="multipart/form-data">
{% csrf_token %}

<!-- Display each form. The as_p method wraps each element in a paragraph
(<p>) element. This ensures each element appears on a new line, making everything look neater. -->
{{ user_form.as_p }}
<!-- {{ profile_form.as_p }} -->

<!-- Provide a button to click to submit the form. -->
<input type="submit" name="submit" value="Register" />
<div class="form-group">
<p class="required">
<label for="id_email">Username: (please use a valid email address)</label>
<input class="form-control" id="id_email" name="username" type="email" placeholder="Enter email"/>
</p>
</div>
<div class="form-group">
<p class="required">
<label for="id_password1">Password:</label>
<input class="form-control" id="id_password" name="password" type="password" placeholder="Enter password"/>
</p>
</div>
<div class="form-group">
<p class="required">
<label for="id_password2">Password (again):</label>
<input class="form-control" id="id_password2" name="password2" type="password" placeholder="Enter password again" />
</p>
</div>
<button id="id_register_button" type="submit" class="btn btn-default">Submit</button>
</form>
{% endif %}

{% if registered %}
<h4 class="form-signin-heading">Click here to sign in: <a href="/op_tasks/login/">Sign in</a>
<h4 class="form-signin-heading">Click here to sign in: <a href="/op_tasks/login">Sign in</a>
{% endif %}

{% endblock %}
@@ -37,8 +37,20 @@ <h1><b>Status</b></h1>

<div class="product-instructions" >
<a href="/op_tasks/instruct/">
<span class="glyphicon glyphicon-book"></span>
Click here to review instructional materials
{% if not user.userprofile.read_instructions %}
<div class="task-current">
<h3>
<span class="glyphicon glyphicon-unchecked"></span>
Click here to review instructional materials
</h3>
</div>
{% else %}
<h3>
<span class="glyphicon glyphicon-check"></span>
Click here to review instructional materials
</h3>
<p class="text">This material is available throughout the experiment</p>
{% endif %}
</a>
</div>
<table class="ot-list table table-bordered">
@@ -57,12 +69,12 @@ <h1><b>Status</b></h1>
</td>
</tr>
{% elif task.task_complete and not task.exit_complete %}
<tr class="ot-current">
<tr class="task-current">
<td class="status">
<span class="glyphicon glyphicon-unchecked"></span>
</td>
<td>
<div class="ot-current">
<div class="task-current">
<h3 class="heading disabled">{{task.op_task.name}}</h3>
<p class="text disabled">Task Complete. Thank You!</p>
<a href="" data-toggle="modal" data-target="#exit-{{task.pk}}"><span class="glyphicon glyphicon-hand-right"></span>
@@ -71,12 +83,12 @@ <h3 class="heading disabled">{{task.op_task.name}}</h3>
</td>
</tr>
{% elif task.task_active %}
<tr class="ot-current">
<tr class="task-current">
<td class="status">
<span class="glyphicon glyphicon-unchecked"></span>
</td>
<td>
<a class="ot-current" href="{% url 'op_tasks:product' task_pk=task.pk %}">
<a class="task-current" href="{% url 'op_tasks:product' task_pk=task.pk %}">
<h3 class="heading">{{task.op_task.name}}</h3>
<p class="text">Task not yet completed. Click to start this Operational Task</p>
</a>
@@ -20,6 +20,6 @@
url(r'^product_instructions$', views.product_instruct, name='product_instruct')
)

print settings.DEBUG, settings.STATIC_ROOT
# print settings.DEBUG, settings.STATIC_ROOT
if settings.DEBUG:
urlpatterns += url(r'^static/(?P<path>.*)$', vs.serve),

0 comments on commit 3712236

Please sign in to comment.