-
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.
* init * First test on item anon read * testing
- Loading branch information
Showing
8 changed files
with
122 additions
and
8 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 |
---|---|---|
@@ -1,7 +1,5 @@ | ||
{ | ||
"python.testing.pytestArgs": [ | ||
"tests" | ||
], | ||
"python.testing.pytestArgs": [], | ||
"python.testing.unittestEnabled": false, | ||
"python.testing.pytestEnabled": true | ||
} |
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,44 @@ | ||
# Generated by Django 5.0.3 on 2024-04-28 11:57 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("share_app", "0003_alter_location_unique_together"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Item", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("description", models.CharField(max_length=164)), | ||
("header", models.CharField(max_length=32)), | ||
( | ||
"category", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="share_app.category", | ||
), | ||
), | ||
( | ||
"location", | ||
models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
to="share_app.location", | ||
), | ||
), | ||
], | ||
), | ||
] |
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,52 @@ | ||
import pytest | ||
import random | ||
|
||
from django.urls import include, path, reverse | ||
from rest_framework.test import APITestCase, URLPatternsTestCase | ||
from rest_framework import status | ||
|
||
from share_app.models import Item, Category, Location | ||
from conftest import Clients | ||
|
||
class ItemTests(APITestCase, URLPatternsTestCase, Clients): | ||
urlpatterns = [ | ||
path('', include('share.urls')), | ||
] | ||
|
||
def setUp(self): | ||
# Set up data for the whole TestCase | ||
self.location = Location.objects.create(city="Hamburg", post_code="22525") | ||
self.category = Category.objects.create(name="Test2") | ||
self.item = Item.objects.create( | ||
description="An awesome thing to share", | ||
header="This is short", | ||
category = self.category, | ||
location = self.location | ||
) | ||
|
||
def test_anon_read(self): | ||
""" | ||
Ensure we can create a new account object. | ||
""" | ||
url = reverse('items-list') | ||
response = self.client.get(url, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(len(response.data), 1) | ||
url = reverse('items-detail', args=[1]) | ||
response = self.client.get(url, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_200_OK) | ||
self.assertEqual(response.data["header"], "This is short") | ||
|
||
def test_annon_no_write(self): | ||
''' | ||
Ensure that we can only announce new stuff if we dare known | ||
''' | ||
url = reverse('items-list') | ||
data = {'city': 'Hamburg', 'post_code': 13371} | ||
response = self.client.post(url,data, format='json') | ||
self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) | ||
self.assertEqual(len(response.data), 1) | ||
|
||
def test_user_create(self): | ||
# Include an appropriate `Authorization:` header on all requests. | ||
pass |
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