mirror of
https://github.com/TandoorRecipes/recipes.git
synced 2026-01-07 15:18:20 -05:00
tests basically working
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import copy
|
||||||
import inspect
|
import inspect
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
@@ -8,6 +9,11 @@ from django_scopes import scopes_disabled
|
|||||||
from cookbook.models import Space
|
from cookbook.models import Space
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture(autouse=True)
|
||||||
|
def enable_db_access_for_all_tests(db):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def test_password():
|
def test_password():
|
||||||
return 'strong-test-pass'
|
return 'strong-test-pass'
|
||||||
@@ -25,34 +31,38 @@ def create_user(db, django_user_model, test_password):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def space_1(client):
|
def space_1():
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
return Space.objects.get_or_create(name='space_1')[0]
|
return Space.objects.get_or_create(name='space_1')[0]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def space_2(client):
|
def space_2():
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
return Space.objects.get_or_create(name='space_2')[0]
|
return Space.objects.get_or_create(name='space_2')[0]
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_1(client, space_1):
|
def user_1(client, space_1):
|
||||||
|
c = copy.deepcopy(client)
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
|
print(f'creating user 1 with space {space_1}')
|
||||||
user = User.objects.create(username='user_1')
|
user = User.objects.create(username='user_1')
|
||||||
user.groups.add(Group.objects.get(name='user'))
|
user.groups.add(Group.objects.get(name='user'))
|
||||||
user.userpreference.space = space_1
|
user.userpreference.space = space_1
|
||||||
user.userpreference.save()
|
user.userpreference.save()
|
||||||
client.force_login(user)
|
c.force_login(user)
|
||||||
return client
|
return c
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def user_2(client, space_2):
|
def user_2(client, space_2):
|
||||||
|
c = copy.deepcopy(client)
|
||||||
with scopes_disabled():
|
with scopes_disabled():
|
||||||
|
print(f'creating user 2 with space {space_2}')
|
||||||
user = User.objects.create(username='user_2')
|
user = User.objects.create(username='user_2')
|
||||||
user.groups.add(Group.objects.get(name='user'))
|
user.groups.add(Group.objects.get(name='user'))
|
||||||
user.userpreference.space = space_2
|
user.userpreference.space = space_2
|
||||||
user.userpreference.save()
|
user.userpreference.save()
|
||||||
client.force_login(user)
|
c.force_login(user)
|
||||||
return client
|
return c
|
||||||
|
|||||||
@@ -10,11 +10,16 @@ from cookbook.models import Keyword, Space
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.django_db
|
@pytest.mark.django_db
|
||||||
def test_user_create(user_1, user_2):
|
def test_user_create(user_2, user_1):
|
||||||
r = user_1.post(reverse('api:keyword-list'), {'name': 'test', 'space': 1}, content_type='application/json')
|
r = user_1.post(reverse('api:keyword-list'), {'name': 'test', 'space': 1}, content_type='application/json')
|
||||||
response = json.loads(r.content)
|
response = json.loads(r.content)
|
||||||
assert r.status_code == 201
|
assert r.status_code == 201
|
||||||
assert response['name'] == 'test'
|
assert response['name'] == 'test'
|
||||||
|
|
||||||
|
print('DEEEEEBUUUUUGGGG')
|
||||||
|
print(user_1.get(reverse('view_test')).content)
|
||||||
|
print(user_2.get(reverse('view_test')).content)
|
||||||
|
print(user_2)
|
||||||
|
|
||||||
r = user_2.get(reverse('api:keyword-detail', args={response['id']}), content_type='application/json')
|
r = user_2.get(reverse('api:keyword-detail', args={response['id']}), content_type='application/json')
|
||||||
assert r.status_code == 404
|
assert r.status_code == 404
|
||||||
|
|||||||
Reference in New Issue
Block a user