def test_fetched_controlled_circuit_unauthenticated(self):
        create_circuit(name='c1')

        request = self.factory.get(self.url, format='json')
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED)
    def test_fetch_many_circuits_activations_not_for_today(self):
        c1 = create_circuit(name='c1')
        c1.collaborators.add(self.user)
        c2 = create_circuit(name='c2')
        c2.collaborators.add(self.user)
        create_circuit(name='c3')

        today = datetime.datetime.now(tz=pytz.UTC)
        tomorrow = today + datetime.timedelta(days=1)
        yesterday = today - +datetime.timedelta(days=1)

        create_scheduled_one_time_activation(c1, timestamp=tomorrow)
        create_scheduled_one_time_activation(c1, timestamp=yesterday)

        request = self.factory.get(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(2, len(response.data))
        self.assertIsNone(response.data[0].get('one_time_activation'))
        self.assertListEqual([], response.data[0].get('schedule'))
        self.assertIsNone(response.data[1].get('one_time_activation'))
        self.assertListEqual([], response.data[1].get('schedule'))

        self.assertCircuitEqual(response.data[0], c1)
        self.assertCircuitEqual(response.data[1], c2)
    def test_fetched_controlled_circuit_no_circuit_assigned(self):
        create_circuit(name='c1')

        request = self.factory.get(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
 def setUp(self):
     self.user = create_user()
     self.circuit = create_circuit(name='c1')
     self.circuit.collaborators.add(self.user)
     self.circuit_not_related = create_circuit(name='c2')
     self.view = CircuitViewSet.as_view(actions={
         'get': 'retrieve'
     })
     self.factory = APIRequestFactory()
     self.url = reverse('circuit-detail', kwargs={'pk': self.circuit.pk})
    def test_fetch_many_circuits_no_related(self):
        c1 = create_circuit(name='c1')
        create_circuit(name='c2')
        create_circuit(name='c3')

        create_scheduled_one_time_activation(c1)
        create_scheduled_one_time_activation(c1)

        create_scheduled_activation(c1)
        create_scheduled_activation(c1)

        request = self.factory.get(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(0, len(response.data))
    def test_fetched_controlled_circuit_owner_is_the_controller(self):
        circuit = create_circuit(name='c1', controller=self.user)

        request = self.factory.get(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertCircuitEqual(response.data, circuit)
    def setUp(self):
        self.user = create_user()
        self.circuit = create_circuit(name='c1')
        self.circuit.controller = self.user
        self.circuit.save()

        self.view = ActivationLogView.as_view()
        self.factory = APIRequestFactory()
        self.url = reverse('circuit-activation-log')
Exemplo n.º 8
0
    def setUp(self):
        self.user = create_user()
        self.circuit = create_circuit(name='c1')
        self.circuit.collaborators.add(self.user)

        self.view = CircuitScheduleView.as_view()
        self.factory = APIRequestFactory()
        self.url = reverse('circuit-schedule',
                           kwargs={'circuit_id': self.circuit.pk})
    def setUp(self):
        self.user = create_user()
        self.circuit = create_circuit(name='c1')
        self.circuit.collaborators.add(self.user)

        self.view = CircuitOneTimeActivationView.as_view()
        self.factory = APIRequestFactory()
        self.url = reverse('circuit-one-time-activations',
                           kwargs={'circuit_id': self.circuit.pk})
    def test_fetch_many_circuits_no_activations_no_schedule(self):
        c1 = create_circuit(name='c1')
        c1.collaborators.add(self.user)
        c2 = create_circuit(name='c2')
        c2.collaborators.add(self.user)
        create_circuit(name='c3')

        request = self.factory.get(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(2, len(response.data))
        self.assertIsNone(response.data[0].get('one_time_activation'))
        self.assertListEqual([], response.data[0].get('schedule'))
        self.assertIsNone(response.data[1].get('one_time_activation'))
        self.assertListEqual([], response.data[1].get('schedule'))

        self.assertCircuitEqual(response.data[0], c1)
        self.assertCircuitEqual(response.data[1], c2)
Exemplo n.º 11
0
    def test_patch(self):
        health_check = datetime.datetime.now(tz=pytz.UTC) - datetime.timedelta(
            days=1)
        circuit = create_circuit(name='c1',
                                 controller=self.user,
                                 health_check=health_check)
        healthy = circuit.healthy

        self.assertFalse(healthy)

        request = self.factory.patch(self.url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCircuitEqual(response.data,
                                Circuit.objects.get(pk=circuit.pk))