Merge ~andersson123/autopkgtest-cloud:unit_test_duplicate_request into autopkgtest-cloud:master

Proposed by Tim Andersson
Status: Merged
Merged at revision: 4269416b9c9362497dac9dd1ed987c2ef54227a4
Proposed branch: ~andersson123/autopkgtest-cloud:unit_test_duplicate_request
Merge into: autopkgtest-cloud:master
Diff against target: 64 lines (+45/-1)
1 file modified
charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py (+45/-1)
Reviewer Review Type Date Requested Status
Brian Murray Approve
Review via email: mp+451369@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brian Murray (brian-murray) wrote :

There is a docstring which says """Valid distro request is accepted""" however, that isn't the test that is actually being run. Additionally, I think we should add a test for that case as the tests being added check if it is already queued or already running but not the opposite of both.

review: Needs Fixing
Revision history for this message
Tim Andersson (andersson123) wrote :

:facepalm: ugh sorry about the docstring.

Makes sense re the additional test, I'll amend.

Revision history for this message
Tim Andersson (andersson123) wrote :

I've added an additional test but having a weird issue with it which I'd like to discuss in standup.

Revision history for this message
Brian Murray (brian-murray) wrote :

Looks great, thanks!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py b/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
2index 8d93d43..634d72d 100644
3--- a/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
4+++ b/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
5@@ -10,7 +10,11 @@ from unittest.mock import MagicMock, patch
6
7 import request.submit
8 from distro_info import UbuntuDistroInfo
9-from helpers.exceptions import WebControlException
10+from helpers.exceptions import (
11+ RequestInQueue,
12+ RequestRunning,
13+ WebControlException,
14+)
15
16
17 class SubmitTestBase(TestCase):
18@@ -438,6 +442,46 @@ class DistroRequestValidationTests(SubmitTestBase):
19 )
20 self.assertEqual(mock_urlopen.call_count, 6)
21
22+ @patch("request.submit.Submit.is_test_in_queue")
23+ def test_already_queued(self, mock_is_test_in_queue):
24+ """Test request is rejected if already queued"""
25+
26+ is_test_in_queue_cm = MagicMock()
27+ is_test_in_queue_cm.__enter__.return_value = is_test_in_queue_cm
28+ is_test_in_queue_cm.is_test_in_queue.side_effect = RequestInQueue(
29+ "testy", "blue", "C51", "ab/1.2"
30+ )
31+ mock_is_test_in_queue.return_value = is_test_in_queue_cm
32+
33+ with self.assertRaises(WebControlException) as cme:
34+ self.submit.validate_distro_request(
35+ "testy", "C51", "blue", ["ab/1.2"], "joe"
36+ )
37+ self.assertEqual(
38+ "Test already queued:\nrelease: testy\npkg: blue\narch: C51\ntriggers: ab/1.2",
39+ str(cme.exception),
40+ )
41+
42+ @patch("request.submit.Submit.is_test_running")
43+ def test_already_running(self, mock_is_test_running):
44+ """Test request is rejected if already running"""
45+
46+ is_test_running_cm = MagicMock()
47+ is_test_running_cm.__enter__.return_value = is_test_running_cm
48+ is_test_running_cm.is_test_running.side_effect = RequestRunning(
49+ "testy", "blue", "C51", "ab/1.2"
50+ )
51+ mock_is_test_running.return_value = is_test_running_cm
52+
53+ with self.assertRaises(WebControlException) as cme:
54+ self.submit.validate_distro_request(
55+ "testy", "C51", "blue", ["ab/1.2"], "joe"
56+ )
57+ self.assertEqual(
58+ "Test already running:\nrelease: testy\npkg: blue\narch: C51\ntriggers: ab/1.2",
59+ str(cme.exception),
60+ )
61+
62
63 class GitRequestValidationTests(SubmitTestBase):
64 """Test verification of git branch test requests"""

Subscribers

People subscribed via source and target branches