Example #1
0
 def test_that_unsupported_precheck_works_on_requests_errors(self, fake_get):
     fake_get.side_effect = requests.exceptions.RequestException
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     unsupported_precheck(force=True)
     sys.stdout = sys.__stdout__
     self.assertNotIn("New version of SwagLyrics available:", capturedOutput.getvalue())
     self.assertIn("Could not update unsupported.txt successfully.", capturedOutput.getvalue())
Example #2
0
 def test_that_unsupported_precheck_updates_after_a_day(self, fake_get):
     fake_get.side_effect = requests.exceptions.RequestException
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     with open(unsupported_txt, 'w') as f:
         f.write(str(time.time() - 86500))  # more than a day
     unsupported_precheck()
     sys.stdout = sys.__stdout__
     self.assertTrue(fake_get.called)
     self.assertIn("Could not update unsupported.txt successfully.", capturedOutput.getvalue())
Example #3
0
 def test_that_unsupported_precheck_works_on_permission_error(self, fake_get):
     fake_get.side_effect = [R(200, '0.2.6'), PermissionError]
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     with self.assertRaises(SystemExit) as se:
         unsupported_precheck(force=True)
     sys.stdout = sys.__stdout__
     self.assertEqual(se.exception.code, 1)
     self.assertNotIn("New version of SwagLyrics available:", capturedOutput.getvalue())
     self.assertIn("You should install SwagLyrics as --user or use sudo to access unsupported.txt.",
                   capturedOutput.getvalue())
Example #4
0
 def test_that_unsupported_precheck_initial_check_handles_permission_error(self, f_time):
     # we use time to raise PermissionError although irl it will be raised by file i/o
     f_time.side_effect = PermissionError
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     with self.assertRaises(SystemExit) as se:
         unsupported_precheck()
     sys.stdout = sys.__stdout__
     self.assertEqual(se.exception.code, 1)
     self.assertIn("You should install SwagLyrics as --user or use sudo to access unsupported.txt.",
                   capturedOutput.getvalue())
Example #5
0
 def test_unsupported_precheck_handles_value_error(self, fake_get):
     """
     checks ValueError raised when first line isn't a float gets handled.
     """
     with open(unsupported_txt, 'w') as f:
         f.write('random string')  # not a float
     fake_get.side_effect = requests.exceptions.RequestException
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     unsupported_precheck()
     self.assertNotIn("New version of SwagLyrics available:", capturedOutput.getvalue())
     self.assertIn("Could not update unsupported.txt successfully.", capturedOutput.getvalue())
 def test_that_unsupported_precheck_works_normally(self, fake_get):
     fake_txt = 'unsupported txt test'
     fake_get.side_effect = [R(200, '0.2.9'), R(200, fake_txt)]
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     unsupported_precheck()
     sys.stdout = sys.__stdout__
     self.assertIn(
         "New version of SwagLyrics available: v0.2.9\nPlease update :)",
         capturedOutput.getvalue())
     self.assertIn("Updated unsupported.txt successfully.",
                   capturedOutput.getvalue())
     data = unsupported_txt_data()
     self.assertEqual(data, fake_txt)
Example #7
0
 def test_that_unsupported_precheck_works_normally(self, fake_get):
     fake_txt = 'unsupported txt test'
     fake_get.side_effect = [R(200, '0.2.9'), R(200, fake_txt)]
     capturedOutput = io.StringIO()
     sys.stdout = capturedOutput
     unsupported_precheck(force=True)
     update_time = time.time()  # get current time to compare with update time from the function
     sys.stdout = sys.__stdout__
     self.assertIn("New version of SwagLyrics available: v0.2.9\nPlease update :)", capturedOutput.getvalue())
     self.assertIn("Updated unsupported.txt successfully.", capturedOutput.getvalue())
     data = unsupported_txt_data().splitlines()
     time_from_txt = float(data[0])  # get actual updation time from file
     test_txt = data[1]
     self.assertEqual(test_txt, fake_txt)
     self.assertAlmostEqual(update_time, time_from_txt, delta=1)  # allow 1s mismatch
Example #8
0
 def test_that_unsupported_precheck_does_not_update_under_a_day(self):
     with open(unsupported_txt, 'w') as f:
         f.write(str(time.time()))
     val = unsupported_precheck()
     self.assertIsNone(val)