Enhanced time synchronization for drf views.
added test to see if the should_update would use raise_exception config
1 file changed, +12 -0
+12-0timecheck/tests.py
| @@ -29,15 +29,18 @@ class TimeCheckTests(TestCase): | ||
| 29 | 29 | def test_get_client_is_older(self): |
| 30 | 30 | client_time = fmt_dt(self.earlier) |
| 31 | 31 | response = self.client.get("/", HTTP_LASTUPDATED=client_time) |
| 32 | + conf["raise_exception"] = True | |
| 32 | 33 | self.assertEqual(response.status_code, 200) |
| 33 | 34 | |
| 34 | 35 | def test_get_client_is_equal(self): |
| 35 | 36 | client_time = fmt_dt(self.now) |
| 36 | 37 | response = self.client.get("/", HTTP_LASTUPDATED=client_time) |
| 38 | + conf["raise_exception"] = True | |
| 37 | 39 | self.assertEqual(response.status_code, conf["noupdate_code"]) |
| 38 | 40 | |
| 39 | 41 | def test_put_client_is_newer(self): |
| 40 | 42 | client_time = fmt_dt(self.later) |
| 43 | + conf["raise_exception"] = True | |
| 41 | 44 | response = self.client.put( |
| 42 | 45 | "/", |
| 43 | 46 | { |
| @@ -50,15 +53,24 @@ class TimeCheckTests(TestCase): | ||
| 50 | 53 | |
| 51 | 54 | def test_put_client_is_older(self): |
| 52 | 55 | client_time = fmt_dt(self.earlier) |
| 56 | + conf["raise_exception"] = True | |
| 53 | 57 | response = self.client.put( |
| 54 | 58 | "/", |
| 55 | 59 | {"lastUpdated": client_time}, |
| 56 | 60 | format="json", |
| 57 | 61 | ) |
| 58 | 62 | self.assertEqual(response.status_code, conf["noupdate_code"]) |
| 63 | + conf["raise_exception"] = False | |
| 64 | + response = self.client.put( | |
| 65 | + "/", | |
| 66 | + {"lastUpdated": client_time}, | |
| 67 | + format="json", | |
| 68 | + ) | |
| 69 | + self.assertEqual(response.status_code, 200) | |
| 59 | 70 | |
| 60 | 71 | def test_put_client_is_equal(self): |
| 61 | 72 | client_time = fmt_dt(self.now) |
| 73 | + conf["raise_exception"] = True | |
| 62 | 74 | response = self.client.put( |
| 63 | 75 | "/", |
| 64 | 76 | {"lastUpdated": client_time}, |