-
Notifications
You must be signed in to change notification settings - Fork 2
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
15 changed files
with
513 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Generated by Django 2.1.7 on 2019-07-09 18:49 | ||
|
||
import api.models | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0003_auto_20190607_1921'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='project', | ||
name='project_photo', | ||
field=models.ImageField(blank=True, null=True, upload_to=api.models.project_directory_path), | ||
), | ||
] |
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,14 @@ | ||
# Generated by Django 2.1.7 on 2019-07-10 20:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('api', '0004_auto_20190710_0859'), | ||
('api', '0004_auto_20190709_1849'), | ||
] | ||
|
||
operations = [ | ||
] |
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,172 @@ | ||
import json | ||
|
||
from rest_framework.test import APITestCase | ||
|
||
from users.models import CustomUser | ||
|
||
from api.models import * | ||
from api.serializers import * | ||
|
||
|
||
class AuthBaseTestCase(APITestCase): | ||
email = "@testuser.com" | ||
password = "12345Hola" | ||
|
||
def setUp(self): | ||
self.user = CustomUser.objects.create_user('user', 'user'+self.email, self.password) | ||
self.jefe = CustomUser.objects.create_user('jefe', 'jefe'+self.email, self.password) | ||
self.emp1 = CustomUser.objects.create_user('emp1', 'emp1'+self.email, self.password) | ||
self.emp2 = CustomUser.objects.create_user('emp2', 'emp2'+self.email, self.password) | ||
self.client.login(username='jefe', password=self.password) | ||
|
||
|
||
|
||
class ProjectTestCase(AuthBaseTestCase): | ||
url = '/api/v1/projects' | ||
|
||
def setUp(self): | ||
super().setUp() # Authenticanting | ||
self.data = { | ||
"title": "black mesa", | ||
"description": "particle accelerator", | ||
"creator": self.jefe, | ||
} | ||
self.project = Project.objects.create(**self.data) | ||
self.data['creator'] = self.jefe.id | ||
|
||
|
||
def test_read_project_get(self): | ||
""" | ||
Test to verify GET project valid (Model and Serializer) | ||
""" | ||
response = self.client.get(self.url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
response_data = json.loads(response.content)['results'] | ||
project = Project.objects.get(title="black mesa") | ||
projectSerial = ProjectSerializer(instance=project) | ||
self.assertEqual(projectSerial.data, response_data[0]) | ||
|
||
|
||
def test_read_project_get_by_another_user(self): | ||
""" | ||
Test to verify GET project by a different user | ||
""" | ||
self.client.logout() | ||
self.client.login(username='user', password=self.password) | ||
url = self.url+'/{id}'.format(id=self.project.id) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
# the project doesn't belong to the user | ||
self.assertEqual(404, response.status_code) # Not found | ||
|
||
|
||
def test_create_project_post(self): | ||
""" | ||
Test to verify POST project valid | ||
""" | ||
self.data['title'] = 'black mesa 2' | ||
response = self.client.post(self.url, self.data) | ||
print(response.status_code, response.content) | ||
self.assertEqual(201, response.status_code) | ||
|
||
response = self.client.get(self.url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
response_data = json.loads(response.content) | ||
self.assertEqual(2, response_data['count']) # 2 projects | ||
|
||
|
||
def test_delete_project_delete(self): | ||
""" | ||
Test to verify DELETE project valid | ||
""" | ||
url = self.url+'/{id}'.format(id=self.project.id) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
|
||
response = self.client.delete(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(204, response.status_code) | ||
self.assertEqual(b'', response.content) | ||
|
||
|
||
def test_update_project_patch(self): | ||
""" | ||
Test to verify PATCH project valid | ||
""" | ||
data = {'title': 'Black Mesa.'} | ||
url = self.url+'/{id}'.format(id=self.project.id) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
|
||
response = self.client.patch(url, data) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
response_data = json.loads(response.content) | ||
print(response_data) | ||
self.assertEqual(data['title'], response_data['title']) # updated | ||
|
||
|
||
def test_update_project_put(self): | ||
""" | ||
Test to verify PUT project valid | ||
""" | ||
data = dict(self.data) # copy | ||
data['title'] = 'black mesa 1' | ||
url = self.url+'/{id}'.format(id=self.project.id) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
|
||
response = self.client.put(url, data) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
response_data = json.loads(response.content) | ||
print(response_data) | ||
self.assertEqual(data['title'], response_data['title']) # updated | ||
|
||
|
||
def test_update_project_put_invalid_incomplete(self): | ||
""" | ||
Test to verify PUT project invalid(incomplete) | ||
""" | ||
data = { | ||
"title": "black mesa 1", | ||
"creator": self.jefe.id, | ||
} | ||
url = self.url+'/{id}'.format(id=self.project.id) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(200, response.status_code) | ||
|
||
response = self.client.put(url, data) | ||
print(response.status_code, response.content) | ||
self.assertEqual(400, response.status_code) | ||
response_data = json.loads(response.content) | ||
print(response_data) | ||
self.assertTrue("description" in response_data) | ||
|
||
|
||
def test_update_project_put_invalid_inexistent(self): | ||
""" | ||
Test to verify PUT project invalid(inexistent) | ||
""" | ||
data = { | ||
"title": "black mesa 9", | ||
"description": "particle accelerator", | ||
"creator": self.jefe.id, | ||
} | ||
url = self.url+'/{id}'.format(id=self.project.id+9) | ||
response = self.client.get(url) | ||
print(response.status_code, response.content) | ||
self.assertEqual(404, response.status_code) | ||
|
||
response = self.client.put(url, data) | ||
print(response.status_code, response.content) | ||
self.assertEqual(404, response.status_code) | ||
response_data = json.loads(response.content) | ||
print(response_data) | ||
self.assertTrue("detail" in response_data) |
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,19 @@ | ||
# Generated by Django 2.1.7 on 2019-07-04 14:33 | ||
|
||
from django.db import migrations, models | ||
import users.models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0001_initial'), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name='customuser', | ||
name='profile_photo', | ||
field=models.ImageField(blank=True, null=True, upload_to=users.models.user_directory_path), | ||
), | ||
] |
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,14 @@ | ||
# Generated by Django 2.1.7 on 2019-07-10 20:04 | ||
|
||
from django.db import migrations | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('users', '0002_auto_20190710_0859'), | ||
('users', '0002_auto_20190704_1433'), | ||
] | ||
|
||
operations = [ | ||
] |
Oops, something went wrong.