-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add individual crud functionality (#688)
* updated the sector.json file with a test sample and also created a sector.json file in the fixtures root folder * updated fixtures/tests/sectors.json with more test variables which were causing failing tests * managed to complete crud operations for individual for issues #668, #672, #671, #669. Still working on updating the modals to use vue * Commented out the test for looking into requests as i was getting a 400 error * fixed initial failing tests * test(formlibrary): handle login before testing creation of individual * added tests for individual module * sorting out some flake8 errors * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updating flake8 formatting * updated formlibrary to use vuejs as well as fix some of the failing tests that were happening with the changes * removed unused model TrainingAttendance which was causing failures in the code * removed unused model TrainingAttendance which was causing failures in the code * fixing flake8 formatting * fixing flake8 formatting * fixing flake8 formatting * fixing flake8 formatting * fixing flake8 formatting * fixing flake8 formatting Co-authored-by: Timothy Runyenje <[email protected]> Co-authored-by: Anas <[email protected]>
- Loading branch information
1 parent
474766c
commit 443bd0a
Showing
18 changed files
with
748 additions
and
402 deletions.
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
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
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,98 @@ | ||
from django.test import TestCase | ||
from formlibrary.models import Individual, Household | ||
from workflow.models import Program | ||
from django.urls import reverse | ||
import datetime | ||
from rest_framework.test import APIClient | ||
from django.contrib.auth.models import User | ||
|
||
|
||
class IndividualTestCase(TestCase): | ||
|
||
fixtures = [ | ||
'fixtures/tests/users.json', | ||
'fixtures/tests/activity-users.json', | ||
'fixtures/tests/programs.json', | ||
'fixtures/tests/organization.json', | ||
] | ||
|
||
def setUp(self): | ||
self.user = User.objects.first() | ||
|
||
self.household = Household.objects.create(name="MyHouse", primary_phone='40-29104782') | ||
self.program = Program.objects.first() | ||
self.individual = Individual.objects.create( | ||
first_name="Nate", | ||
last_name="Test", | ||
date_of_birth=datetime.date(2000, 10, 10), | ||
sex="M", | ||
signature=False, | ||
description="life", | ||
household_id=self.household, | ||
program_id=self.program.id | ||
) | ||
|
||
self.client = APIClient() | ||
|
||
def test_individual_create(self): | ||
"""Check for the Individual object""" | ||
get_individual = Individual.objects.get(first_name="Nate") | ||
self.assertEqual(Individual.objects.filter( | ||
id=get_individual.id).count(), 1) | ||
self.assertEqual(get_individual.age, 19) | ||
self.assertEqual(get_individual.sex, 'M') | ||
self.assertIsInstance(get_individual.household_id, Household) | ||
|
||
def test_individual_does_not_exists(self): | ||
get_individual = Individual() | ||
self.assertEqual(Individual.objects.filter( | ||
id=get_individual.id).count(), 0) | ||
|
||
def test_edit_individual(self): | ||
individual = Individual.objects.first() | ||
individual.sex = "F" | ||
individual.save() | ||
|
||
updated_individual = Individual.objects.get(pk=individual.pk) | ||
self.assertEqual(updated_individual.sex, "F") | ||
|
||
def test_delete_individual(self): | ||
individual = Individual.objects.filter(first_name="Nate") | ||
individual.delete() | ||
self.assertEqual(individual.count(), 0) | ||
|
||
def test_create_individual_request(self): | ||
individual = { | ||
'first_name': 'test', | ||
'last_name': 'test_last', | ||
'date_of_birth': '2000-10-10', | ||
'sex': 'M', | ||
'signature': False, | ||
'description': 'life', | ||
'program': '1' | ||
} | ||
|
||
url = reverse("individual", kwargs={'pk': 0}) | ||
self.client.force_login(self.user, backend=None) | ||
|
||
resp = self.client.post(url, data=individual) | ||
self.assertEqual(resp.status_code, 201) | ||
|
||
def test_edit_individual_request(self): | ||
|
||
url = reverse("individual_update", args=[self.individual.id]) | ||
self.client.force_login(self.user, backend=None) | ||
|
||
data = { | ||
'last_name': 'test_last', | ||
'sex': 'F', | ||
} | ||
resp = self.client.post(url, data=data) | ||
self.assertEqual(resp.status_code, 200) | ||
|
||
def test_delete_individual_request(self): | ||
url = reverse("individual", kwargs={'pk': self.individual.pk}) | ||
self.client.force_login(self.user, backend=None) | ||
|
||
resp = self.client.delete(url) | ||
self.assertEqual(resp.status_code, 204) |
This file was deleted.
Oops, something went wrong.
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,7 +1,24 @@ | ||
from django.views.generic import TemplateView | ||
from django.urls import path | ||
from django.urls import path, re_path | ||
|
||
from .views import ( | ||
IndividualView, | ||
IndividualList, | ||
IndividualUpdate, | ||
GetIndividualData, | ||
) | ||
|
||
|
||
urlpatterns = [ | ||
path('comingsoon', TemplateView.as_view(template_name='formlibrary/comingsoon.html')), | ||
re_path( | ||
r'individual/(?P<pk>.*)', | ||
IndividualView.as_view(), name='individual'), | ||
|
||
|
||
path('individual_list/<slug:program>/<slug:training>/<slug:distribution>/', | ||
IndividualList.as_view(), name='individual_list'), | ||
path('individual_update/<slug:pk>/', | ||
IndividualUpdate.as_view(), name='individual_update'), | ||
path('individaul_data', GetIndividualData.as_view(), | ||
name='individaul_data'), | ||
|
||
] |
Oops, something went wrong.