-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
12 changed files
with
155 additions
and
141 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from django.core.management import call_command | ||
from rest_framework.test import APITestCase | ||
|
||
from .client import BaseClient | ||
from character.factories import PlayerFactory | ||
from character.models import Player | ||
|
||
|
||
class BaseTestCase(APITestCase): | ||
|
||
def setUp(self): | ||
call_command('socialapps') | ||
self.client = BaseClient() | ||
self.player = PlayerFactory.create() | ||
|
||
def tearDown(self): | ||
self.client = None | ||
Player.objects.all().delete() | ||
|
||
def test_authenticate(self): | ||
pwd = 'qweqweqwe' | ||
response = self.client.authenticate(self.player.user.username, pwd) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertNotEqual(self.client.auth_token, '') | ||
self.assertEqual( | ||
sorted(list(response.json().keys())), | ||
sorted(['access_token', 'expires_in', 'refresh_token', 'scope', | ||
'token_type']), | ||
) | ||
|
||
def test_logout_without_login(self): | ||
response = self.client.logout() | ||
self.assertEqual(response.status_code, 400) | ||
self.assertEqual( | ||
response.json(), | ||
{ | ||
'error': 'invalid_request', | ||
'error_description': 'Missing token parameter.' | ||
} | ||
) | ||
|
||
def test_logout(self): | ||
pwd = 'qweqweqwe' | ||
self.client.authenticate(self.player.user.username, pwd) | ||
response = self.client.logout() | ||
self.assertEqual(response.status_code, 204) | ||
self.assertEqual(self.client.auth_token, '') |
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 |
---|---|---|
@@ -1,22 +1,20 @@ | ||
from django.conf import settings | ||
from urllib.parse import urlencode | ||
from django.contrib.auth.models import User | ||
from django.core.management import call_command | ||
from rest_framework.test import APITestCase | ||
from urllib.parse import urlencode | ||
|
||
from base.client import BaseClient | ||
from .factories import NPCFactory | ||
from .models import NPC | ||
from .factories import NPCFactory, PlayerFactory | ||
from .models import NPC, Player | ||
from .serializers import NPCSerializer | ||
|
||
|
||
class NPCTestCase(APITestCase): | ||
|
||
def setUp(self): | ||
self.user = User.objects.create_superuser(username='[email protected]', | ||
password='qweqweqwe', email='[email protected]') | ||
self.player = PlayerFactory.create() | ||
call_command('socialapps') | ||
self.client = BaseClient(version=settings.VERSION) | ||
self.client = BaseClient() | ||
self.npc = NPCFactory.create() | ||
self.data = { | ||
'user': { | ||
|
@@ -27,10 +25,11 @@ def setUp(self): | |
|
||
def tearDown(self): | ||
self.client = None | ||
Player.objects.all().delete() | ||
NPC.objects.all().delete() | ||
|
||
def authenticate(self, username='[email protected]', pwd='qweqweqwe'): | ||
response = self.client.authenticate(username, pwd) | ||
self.assertEqual(response.status_code, 200) | ||
def authenticate(self, pwd='qweqweqwe'): | ||
self.client.authenticate(self.player.user.username, pwd) | ||
|
||
# CREATE | ||
def character_create(self, ctype, data, st): | ||
|
@@ -54,7 +53,7 @@ def test_npc_create_bad_request(self): | |
def test_npc_create_exist(self): | ||
self.authenticate() | ||
data = {'user': { | ||
'email': self.user.email, | ||
'email': self.player.user.email, | ||
'password': 'qweqweqwe' | ||
}} | ||
self.character_create('npc', data, 400) | ||
|
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 |
---|---|---|
@@ -1,5 +1,3 @@ | ||
from django.conf import settings | ||
from django.contrib.auth.models import User | ||
from django.contrib.contenttypes.models import ContentType | ||
from django.contrib.gis.geos import Point | ||
from django.core.management import call_command | ||
|
@@ -27,11 +25,8 @@ | |
class ContentTestCase(APITestCase): | ||
|
||
def setUp(self): | ||
User.objects.create_superuser(username='[email protected]', | ||
password='qweqweqwe', | ||
email='[email protected]') | ||
call_command('socialapps') | ||
self.client = BaseClient(version=settings.VERSION) | ||
self.client = BaseClient() | ||
self.player = PlayerFactory.create() | ||
self.game = GameFactory.create() | ||
self.owner = Owner(player=self.player, game=self.game) | ||
|
@@ -82,23 +77,22 @@ def tearDown(self): | |
Knowledge.objects.all().delete() | ||
Rol.objects.all().delete() | ||
|
||
def authenticate(self, username='[email protected]', pwd='qweqweqwe'): | ||
response = self.client.authenticate(username, pwd) | ||
self.assertEqual(response.status_code, 200) | ||
def authenticate(self, pwd='qweqweqwe'): | ||
self.client.authenticate(self.player.user.username, pwd) | ||
|
||
# LIST | ||
def test_list_content_unauth(self): | ||
response = self.client.get('/content/') | ||
self.assertEqual(response.status_code, 401) | ||
|
||
def test_list_content(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.get('/content/') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 5) | ||
|
||
def test_list_content_filter_game(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.get('/content/?game_id={}'.format(self.game.pk)) | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 5) | ||
|
@@ -109,7 +103,7 @@ def test_list_content_filter_game(self): | |
|
||
def test_list_content_filter_bad(self): | ||
""" If you use bad query params, return none """ | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.get('/content/?game_id=str') | ||
self.assertEqual(response.status_code, 200) | ||
self.assertEqual(len(response.json()), 0) | ||
|
@@ -127,7 +121,7 @@ def test_create_content_unauth(self): | |
self.assertEqual(response.status_code, 401) | ||
|
||
def test_create_content_bad_request(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
self.data_mode1['content_type'] = 'bad' | ||
response = self.client.post('/content/', self.data_mode1) | ||
self.assertEqual(response.status_code, 400) | ||
|
@@ -137,7 +131,7 @@ def test_create_content_bad_request(self): | |
self.assertEqual(response.status_code, 400) | ||
|
||
def test_create_content(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.post('/content/', self.data_mode1) | ||
self.assertEqual(response.status_code, 201) | ||
|
||
|
@@ -149,13 +143,13 @@ def test_destroy_content_unauth(self): | |
response = self.client.delete('/content/{}/'.format(self.contentItem.pk)) | ||
self.assertEqual(response.status_code, 401) | ||
|
||
self.owner.delete() | ||
self.authenticate(username=self.player.user.username) | ||
player = PlayerFactory.create() | ||
self.client.authenticate(player.user.username, 'qweqweqwe') | ||
response = self.client.delete('/content/{}/'.format(self.contentItem.pk)) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
def test_destroy_content(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.delete('/content/{}/'.format(self.contentItem.pk)) | ||
self.assertEqual(response.status_code, 204) | ||
|
||
|
@@ -172,7 +166,7 @@ def test_update_content_unauth(self): | |
self.assertEqual(response.status_code, 401) | ||
|
||
def test_update_content_bad_request(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
data = { | ||
"portion": { | ||
"longitude": 36.261421, | ||
|
@@ -189,8 +183,8 @@ def test_update_content_bad_request(self): | |
self.assertEqual(response.status_code, 400) | ||
|
||
def test_update_content(self): | ||
self.authenticate(username=self.player.user.username) | ||
data = ContentSerializer(self.contentNPC).data | ||
self.authenticate() | ||
data.update({ | ||
"position": { | ||
"longitude": 36.261421, | ||
|
@@ -218,7 +212,7 @@ def test_update_content(self): | |
|
||
# RETRIEVE | ||
def test_get_content_unexist_pk(self): | ||
self.authenticate(username=self.player.user.username) | ||
self.authenticate() | ||
response = self.client.get('/content/{}/'.format(0)) | ||
self.assertEqual(response.status_code, 404) | ||
|
||
|
@@ -227,9 +221,9 @@ def test_get_content_unauth(self): | |
self.assertEqual(response.status_code, 401) | ||
|
||
def test_get_content(self): | ||
self.authenticate(username=self.player.user.username) | ||
contents = [self.contentPlayer, self.contentNPC, self.contentItem, | ||
self.contentKnowledge, self.contentRol] | ||
self.authenticate() | ||
for content in contents: | ||
response = self.client.get('/content/{}/'.format(content.pk)) | ||
self.assertEqual(response.status_code, 200) | ||
|
Oops, something went wrong.