Private
Public Access
1
0

adding APIKey method

This commit is contained in:
2024-11-26 14:49:26 +01:00
parent 68a3ad8bcd
commit 5968d2a0e2
9 changed files with 174 additions and 3 deletions

View File

@@ -26,6 +26,7 @@ import json
from rowers.ownapistuff import *
from rowers.views.apiviews import *
from rowers.models import APIKey
class OwnApi(TestCase):
def setUp(self):
@@ -45,7 +46,7 @@ class OwnApi(TestCase):
self.u.set_password(self.password)
self.u.save()
self.factory = APIRequestFactory()
self.apikey = APIKey.objects.create(user=self.u)
def test_strokedataform(self):
login = self.c.login(username=self.u.username, password=self.password)
@@ -245,6 +246,38 @@ class OwnApi(TestCase):
self.assertEqual(response.status_code, 201)
def test_strokedataform_rowingdata_apikey(self):
url = reverse('strokedata_rowingdata_apikey')
filename = 'rowers/tests/testdata/testdata.csv'
f = open(filename, 'rb')
# Use API Key header
headers = {
"HTTP_AUTHORIZATION": self.apikey.key,
}
form_data = {
"workouttype": "rower",
"boattype": "1x",
"notes": "A test file upload",
}
# Send POST request
response = self.client.post(
url,
{"file": f, **form_data},
format="multipart", # Ensure multipart/form-data is used
**headers, # Optional if login doesn't suffice
)
f.close()
# Assertions
self.assertEqual(response.status_code, 201)
def test_strokedataform_empty(self):
login = self.c.login(username=self.u.username, password=self.password)