Private
Public Access
1
0

Merge branch 'develop' into feature/stravaapi

This commit is contained in:
2024-12-06 10:43:04 +01:00
12 changed files with 474 additions and 57 deletions

View File

@@ -32,6 +32,8 @@ from bs4 import BeautifulSoup
from rowers.ownapistuff import *
from rowers.views.apiviews import *
from rowers.models import APIKey
from rowers.teams import add_member, add_coach
from rowers.views.analysisviews import histodata
@@ -476,9 +478,8 @@ class OwnApi(TestCase):
self.password = faker.word()
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)
@@ -642,6 +643,75 @@ class OwnApi(TestCase):
response = strokedata_tcx(request)
self.assertEqual(response.status_code,200)
def test_strokedataform_rowingdata(self):
url = reverse('strokedata_rowingdata')
filename = 'rowers/tests/testdata/testdata.csv'
f = open(filename, 'rb')
# Use Basic Auth header (alternative if using a custom view)
credentials = f"{self.u.username}:{self.password}"
base64_credentials = base64.b64encode(credentials.encode()).decode()
# Use Basic Auth header
headers = {
"HTTP_AUTHORIZATION": f"Basic {base64_credentials}"
}
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_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)
self.assertTrue(login)