Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions neuropy/medication/fixtures/medication.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"half_life":"03:30:00",
"medium_end":"05:00:00",
"medium_start":"03:30:00",
"peak_period":"04:30:00",
"peak_period":"09:30:00",
"med_type":"stimulant",
"peak_end":"09:30:00",
"post_peak_easy_start":"12:00:00",
Expand All @@ -31,7 +31,7 @@
"half_life":"10:00:00",
"medium_end":"05:00:00",
"medium_start":"03:30:00",
"peak_period":"04:00:00",
"peak_period":"09:30:00",
"med_type":"stimulant",
"peak_end":"09:30:00",
"post_peak_easy_start":"12:00:00",
Expand All @@ -53,7 +53,7 @@
"half_life":"07:00:00",
"medium_end":"05:00:00",
"medium_start":"03:30:00",
"peak_period":"06:00:00",
"peak_period":"09:30:00",
"med_type":"stimulant",
"peak_end":"09:30:00",
"post_peak_easy_start":"12:00:00",
Expand All @@ -75,7 +75,7 @@
"half_life":"03:30:00",
"medium_end":"05:00:00",
"medium_start":"03:30:00",
"peak_period":"06:00:00",
"peak_period":"09:30:00",
"med_type":"stimulant",
"peak_end":"09:30:00",
"post_peak_easy_start":"12:00:00",
Expand All @@ -97,7 +97,7 @@
"half_life":"11:00:00",
"medium_end":"05:00:00",
"medium_start":"03:30:00",
"peak_period":"04:00:00",
"peak_period":"09:30:00",
"med_type":"stimulant",
"peak_end":"09:30:00",
"post_peak_easy_start":"12:00:00",
Expand Down
1 change: 0 additions & 1 deletion neuropy/medication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ class Medication(models.Model):
post_peak_medium_end = models.CharField(validators=[validate_comma_separated_integer_list], max_length=50)
post_peak_easy_start = models.CharField(validators=[validate_comma_separated_integer_list], max_length=50)
post_peak_easy_end = models.CharField(validators=[validate_comma_separated_integer_list], max_length=50)
# Ease_priority_matrix=models.CharField

def __str__(self):
"""String representation of Medication."""
Expand Down
79 changes: 48 additions & 31 deletions neuropy/medication/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,65 @@
from medication.models import Medication
import factory
import datetime


class MedicationFactory(factory.django.DjangoModelFactory):
"""Create test instance of todos."""

class Meta:
"""Invoke Todo instance using Todo model class."""

model = Medication

name = 'CONCERTA'
med_type = 'stimulant'
treating_dis = 'ADD/ADHD'
half_life = datetime.timedelta(hours=3, minutes=30) # 03:30:00
ramp_up = datetime.timedelta(hours=4, minutes=30) # 04:30:00
peak_period = datetime.timedelta(hours=7) # 07:00:00

import dateutil

class MedicationTestCase(TestCase):
"""Test the Medication model."""

def setUp(self):
"""Setup for medications."""
self.medications = [MedicationFactory.create() for i in range(10)]
self.medications = [medication for medication in Medication.objects.all()]

def test_name(self):
def test_all_meds_are_present(self):
"""Test top all ADHD medications are present."""
self.assertTrue(self.medications[0].name == 'CONCERTA')
self.assertTrue(self.medications[1].name == 'ADDERALL')
self.assertTrue(self.medications[2].name == 'Focalin')
self.assertTrue(self.medications[3].name == 'Ritalin LA')
self.assertTrue(self.medications[4].name == 'Vyvanse')

def test_medication1_info_is_correct(self):
"""Test that a medication instance has a name."""
medication = self.medications[1]
medication = Medication.objects.get(id=medication.id)
self.assertTrue(medication.name == "CONCERTA")
med1 = self.medications[0]
self.assertTrue(med1.name == "CONCERTA")
self.assertTrue(med1.med_type == 'stimulant')
self.assertTrue(med1.treating_dis == 'ADD/ADHD')
self.assertTrue(med1.half_life == datetime.timedelta(hours=3, minutes=30))
self.assertTrue(med1.ramp_up == datetime.timedelta(hours=3, minutes=30))

