diff --git a/README.md b/README.md index d20bc84..7a60d07 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 😎 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..380113e --- /dev/null +++ b/web/accounts/tests/test_forms.py @@ -0,0 +1,107 @@ +from django.test import TestCase +from accounts.forms import SignUpForm +from accounts.models import Profile + + +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') + + 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') + + + # 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_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..3c96692 --- /dev/null +++ b/web/accounts/tests/test_views.py @@ -0,0 +1,126 @@ +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 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 ThanksViewTest(TestCase): + 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): + 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): + 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): + + 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")