From d8e555336d59bafa6a18936a89d85c2033e2248e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 05:04:24 -0800 Subject: [PATCH 1/8] fixed added more algo tests. passing. --- neuropy/todo/tests.py | 41 +++++++++++++++++++++++++++++++++-------- neuropy/todo/views.py | 2 +- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index dbc61ae..06512b6 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -11,7 +11,6 @@ from bs4 import BeautifulSoup import datetime - class TodoFactory(factory.django.DjangoModelFactory): """Create test instance of todos.""" @@ -127,24 +126,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.""" @@ -419,6 +424,23 @@ def test_edit_todo_status_code_302(self): }) self.assertTrue(response.status_code == 302) + 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) + # import pdb; pdb.set_trace() + seen_tasks = [] + # bucket_list = [priority_now, hard, medium, easy] + # for bucket in bucket_list: + 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 + def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self): """Test edit todo saves db and shows to detail todo view.""" user = self.users[4] @@ -460,25 +482,27 @@ def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self): self.assertTrue('

Duration: 3

' in html) self.assertTrue('

Description: Then Buy 7/11

' 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[0]['title'] == todo_lst[2].title) + self.assertTrue(todos[2]['title'] == todo_lst[1].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.""" @@ -511,8 +535,9 @@ 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_logged_out_todo_fails(self): """Test that a logged out user cannot create a todo.""" diff --git a/neuropy/todo/views.py b/neuropy/todo/views.py index 3bb7cc4..1462ca6 100644 --- a/neuropy/todo/views.py +++ b/neuropy/todo/views.py @@ -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): From b14c5ef605d2dae0e691c7ae308c2bcf30071a41 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 05:07:58 -0800 Subject: [PATCH 2/8] moved algo test to designated area. --- neuropy/todo/tests.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index 06512b6..ab40cde 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -424,23 +424,6 @@ def test_edit_todo_status_code_302(self): }) self.assertTrue(response.status_code == 302) - 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) - # import pdb; pdb.set_trace() - seen_tasks = [] - # bucket_list = [priority_now, hard, medium, easy] - # for bucket in bucket_list: - 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 - def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self): """Test edit todo saves db and shows to detail todo view.""" user = self.users[4] @@ -484,6 +467,7 @@ def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self): # --------------- Algorithm Unittests ------------------ + def test_todo_ease_level_is_correct(self): """Test todo ease level is correct.""" profile, todos = self.generate_todos() @@ -537,6 +521,23 @@ def test_todo_duration(self): diff_todos_1 = todos[1]['end'] - todos[1]['start'] 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) + # import pdb; pdb.set_trace() + seen_tasks = [] + # bucket_list = [priority_now, hard, medium, easy] + # for bucket in bucket_list: + 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 + # ----------------------- --------------------------- def test_logged_out_todo_fails(self): From 250494b0c51a97f6bb4113f6a72e977878b266dd Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 19:21:16 -0800 Subject: [PATCH 3/8] diff --- neuropy/medication/tests.py | 63 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 30 deletions(-) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py index 11f1bd7..94b4427 100644 --- a/neuropy/medication/tests.py +++ b/neuropy/medication/tests.py @@ -6,46 +6,49 @@ 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 - - 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_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_name(self): + 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_change_data(self): """Test Editing medication data.""" From 953d22269d03c10e3db193a6dd35136a1f9195ec Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 19:22:57 -0800 Subject: [PATCH 4/8] corpse code. --- neuropy/medication/models.py | 1 - neuropy/todo/forms.py | 12 ++++++------ neuropy/todo/models.py | 10 +++++----- neuropy/todo/tests.py | 6 +++--- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/neuropy/medication/models.py b/neuropy/medication/models.py index 20becae..a932bbc 100644 --- a/neuropy/medication/models.py +++ b/neuropy/medication/models.py @@ -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.""" diff --git a/neuropy/todo/forms.py b/neuropy/todo/forms.py index 6d4ed6f..8cc3428 100644 --- a/neuropy/todo/forms.py +++ b/neuropy/todo/forms.py @@ -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) diff --git a/neuropy/todo/models.py b/neuropy/todo/models.py index fb51c99..f3bbbe6 100644 --- a/neuropy/todo/models.py +++ b/neuropy/todo/models.py @@ -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) diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index ab40cde..6d58c95 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -478,8 +478,8 @@ 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[2].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.""" @@ -526,8 +526,8 @@ def test_priority_now_does_not_duplicate(self): from todo.views import create_event_list profile, todo_lst = self.generate_todos() todos = create_event_list("CONCERTA", profile) - # import pdb; pdb.set_trace() seen_tasks = [] + # import pdb; pdb.set_trace() # bucket_list = [priority_now, hard, medium, easy] # for bucket in bucket_list: for todo in todos: @@ -610,7 +610,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") From 98cc36ee99ea83210029ee80db1ec2ec5c170e93 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 22:58:05 -0800 Subject: [PATCH 5/8] Added tests --- neuropy/medication/tests.py | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/neuropy/medication/tests.py b/neuropy/medication/tests.py index 94b4427..780d698 100644 --- a/neuropy/medication/tests.py +++ b/neuropy/medication/tests.py @@ -4,7 +4,7 @@ from medication.models import Medication import factory import datetime - +import dateutil class MedicationTestCase(TestCase): """Test the Medication model.""" @@ -50,6 +50,20 @@ def test_no_dupelicate_medication(self): 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.""" medication = self.medications[1] From f5f6d035358898402959fa29640d6e3fa7a30b3e Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 22:58:25 -0800 Subject: [PATCH 6/8] Added medication JSON files --- neuropy/medication/fixtures/medication.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/neuropy/medication/fixtures/medication.json b/neuropy/medication/fixtures/medication.json index d5a21ba..a68dcf3 100644 --- a/neuropy/medication/fixtures/medication.json +++ b/neuropy/medication/fixtures/medication.json @@ -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", @@ -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", @@ -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", @@ -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", @@ -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", From d192bd12da90660e38a685a6ed2a906089365e39 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 22:59:09 -0800 Subject: [PATCH 7/8] added more todo algo tests. All passing. --- neuropy/todo/tests.py | 1 + 1 file changed, 1 insertion(+) diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index 6d58c95..769e05d 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -11,6 +11,7 @@ from bs4 import BeautifulSoup import datetime + class TodoFactory(factory.django.DjangoModelFactory): """Create test instance of todos.""" From 8680b0f8e53c828f02ada3a37d1ca51b404a93a9 Mon Sep 17 00:00:00 2001 From: Your Name Date: Mon, 20 Feb 2017 23:05:45 -0800 Subject: [PATCH 8/8] clean up corpse code and comments. --- neuropy/todo/tests.py | 6 +----- neuropy/userprofile/tests.py | 1 - 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/neuropy/todo/tests.py b/neuropy/todo/tests.py index 769e05d..83ffb7c 100644 --- a/neuropy/todo/tests.py +++ b/neuropy/todo/tests.py @@ -466,7 +466,6 @@ def test_edit_todo_saves_db_and_shows_to_detail_todo_view(self): self.assertTrue('

Duration: 3

' in html) self.assertTrue('

Description: Then Buy 7/11

' in html) - # --------------- Algorithm Unittests ------------------ def test_todo_ease_level_is_correct(self): @@ -528,9 +527,6 @@ def test_priority_now_does_not_duplicate(self): profile, todo_lst = self.generate_todos() todos = create_event_list("CONCERTA", profile) seen_tasks = [] - # import pdb; pdb.set_trace() - # bucket_list = [priority_now, hard, medium, easy] - # for bucket in bucket_list: for todo in todos: if todo in seen_tasks: raise ValueError("Todo already exists") @@ -539,7 +535,7 @@ def test_priority_now_does_not_duplicate(self): 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.""" diff --git a/neuropy/userprofile/tests.py b/neuropy/userprofile/tests.py index c396f8b..92208e7 100644 --- a/neuropy/userprofile/tests.py +++ b/neuropy/userprofile/tests.py @@ -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'