forked from getpatchwork/patchwork
-
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.
tests: Add tests for linking series feature
Closes getpatchwork#506 Signed-off-by: andrepapoti <[email protected]>
- Loading branch information
1 parent
a46a465
commit 27739c8
Showing
2 changed files
with
95 additions
and
0 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 |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
# Copyright (C) 2018 Stephen Finucane <[email protected]> | ||
# | ||
# SPDX-License-Identifier: GPL-2.0-or-later | ||
import json | ||
|
||
from django.test import override_settings | ||
from django.urls import NoReverseMatch | ||
|
@@ -203,3 +204,49 @@ def test_create_update_delete(self): | |
|
||
resp = self.client.delete(self.api_url(series.id)) | ||
self.assertEqual(status.HTTP_405_METHOD_NOT_ALLOWED, resp.status_code) | ||
|
||
def test_series_linking(self): | ||
series_a = self._create_series() | ||
series_b = create_series( | ||
project=series_a.project, submitter=series_a.submitter | ||
) | ||
series_c = create_series( | ||
project=series_a.project, submitter=series_a.submitter | ||
) | ||
series_d = create_series(submitter=series_a.submitter) | ||
|
||
self.client.authenticate(user=series_a.submitter.user) | ||
|
||
url = reverse( | ||
'api-series-link', | ||
kwargs={'pk': series_a.id, 'related_series_id': series_b.id}, | ||
) | ||
resp = self.client.patch(url) | ||
related_series = json.loads(resp.content).get('related_series') | ||
self.assertEqual(len(related_series), 1) | ||
self.assertEqual( | ||
related_series[0]['web_url'], | ||
f'http://example.com/project/myproject/list/?series={series_b.id}', | ||
) | ||
|
||
url = reverse( | ||
'api-series-link', | ||
kwargs={'pk': series_a.id, 'related_series_id': series_c.id}, | ||
) | ||
resp = self.client.patch(url) | ||
related_series = json.loads(resp.content).get('related_series') | ||
self.assertEqual(len(related_series), 2) | ||
self.assertEqual( | ||
related_series[1]['web_url'], | ||
f'http://example.com/project/myproject/list/?series={series_c.id}', | ||
) | ||
|
||
url = reverse( | ||
'api-series-link', | ||
kwargs={'pk': series_a.id, 'related_series_id': series_d.id}, | ||
) | ||
resp = self.client.patch(url) | ||
self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST) | ||
self.assertEqual(len(related_series), 2) | ||
|
||
print(series_a.related_series.all()) |
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