class ObservationDeleteTest(TestCase): """ Test to ensure the observation list is generated by Django """ client = Client() user = None observation = None satellites = [] transmitters = [] def setUp(self): self.user = UserFactory() self.client.force_login(self.user) for x in xrange(1, 10): self.satellites.append(SatelliteFactory()) for x in xrange(1, 10): self.transmitters.append(TransmitterFactory()) self.observation = ObservationFactory() self.observation.author = self.user # observations in progress cannot be deleted self.observation.start = datetime.now() + timedelta( minutes=(2 * int(settings.OBSERVATION_MAX_DELETION_RANGE))) self.observation.end = datetime.now() - timedelta( minutes=(2 * int(settings.OBSERVATION_MIN_DELETION_RANGE))) self.observation.save() def test_observation_delete_author(self): """Deletion OK when user is the author of the observation""" response = self.client.get('/observations/%d/delete/' % self.observation.id) self.assertRedirects(response, '/observations/') response = self.client.get('/observations/') with self.assertRaises(Observation.DoesNotExist): _lookup = Observation.objects.get( pk=self.observation.id) # noqa:F841 def test_observation_delete_staff(self): """Deletion OK when user is staff and there is no data""" self.user = UserFactory() self.user.user_permissions.add( Permission.objects.get(codename='delete_observation')) self.user.save() self.client.force_login(self.user) response = self.client.get('/observations/%d/delete/' % self.observation.id) self.assertRedirects(response, '/observations/') response = self.client.get('/observations/') with self.assertRaises(Observation.DoesNotExist): _lookup = Observation.objects.get( pk=self.observation.id) # noqa:F841
class SettingsSiteViewTest(TestCase): """ Test to ensure the satellite fetch feature works """ client = Client() user = None def setUp(self): self.user = UserFactory() self.user.is_superuser = True self.user.save() self.client.force_login(self.user) def test_get(self): response = self.client.get('/settings_site/') self.assertContains(response, 'Fetch Data')
class SettingsSiteViewTest(TestCase): """ Test to ensure the satellite fetch feature works """ client = Client() user = None def setUp(self): self.user = UserFactory() self.user.is_superuser = True self.user.save() self.client.force_login(self.user) def test_get(self): response = self.client.get('/settings_site/') self.assertContains(response, 'Fetch Data') @patch('urllib2.urlopen', Mock()) def test_post(self): response = self.client.post('/settings_site/', {'fetch': True}) self.assertRedirects(response, '/settings_site/')