adding APIKey method
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user