-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
207 additions
and
93 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[run] | ||
branch = True | ||
omit = *__init__.py,manage.py,*migrations*,*settings.py,*tests* |
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,31 @@ | ||
name: Django CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
strategy: | ||
max-parallel: 4 | ||
matrix: | ||
python-version: [3.8] | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Install Dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
pip install -r requirements.txt | ||
- name: Run Tests | ||
run: | | ||
python manage.py test | ||
This file was deleted.
Oops, something went wrong.
48 changes: 0 additions & 48 deletions
48
blogs/migrations/0002_alter_user_bio_alter_user_email_and_more.py
This file was deleted.
Oops, something went wrong.
Empty file.
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,13 @@ | ||
{ | ||
"model": "blogs.user", | ||
"pk": 1, | ||
"fields": { | ||
"first_name": "John", | ||
"last_name": "Smith", | ||
"username": "johnsmith", | ||
"email": "[email protected]", | ||
"bio": "Hello, I'm John Smith.", | ||
"password": "pbkdf2_sha256$260000$4BNvFuAWoTT1XVU8D6hCay$KqDCG+bHl8TwYcvA60SGhOMluAheVOnF1PMz0wClilc=" | ||
} | ||
} | ||
] |
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,38 @@ | ||
[ | ||
{ | ||
"model": "blogs.user", | ||
"pk": 2, | ||
"fields": { | ||
"first_name": "Jane", | ||
"last_name": "Doe", | ||
"username": "janedoe", | ||
"email": "[email protected]", | ||
"password": "pbkdf2_sha256$260000$iGkOGC00dvNVncr3rtGWdL$IkIyONd+R4mPoN4APRvVqk5tGVLa3xocSQ2qJur+VZo=", | ||
"bio": "Hi, my name is Jane." | ||
} | ||
}, | ||
{ | ||
"model": "blogs.user", | ||
"pk": 3, | ||
"fields": { | ||
"first_name": "Adam", | ||
"last_name": "Johnson", | ||
"username": "adamjohnson", | ||
"email": "[email protected]", | ||
"password": "pbkdf2_sha256$260000$iGkOGC00dvNVncr3rtGWdL$IkIyONd+R4mPoN4APRvVqk5tGVLa3xocSQ2qJur+VZo=", | ||
"bio": "Hello, my name is Adam." | ||
} | ||
}, | ||
{ | ||
"model": "blogs.user", | ||
"pk": 4, | ||
"fields": { | ||
"first_name": "James", | ||
"last_name": "Brown", | ||
"username": "jamesbrown", | ||
"email": "[email protected]", | ||
"password": "pbkdf2_sha256$260000$iGkOGC00dvNVncr3rtGWdL$IkIyONd+R4mPoN4APRvVqk5tGVLa3xocSQ2qJur+VZo=", | ||
"bio": "Hello, my name is James." | ||
} | ||
} | ||
] |
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,121 @@ | ||
"""Unit tests for the User model""" | ||
from django.core.exceptions import ValidationError | ||
from django.test import TestCase | ||
|
||
from blogs.models import User | ||
|
||
|
||
class UserModelTestCase(TestCase): | ||
"""Unit tests of the user model.""" | ||
|
||
fixtures = [ | ||
"blogs/tests/fixtures/default_user.json", | ||
"blogs/tests/fixtures/other_users.json", | ||
] | ||
|
||
def setUp(self): | ||
self.user = User.objects.get(username="johnsmith") | ||
|
||
def _assert_user_is_valid(self): | ||
try: | ||
self.user.full_clean() | ||
except ValidationError: | ||
self.fail("Test user should be valid") | ||
|
||
def _assert_user_is_invalid(self): | ||
with self.assertRaises(ValidationError): | ||
self.user.full_clean() | ||
|
||
def test_username_must_have_at_least_three_alphanumericals(self): | ||
"""Test username must have at least three alphanumericals.""" | ||
self.user.username = "ab" | ||
self._assert_user_is_invalid() | ||
|
||
def test_username_cannot_be_blank(self): | ||
"""Test username cannot be blank.""" | ||
self.user.username = "" | ||
self._assert_user_is_invalid() | ||
|
||
def test_username_can_be_30_characters_long(self): | ||
"""Test username can be 30 characters long.""" | ||
self.user.username = "x" * 30 | ||
self._assert_user_is_valid() | ||
|
||
def test_username_cannot_be_over_30_characters_long(self): | ||
"""Test username cannot be over 30 characters long.""" | ||
self.user.username = "x" * 31 | ||
self._assert_user_is_invalid() | ||
|
||
def test_username_must_be_unique(self): | ||
"""Test username must be unique.""" | ||
second_user = User.objects.get(username="janedoe") | ||
self.user.username = second_user.username | ||
self._assert_user_is_invalid() | ||
|
||
def test_username_has_numbers(self): | ||
"""Test username has numbers.""" | ||
self.user.username = "j0hnd03" | ||
self._assert_user_is_valid() | ||
|
||
def test_first_name_is_not_blank(self): | ||
"""Test first name must not be blank.""" | ||
self.user.first_name = "" | ||
self._assert_user_is_invalid() | ||
|
||
def test_first_name_is_not_unique(self): | ||
"""Test first name is not unique.""" | ||
second_user = User.objects.get(username="janedoe") | ||
self.user.first_name = second_user.first_name | ||
self._assert_user_is_valid() | ||
|
||
def test_first_name_can_have_less_than_50_characters(self): | ||
"""Test first name can have less than 50 characters.""" | ||
self.user.first_name = "x" * 50 | ||
self._assert_user_is_valid() | ||
|
||
def test_first_name_cannot_have_more_than_50_characters(self): | ||
"""Test first name cannot have more than 50 characters.""" | ||
self.user.first_name = "x" * 51 | ||
self._assert_user_is_invalid() | ||
|
||
def test_last_name_is_not_blank(self): | ||
"""Test last name is not blank.""" | ||
self.user.last_name = "" | ||
self._assert_user_is_invalid() | ||
|
||
def test_last_name_is_not_unique(self): | ||
"""Test last name is not unique.""" | ||
second_user = User.objects.get(username="janedoe") | ||
self.user.last_name = second_user.last_name | ||
self._assert_user_is_valid() | ||
|
||
def test_last_name_can_have_less_than_50_characters(self): | ||
"""Test last name can have less than 50 characters.""" | ||
self.user.last_name = "x" * 50 | ||
self._assert_user_is_valid() | ||
|
||
def test_last_name_cannot_have_more_than_50_characters(self): | ||
"""Test last name cannot have more than 50 characters.""" | ||
self.user.last_name = "x" * 51 | ||
self._assert_user_is_invalid() | ||
|
||
def test_bio_can_be_blank(self): | ||
"""Test bio can be blank.""" | ||
self.user.bio = "" | ||
self._assert_user_is_valid() | ||
|
||
def test_bio_may_not_be_unique(self): | ||
"""Test bio may not be unique.""" | ||
second_user = User.objects.get(username="janedoe") | ||
self.user.bio = second_user.bio | ||
self._assert_user_is_valid() | ||
|
||
def test_bio_may_have_520_chars(self): | ||
"""Test bio may have 520 characters.""" | ||
self.user.bio = "x" * 520 | ||
self._assert_user_is_valid() | ||
|
||
def test_bio_cannot_have_over_520_chars(self): | ||
"""Test bio cannot have over 520 characters.""" | ||
self.user.bio = "x" * 521 | ||
self._assert_user_is_invalid() |
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 |
---|---|---|
|
@@ -2,3 +2,4 @@ asgiref==3.5.2 | |
backports.zoneinfo==0.2.1 | ||
Django==4.1.3 | ||
sqlparse==0.4.3 | ||
coverage==6.5.0 |