Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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
52 changes: 51 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
# pyconng-2019
### PyconNg-2019

The official website for PyconNg-2019 visit <a herf='http://pycon.pythonnigeria.org/'> link </a>

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 [email protected]: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 <folder>
* cd into <folder>
* 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/<or any python-version>
* pipenv shell
* pipenv install


### Contribute
* fork the repo
* Clone it locally (git clone https://github.com/<username>/pyconng-2019.git)
* Add upstream repo (git remote add upstream https://github.com/<username>/pyconng-2019.git)
* Create a feature/topic branch (`git checkout -b <branch_name>)
* 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 <branch_name>)
* Rebase your changes onto the latest changes in master (git rebase master)
* Push your fix/feature branch to your fork (git push upstream <branch_name>)




Thanks alot, happy coding &#128526;
3 changes: 3 additions & 0 deletions web/accounts/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 0 additions & 3 deletions web/accounts/tests.py

This file was deleted.

Empty file added web/accounts/tests/__init__.py
Empty file.
107 changes: 107 additions & 0 deletions web/accounts/tests/test_forms.py
Original file line number Diff line number Diff line change
@@ -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':'[email protected]'
}
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':'[email protected]'
}
form = SignUpForm(data=data)
self.assertFalse(form.is_valid())
96 changes: 96 additions & 0 deletions web/accounts/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -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)









126 changes: 126 additions & 0 deletions web/accounts/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -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")