def test_treating_disorder(self):
def test_treating_disorder_are_all_same(self):
"""Test that a medication instance has a name."""
medication = self.medications[1]
medication = Medication.objects.get(id=medication.id)
self.assertTrue(medication.treating_dis == "ADD/ADHD")
for medication in self.medications:
self.assertTrue(medication.treating_dis == "ADD/ADHD")

def test_med_type(self):
"""Test medication instance type."""
medication = self.medications[1]
medications = Medication.objects.get(id=medication.id)
self.assertTrue(medication.med_type == "stimulant")
def test_med_type_are_all_same(self):
"""Test medicatcion instance type."""
for medication in self.medications:
self.assertTrue(medication.med_type == "stimulant")

def test_no_dupelicate_medication(self):
"""Test that there are no duplicates of a medication."""
seen_meds = []
for medication in self.medications:
if medication in seen_meds:
raise ValueError("Medication already exists")
else:
seen_meds.append(medication)
return seen_meds

def test_peak_start_is_before_peak_end(self):
"""Test that peak start time is before peak end."""
for medication in self.medications:
self.assertTrue(medication.peak_start < medication.peak_end)

def test_medication_duration(self):
"""Test medication peak duration is equal to diff between peak-end and start."""
for medication in self.medications:
peak_end = dateutil.parser.parse(medication.peak_end)
peak_start = dateutil.parser.parse(medication.peak_start)
peak_delta = peak_end - peak_start
peak_period = medication.peak_period
self.assertTrue(peak_delta == peak_period)

def test_change_data(self):
"""Test Editing medication data."""
Expand Down
12 changes: 6 additions & 6 deletions neuropy/todo/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ def __init__(self, *args, **kwargs):
super(TodoForm, self).__init__(*args, **kwargs)

PRIORITY_CHOICES = (
(1, 'Now'),
(2, 'Urgent'),
(3, 'Semi Urgent'),
(4, 'Non Urgent'),
(4, 'Now'),
(3, 'Urgent'),
(2, 'Semi Urgent'),
(1, 'Non Urgent'),
)

EASE_CHOICES = (
(1, 'Easy'),
(2, 'Medium'),
(3, 'Difficult'),
(2, 'Medium'),
(1, 'Easy'),
)
self.fields['title'] = forms.CharField(initial=self.instance.title)
self.fields['description'] = forms.CharField(widget=forms.Textarea, initial=self.instance.description)
Expand Down
10 changes: 5 additions & 5 deletions neuropy/todo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ class Todo(models.Model):
"""Model for an individual Todo."""

PRIORITY_CHOICES = (
(4, 'Non Urgent'),
(4, 'Now'),
(3, 'Urgent'),
(2, 'Semi-Urgent'),
(1, 'Now'),
(2, 'Semi Urgent'),
(1, 'Non Urgent'),
)

EASE_CHOICES = (
(1, 'Easy'),
(2, 'Medium'),
(3, 'Difficult'),
(2, 'Medium'),
(1, 'Easy'),
)

title = models.CharField(max_length=255, blank=True)
Expand Down
39 changes: 31 additions & 8 deletions neuropy/todo/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,24 +127,30 @@ def generate_todos(self):
user = self.users[5]
todo1 = self.todos[0]
todo2 = self.todos[2]
todo1.owner, todo2.owner = user.profile, user.profile
todo3 = self.todos[1]
todo1.owner, todo2.owner, todo3.owner = user.profile, user.profile, user.profile

todo1.date = datetime.date.today()
todo2.date = datetime.date.today()
todo3.date = datetime.date.today()

todo1.ease = 1
todo2.ease = 2
todo3.ease = 3

todo1.priority = 2
todo2.priority = 3
todo3.priority = 4

todo1.duration = 1
todo2.duration = 2
todo3.duration = 3

