From b1adc093079e026c5999d224b5db9cb2d42d008d Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 13:56:56 +0100 Subject: [PATCH 1/7] Dev : Goodness Ezeokafor Date: 13th October 2019 Message : added unit test for the Profile model --- web/accounts/models.py | 3 + web/accounts/tests.py | 3 - web/accounts/tests/__init__.py | 0 web/accounts/tests/test_forms.py | 7 +++ web/accounts/tests/test_models.py | 96 +++++++++++++++++++++++++++++++ web/accounts/tests/test_views.py | 0 6 files changed, 106 insertions(+), 3 deletions(-) delete mode 100644 web/accounts/tests.py create mode 100644 web/accounts/tests/__init__.py create mode 100644 web/accounts/tests/test_forms.py create mode 100644 web/accounts/tests/test_models.py create mode 100644 web/accounts/tests/test_views.py diff --git a/web/accounts/models.py b/web/accounts/models.py index e713724..bcca82e 100644 --- a/web/accounts/models.py +++ b/web/accounts/models.py @@ -18,6 +18,9 @@ class Profile(models.Model): tagline = models.CharField(max_length=35, null=True, blank=True) gender = models.CharField(max_length=1, choices=GENDER) + def __str__(self): + return f'{self.user} profile' + @receiver(post_save, sender=User) def update_user_profile(sender, instance, created, **kwargs): if created: diff --git a/web/accounts/tests.py b/web/accounts/tests.py deleted file mode 100644 index 7ce503c..0000000 --- a/web/accounts/tests.py +++ /dev/null @@ -1,3 +0,0 @@ -from django.test import TestCase - -# Create your tests here. diff --git a/web/accounts/tests/__init__.py b/web/accounts/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/web/accounts/tests/test_forms.py b/web/accounts/tests/test_forms.py new file mode 100644 index 0000000..a993f20 --- /dev/null +++ b/web/accounts/tests/test_forms.py @@ -0,0 +1,7 @@ +from django.test import TestCase +from django import forms + + + +class SignUpFormTest(TestCase): + pass \ No newline at end of file diff --git a/web/accounts/tests/test_models.py b/web/accounts/tests/test_models.py new file mode 100644 index 0000000..c1d9c74 --- /dev/null +++ b/web/accounts/tests/test_models.py @@ -0,0 +1,96 @@ +from django.test import TestCase +from django.contrib.auth.models import User +from accounts.models import Profile + + +class ProfileModelTest(TestCase): + ''' + To Run The Test : python manage.py test accounts.tests.test_models + ''' + @classmethod + def setUpTestData(cls): + test_user = User.objects.create_user( + username="TestUser", + password = "TestPassword" + ) + profile = test_user.profile + profile.bio = "A Dev" + profile.tagline = "Python" + profile.gender = "M" + profile.save() + + + #Testing Profile Model String Representation + def test_str_representation(self): + profile = Profile.objects.get(id=1) + expected_ouput = f'{profile.user} profile' + self.assertEquals(expected_ouput, str(profile)) + def test_profile_vals(self): + test_user = User.objects.latest('id') + profile = Profile.objects.get(id=1) + self.assertEquals(profile.user,test_user) + self.assertEquals(profile.bio,"A Dev") + self.assertEquals(profile.tagline,"Python") + self.assertEquals(profile.gender,"M") + + + # Testing Profile Fields Labels + def test_user_label(self): + ''' + testing the user field in the Profile model + ''' + profile = Profile.objects.get(id=1) + field_label = profile._meta.get_field('user').verbose_name + self.assertEquals(field_label,'user') + + def test_bio_label(self): + ''' + testing the bio field in the Profile model + ''' + profile = Profile.objects.get(id=1) + field_label = profile._meta.get_field('bio').verbose_name + self.assertEquals(field_label,'bio') + + def test_tagline_label(self): + ''' + testing the tagline field in the Profile model + ''' + profile = Profile.objects.get(id=1) + field_label = profile._meta.get_field('tagline').verbose_name + self.assertEquals(field_label,'tagline') + + def test_gender_label(self): + ''' + testing the gender field in the Profile model + ''' + profile = Profile.objects.get(id=1) + field_label = profile._meta.get_field('gender').verbose_name + self.assertEquals(field_label,'gender') + + + # Testing Profile Fields Maxlength + def test_bio_max_length(self): + profile = Profile.objects.get(id=1) + maxlength = profile._meta.get_field('bio').max_length + self.assertEquals(maxlength,500) + + + def test_tagline_max_length(self): + profile = Profile.objects.get(id=1) + maxlength = profile._meta.get_field('tagline').max_length + self.assertEquals(maxlength,35) + + + def test_gender_max_length(self): + profile = Profile.objects.get(id=1) + maxlength = profile._meta.get_field('gender').max_length + self.assertEquals(maxlength,1) + + + + + + + + + diff --git a/web/accounts/tests/test_views.py b/web/accounts/tests/test_views.py new file mode 100644 index 0000000..e69de29 From 88c32127ba3e6165528bfb084f76b87501711270 Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 14:35:08 +0100 Subject: [PATCH 2/7] Dev: Goodness Ezeokafor Date: 13th October 2019 Message: Added Unit Testing For The SignUp Form --- web/accounts/tests/test_forms.py | 48 ++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 3 deletions(-) diff --git a/web/accounts/tests/test_forms.py b/web/accounts/tests/test_forms.py index a993f20..345cfeb 100644 --- a/web/accounts/tests/test_forms.py +++ b/web/accounts/tests/test_forms.py @@ -1,7 +1,49 @@ from django.test import TestCase -from django import forms - +from accounts.forms import SignUpForm class SignUpFormTest(TestCase): - pass \ No newline at end of file + ''' + Unit Test For The Sign Up Form + To Run The Test : python manage.py test accounts.tests.test_forms + ''' + def test_bio_label(self): + form = SignUpForm() + self.assertTrue(form.fields['bio'].label == None or form.fields['bio'] == 'bio') + + def test_gender_label(self): + form= SignUpForm() + self.assertTrue(form.fields['gender'].label==None or form.fields['gender']== 'gender') + + + def test_tagline_label(self): + form = SignUpForm() + self.assertTrue(form.fields['tagline'].label == None or form.fields['tagline'] =='tagline') + + def test_occupation_label(self): + form = SignUpForm() + self.assertTrue(form.fields['occupation'].label == None or form.fields['occupation'] =='occupation') + + def test_first_name_label(self): + form = SignUpForm() + self.assertEquals(form.fields['first_name'].label,'First name') + + def test_last_name_label(self): + form = SignUpForm() + self.assertEquals(form.fields['last_name'].label,'Last name') + + def test_username_label(self): + form = SignUpForm() + self.assertEquals(form.fields['username'].label,'Username') + + def test_email_label(self): + form = SignUpForm() + self.assertTrue(form.fields['email'].label,'Email address') + + def test_password1_label(self): + form = SignUpForm() + self.assertTrue(form.fields['password1'].label,'Password') + + def test_password2_label(self): + form = SignUpForm() + self.assertTrue(form.fields['password2'].label,'Password confirmation') From 569784bcdb34deecb57c86c661538da2782b8d4b Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 15:49:09 +0100 Subject: [PATCH 3/7] Dev : Goodness Ezeokafor Date: 13th October Message: added unit test for account views --- web/accounts/tests/test_forms.py | 58 +++++++++++++++++++++++++++++ web/accounts/tests/test_views.py | 63 ++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+) diff --git a/web/accounts/tests/test_forms.py b/web/accounts/tests/test_forms.py index 345cfeb..380113e 100644 --- a/web/accounts/tests/test_forms.py +++ b/web/accounts/tests/test_forms.py @@ -1,5 +1,6 @@ from django.test import TestCase from accounts.forms import SignUpForm +from accounts.models import Profile class SignUpFormTest(TestCase): @@ -7,6 +8,8 @@ class SignUpFormTest(TestCase): Unit Test For The Sign Up Form To Run The Test : python manage.py test accounts.tests.test_forms ''' + + # Testing Form Label def test_bio_label(self): form = SignUpForm() self.assertTrue(form.fields['bio'].label == None or form.fields['bio'] == 'bio') @@ -47,3 +50,58 @@ def test_password1_label(self): def test_password2_label(self): form = SignUpForm() self.assertTrue(form.fields['password2'].label,'Password confirmation') + + + # Testing Form Help Text + def test_bio_help_text(self): + form = SignUpForm() + self.assertEquals(form.fields['bio'].help_text,"Let us know a bit more about you") + + def test_tagline_help_text(self): + form = SignUpForm() + self.assertEquals(form.fields['tagline'].help_text,"A catch phrase of you") + + # Testing Form Choices + + def test_gender_choices(self): + form = SignUpForm() + self.assertEquals(tuple(form.fields['gender'].choices),Profile.GENDER) + + def test_occupation_choices(self): + form = SignUpForm() + self.assertEquals(tuple(form.fields['occupation'].choices),Profile.OCCUPATION) + + + # Valid/Invalid + def test_valid_form_data(self): + form =SignUpForm() + data= { + 'bio':'A Passionate Developer', + 'tagline':'Great Guy', + 'gender':'M', + 'occupation':'P', + 'first_name':'testuserfirstname', + 'last_name':'testuserlastname', + 'username':'testusername', + 'password1':'testuserpassword', + 'password2':'testuserpassword', + 'email':'testuser@gmail.com' + } + form = SignUpForm(data=data) + self.assertTrue(form.is_valid()) + def test_invalid_form_data(self): + form =SignUpForm() + data= { + 'bio':'A Passionate Developer', + 'tagline':'Great Guy', + 'gender':'M', + 'occupation':'P', + 'first_name':'testuserfirstname', + 'last_name':'testuserlastname', + 'username':'', + 'password1':'testuserpassword', + 'password2':'testuserpassword', + 'email':'testuser@gmail.com' + } + form = SignUpForm(data=data) + self.assertFalse(form.is_valid()) \ No newline at end of file diff --git a/web/accounts/tests/test_views.py b/web/accounts/tests/test_views.py index e69de29..b4b25e1 100644 --- a/web/accounts/tests/test_views.py +++ b/web/accounts/tests/test_views.py @@ -0,0 +1,63 @@ +from django.test import TestCase +from django.urls import reverse +from django.contrib.auth import get_user_model +from django.contrib.auth import authenticate + +class IndexPageViewTest(TestCase): + def test_index_page_view_by_status_code(self): + response = self.client.get('/') + self.assertEquals(response.status_code, 200) + + def test_index_page_view_by_name(self): + response= self.client.get(reverse('index')) + self.assertEquals(response.status_code, 200) + + def test_index_page_view_template(self): + response= self.client.get(reverse('index')) + self.assertTemplateUsed(response, "accounts/index.html") + + +# class DashboardPageViewTest(TestCase): +# def test_index_page_view_by_status_code(self): +# response = self.client.get('/') +# self.assertEquals(response.status_code, 200) + +# def test_index_page_view_by_name(self): +# response= self.client.get(reverse('index')) +# self.assertEquals(response.status_code, 200) + +# def test_index_page_view_template(self): +# response= self.client.get(reverse('index')) +# self.assertTemplateUsed(response, "accounts/index.html") +# print(response) + + + +class SignInTest(TestCase): + def setUp(self): + self.user = get_user_model().objects.create_user(username='testuser',password="testpassword") + self.user.save() + + + def tearDown(self): + self.user.delete() + + def test_correct(self): + user =authenticate(username="testuser", password="testpassword") + self.assertTrue((user is not None) and user.is_authenticated) + + def test_wrong_username(self): + user = authenticate(username='wrong', password='testpassword') + self.assertFalse(user is not None and user.is_authenticated) + + def test_wrong_password(self): + user = authenticate(username='test', password='wrong') + self.assertFalse(user is not None and user.is_authenticated) + + +class ProfilePageViewTest(TestCase): + pass + + +class TicketPricingPageViewTest(TestCase): + pass \ No newline at end of file From 112d88da5a31b946949a9abc62b26afd9b6f9f5e Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 17:26:27 +0100 Subject: [PATCH 4/7] Dev : Goodness Ezeokafor Date: 13th October 2019 Message: - added README.md --- README.md | 52 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index d20bc84..b61f7d5 100644 --- a/README.md +++ b/README.md @@ -1 +1,51 @@ -# pyconng-2019 +### PyconNg-2019 + +The official website for PyconNg-2019 visit link + +Event on the 30th October - 2nd November 2019 Wennovation Hub, 50 Ebitu Ukiwe Street. Jabi, Abuja, Nigeria + + +### Install Project + - Create a parent folder + - Clone into the parent folder + - git clone https://github.com/pyung/pyconng-2019.git (HTTPS) + - git clone git@github.com:pyung/pyconng-2019.git (SSH) + - cd web + - Install dependencies + - pipenv install -r requirements.txt (if using pipenv) + - pip install -r requirements.txt (if using pip) + +### Create a virtual environment using virtualenv + - sudo pip3 install virtualenv + - virtualenv + - cd into + - source bin/activate + - pip install + +### Create a virtual environment using pipenv + - Make sure it is installed + - pip install pipenv (windows developers) + - sudo pip3 install pipenv (ubuntu developers) + - Create parent folder + - CD into parent folder and run pipenv --python 3.7/ + - pipenv shell + - pipenv install + + +### Contribute + - fork the repo + - Clone it locally (git clone https://github.com//pyconng-2019.git) + - Add upstream repo (git remote add upstream https://github.com//pyconng-2019.git) + - Create a feature/topic branch (`git checkout -b ) + - Code fix/feature (add required tests and make sure the pass) + - Commit code on feature/topic branch (git add . && git commit -m “awesome”) + - Checkout master (git checkout master) + - Pull latest from upstream (git pull upstream master) + - Checkout feature/topic branch (git checkout ) + - Rebase your changes onto the latest changes in master (git rebase master) + - Push your fix/feature branch to your fork (git push upstream ) + + + + +Thanks alot, happy coding 😎 From 6647429807048b8d5d35b58faaa33ec9ea6a09a6 Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 17:39:01 +0100 Subject: [PATCH 5/7] changed --- README.md | 62 +++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 31 deletions(-) diff --git a/README.md b/README.md index b61f7d5..7a60d07 100644 --- a/README.md +++ b/README.md @@ -6,44 +6,44 @@ Event on the 30th October - 2nd November 2019 Wennovation Hub, 50 Ebitu Ukiwe S ### Install Project - - Create a parent folder - - Clone into the parent folder - - git clone https://github.com/pyung/pyconng-2019.git (HTTPS) - - git clone git@github.com:pyung/pyconng-2019.git (SSH) - - cd web - - Install dependencies - - pipenv install -r requirements.txt (if using pipenv) - - pip install -r requirements.txt (if using pip) + * Create a parent folder + * Clone into the parent folder + * git clone https://github.com/pyung/pyconng-2019.git (HTTPS) + * git clone git@github.com:pyung/pyconng-2019.git (SSH) + * cd web + * Install dependencies + * pipenv install -r requirements.txt (if using pipenv) + * pip install -r requirements.txt (if using pip) ### Create a virtual environment using virtualenv - - sudo pip3 install virtualenv - - virtualenv - - cd into - - source bin/activate - - pip install + * sudo pip3 install virtualenv + * virtualenv + * cd into + * source bin/activate + * pip install ### Create a virtual environment using pipenv - - Make sure it is installed - - pip install pipenv (windows developers) - - sudo pip3 install pipenv (ubuntu developers) - - Create parent folder - - CD into parent folder and run pipenv --python 3.7/ - - pipenv shell - - pipenv install + * Make sure it is installed + * pip install pipenv (windows developers) + * sudo pip3 install pipenv (ubuntu developers) + * Create parent folder + * CD into parent folder and run pipenv --python 3.7/ + * pipenv shell + * pipenv install ### Contribute - - fork the repo - - Clone it locally (git clone https://github.com//pyconng-2019.git) - - Add upstream repo (git remote add upstream https://github.com//pyconng-2019.git) - - Create a feature/topic branch (`git checkout -b ) - - Code fix/feature (add required tests and make sure the pass) - - Commit code on feature/topic branch (git add . && git commit -m “awesome”) - - Checkout master (git checkout master) - - Pull latest from upstream (git pull upstream master) - - Checkout feature/topic branch (git checkout ) - - Rebase your changes onto the latest changes in master (git rebase master) - - Push your fix/feature branch to your fork (git push upstream ) + * fork the repo + * Clone it locally (git clone https://github.com//pyconng-2019.git) + * Add upstream repo (git remote add upstream https://github.com//pyconng-2019.git) + * Create a feature/topic branch (`git checkout -b ) + * Code fix/feature (add required tests and make sure the pass) + * Commit code on feature/topic branch (git add . && git commit -m “awesome”) + * Checkout master (git checkout master) + * Pull latest from upstream (git pull upstream master) + * Checkout feature/topic branch (git checkout ) + * Rebase your changes onto the latest changes in master (git rebase master) + * Push your fix/feature branch to your fork (git push upstream ) From 05eb2d918628e8321eba85e4fe71d4470b49c39c Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 20:44:54 +0100 Subject: [PATCH 6/7] made changes --- web/accounts/tests/test_views.py | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/web/accounts/tests/test_views.py b/web/accounts/tests/test_views.py index b4b25e1..b99a323 100644 --- a/web/accounts/tests/test_views.py +++ b/web/accounts/tests/test_views.py @@ -54,10 +54,29 @@ def test_wrong_password(self): user = authenticate(username='test', password='wrong') self.assertFalse(user is not None and user.is_authenticated) +class SponsorshipViewTest(TestCase): + def test_sponsorship_page_view_by_status_code(self): + response = self.client.get('/sponsorship') + self.assertEquals(response.status_code, 200) + + def test_sponsorship_page_view_by_name(self): + response= self.client.get(reverse('donate')) + self.assertEquals(response.status_code, 200) + + def test_index_page_view_template(self): + response= self.client.get(reverse('donate')) + self.assertTemplateUsed(response, "accounts/sponsorship.html") -class ProfilePageViewTest(TestCase): + +class ThanksViewTest(TestCase): pass -class TicketPricingPageViewTest(TestCase): +class TicketPayCorporateViewTest(TestCase): + pass + +class TicketPayIndividualViewTest(TestCase): + pass + +class TicketPayStudentsViewTest(TestCase): pass \ No newline at end of file From fc6f5c4a9a45f3e550e1fd7fa9734ac1af054d6f Mon Sep 17 00:00:00 2001 From: Goodness Ezeokafor Date: Sun, 13 Oct 2019 20:58:21 +0100 Subject: [PATCH 7/7] Dev: Goodness Ezeokafor Date: 13th October 2019 Message: added unit test to the accounts views --- web/accounts/tests/test_views.py | 52 +++++++++++++++++++++++++++++--- 1 file changed, 48 insertions(+), 4 deletions(-) diff --git a/web/accounts/tests/test_views.py b/web/accounts/tests/test_views.py index b99a323..3c96692 100644 --- a/web/accounts/tests/test_views.py +++ b/web/accounts/tests/test_views.py @@ -69,14 +69,58 @@ def test_index_page_view_template(self): class ThanksViewTest(TestCase): - pass + def test_thanks_page_view_by_status_code(self): + response = self.client.get('/thank-you') + self.assertEquals(response.status_code, 200) + + def test_sponsorship_page_view_by_name(self): + response= self.client.get(reverse('thanks')) + self.assertEquals(response.status_code, 200) + + def test_index_page_view_template(self): + response= self.client.get(reverse('thanks')) + self.assertTemplateUsed(response, "accounts/sponsor-thanks.html") + class TicketPayCorporateViewTest(TestCase): - pass + def test_ticket_pay_corp_page_view_by_status_code(self): + response = self.client.get('/ticket-pay-corp') + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_corp_page_view_by_name(self): + response= self.client.get(reverse('ticket_pay_corporate')) + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_corp_page_view_template(self): + response= self.client.get(reverse('ticket_pay_corporate')) + self.assertTemplateUsed(response, "accounts/ticket_pay_corporate.html") + class TicketPayIndividualViewTest(TestCase): - pass + def test_ticket_pay_indeividual_page_view_by_status_code(self): + response = self.client.get('/ticket-pay-indiv') + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_indeividual_page_view_by_name(self): + response= self.client.get(reverse('ticket_pay_individual')) + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_indeividual_page_view_template(self): + response= self.client.get(reverse('ticket_pay_individual')) + self.assertTemplateUsed(response, "accounts/ticket_pay_individual.html") + class TicketPayStudentsViewTest(TestCase): - pass \ No newline at end of file + + def test_ticket_pay_student_page_view_by_status_code(self): + response = self.client.get('/ticket-pay-stud') + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_student_page_view_by_name(self): + response= self.client.get(reverse('ticket_pay_students')) + self.assertEquals(response.status_code, 200) + + def test_ticket_pay_student_page_view_template(self): + response= self.client.get(reverse('ticket_pay_students')) + self.assertTemplateUsed(response, "accounts/ticket_pay_students.html")