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
diff --git a/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py b/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
index 8d93d43..634d72d 100644
--- a/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
+++ b/charms/focal/autopkgtest-web/webcontrol/request/tests/test_submit.py
@@ -10,7 +10,11 @@ from unittest.mock import MagicMock, patch
1010
11import request.submit11import request.submit
12from distro_info import UbuntuDistroInfo12from distro_info import UbuntuDistroInfo
13from helpers.exceptions import WebControlException13from helpers.exceptions import (
14 RequestInQueue,
15 RequestRunning,
16 WebControlException,
17)
1418
1519
16class SubmitTestBase(TestCase):20class SubmitTestBase(TestCase):
@@ -438,6 +442,46 @@ class DistroRequestValidationTests(SubmitTestBase):
438 )442 )
439 self.assertEqual(mock_urlopen.call_count, 6)443 self.assertEqual(mock_urlopen.call_count, 6)
440444
445 @patch("request.submit.Submit.is_test_in_queue")
446 def test_already_queued(self, mock_is_test_in_queue):
447 """Test request is rejected if already queued"""
448
449 is_test_in_queue_cm = MagicMock()
450 is_test_in_queue_cm.__enter__.return_value = is_test_in_queue_cm
451 is_test_in_queue_cm.is_test_in_queue.side_effect = RequestInQueue(
452 "testy", "blue", "C51", "ab/1.2"
453 )
454 mock_is_test_in_queue.return_value = is_test_in_queue_cm
455
456 with self.assertRaises(WebControlException) as cme:
457 self.submit.validate_distro_request(
458 "testy", "C51", "blue", ["ab/1.2"], "joe"
459 )
460 self.assertEqual(
461 "Test already queued:\nrelease: testy\npkg: blue\narch: C51\ntriggers: ab/1.2",
462 str(cme.exception),
463 )
464
465 @patch("request.submit.Submit.is_test_running")
466 def test_already_running(self, mock_is_test_running):
467 """Test request is rejected if already running"""
468
469 is_test_running_cm = MagicMock()
470 is_test_running_cm.__enter__.return_value = is_test_running_cm
471 is_test_running_cm.is_test_running.side_effect = RequestRunning(
472 "testy", "blue", "C51", "ab/1.2"
473 )
474 mock_is_test_running.return_value = is_test_running_cm
475
476 with self.assertRaises(WebControlException) as cme:
477 self.submit.validate_distro_request(
478 "testy", "C51", "blue", ["ab/1.2"], "joe"
479 )
480 self.assertEqual(
481 "Test already running:\nrelease: testy\npkg: blue\narch: C51\ntriggers: ab/1.2",
482 str(cme.exception),
483 )
484
441485
442class GitRequestValidationTests(SubmitTestBase):486class GitRequestValidationTests(SubmitTestBase):
443 """Test verification of git branch test requests"""487 """Test verification of git branch test requests"""

Subscribers

People subscribed via source and target branches