user.save()
todo1.save()
todo2.save()
return user.profile, [todo1, todo2]
todo3.save()
return user.profile, [todo1, todo2, todo3]

def make_user_and_login(self):
"""Make user and login."""
Expand Down Expand Up @@ -460,25 +466,27 @@ def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self):
self.assertTrue('<p><strong>Duration: </strong>3</p>' in html)
self.assertTrue('<p><strong>Description: </strong>Then Buy 7/11</p>' in html)

# --------------- Algorithm Unittests ------------------

def test_todo_ease_level_is_correct(self):
"""Test todo ease level is correct."""
profile, todos = self.generate_todos()
todos = create_event_list("CONCERTA", profile)
self.assertTrue(len(todos) == 2)
self.assertTrue(len(todos) == 4)

def test_todo_is_in_order(self):
"""Test todo is arranged in right order."""
profile, todo_lst = self.generate_todos()
todos = create_event_list("CONCERTA", profile)
self.assertTrue(todos[0]['title'] == todo_lst[1].title)
self.assertTrue(todos[1]['title'] == todo_lst[0].title)
self.assertTrue(todos[2]['title'] == todo_lst[1].title)
self.assertTrue(todos[0]['title'] == todo_lst[2].title)

def test_todos_are_correct_ease_level(self):
"""Test todo is assigned to correct ease levels."""
profile, todo_lst = self.generate_todos()
todos = create_event_list("CONCERTA", profile)
self.assertTrue(todos[0]['ease'] == 'hard')
self.assertTrue(todos[1]['ease'] == 'medium')
self.assertTrue(todos[1]['ease'] == 'hard')

def test_todo_created_on_profile_on_wrong_date(self):
"""Test todo is created for current date."""
Expand Down Expand Up @@ -511,8 +519,23 @@ def test_todo_duration(self):
profile, todo_lst = self.generate_todos()
todos = create_event_list("CONCERTA", profile)
diff_todos_1 = todos[1]['end'] - todos[1]['start']
self.assertTrue(datetime.timedelta(hours=todo_lst[0].duration) == diff_todos_1)
self.assertTrue(datetime.timedelta(hours=todo_lst[2].duration) == diff_todos_1)

def test_priority_now_does_not_duplicate(self):
"""Test that a priority to-do does not show as duplicate events."""
from todo.views import create_event_list
profile, todo_lst = self.generate_todos()
todos = create_event_list("CONCERTA", profile)
seen_tasks = []
for todo in todos:
if todo in seen_tasks:
raise ValueError("Todo already exists")
else:
seen_tasks.append(todo)
self.assertTrue(todos[0]['description'] == 'Todo 381' and todos[1]['description'] == 'Todo 381')
return seen_tasks

# --------------------- End Algorithm Unittests ---------------------

def test_logged_out_todo_fails(self):
"""Test that a logged out user cannot create a todo."""
Expand Down Expand Up @@ -584,7 +607,7 @@ def test_schedule_view_returns(self):
"""Test that schedule view returns the right page."""
self.client.force_login(self.users[0])
session = self.client.session
session['some_list'] = [{},{},{}]
session['some_list'] = [{}, {}, {}]
session.save()
html = self.client.get(reverse_lazy('create_sched')).content
parsed_html = BeautifulSoup(html, "html5lib")
Expand Down
2 changes: 1 addition & 1 deletion neuropy/todo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def create_event_list(drug_name, profile):
priority_now = Todo.objects.filter(owner=profile, date=today, priority=4).order_by('ease')
bucket_list = [priority_now, hard, medium, easy]

today = datetime.date.today()
# today = datetime.date.today()
start_time = datetime.datetime(today.year, today.month, today.day, 9)

def td(time):
Expand Down
1 change: 0 additions & 1 deletion neuropy/userprofile/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ def test_user_in_group(self):

def test_profile_has_attributes(self):
"""Test that the profile has attributes and assigns defaults."""
# import pdb; pdb.set_trace()
users = self.users
attributes = [
'active_period_start', 'active_period_end', 'peak_period', 'dose_time'
Expand Down