コード例 #1
0
    def test_fetch_not_related(self):
        create_scheduled_one_time_activation(self.circuit)
        create_scheduled_one_time_activation(self.circuit)

        create_scheduled_activation(self.circuit)
        create_scheduled_activation(self.circuit)

        url = reverse('circuit-detail', kwargs={'pk': self.circuit_not_related.pk})
        request = self.factory.get(url, format='json')
        force_authenticate(request, self.user)
        response = self.view(request, pk=self.circuit_not_related.pk)

        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
コード例 #2
0
    def test_fetch(self):
        today = datetime.datetime.now(tz=pytz.UTC)
        tomorrow = today + datetime.timedelta(days=1)
        yesterday = today - +datetime.timedelta(days=1)

        s1 = create_scheduled_activation(self.circuit, timestamp=yesterday)
        s2 = create_scheduled_activation(self.circuit, timestamp=today)
        s3 = create_scheduled_activation(self.circuit, timestamp=tomorrow)

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertScheduleEqual(response.data, [s1, s2, s3])
コード例 #3
0
    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))
コード例 #4
0
    def test_fetch(self):
        today = datetime.datetime.now(tz=pytz.UTC)
        tomorrow = today + datetime.timedelta(days=1)
        yesterday = today - datetime.timedelta(days=1)

        create_scheduled_one_time_activation(self.circuit, timestamp=tomorrow)
        create_scheduled_one_time_activation(self.circuit, timestamp=yesterday)
        create_scheduled_one_time_activation(self.circuit, timestamp=today)
        most_recent_activation = create_scheduled_one_time_activation(self.circuit,
                                                                      timestamp=today + datetime.timedelta(minutes=5))

        create_scheduled_activation(self.circuit)
        create_scheduled_activation(self.circuit)

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

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCircuitEqual(response.data, self.circuit)
        self.assertOneTimeActivationEqual(response.data['one_time_activation'], most_recent_activation)
コード例 #5
0
    def test_fetch_many_circuits(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')

        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(2, len(response.data))
        self.assertCircuitEqual(response.data[0], c1)
        self.assertCircuitEqual(response.data[1], c2)
コード例 #6
0
    def test_put(self):
        today = datetime.datetime.now(tz=pytz.UTC)
        tomorrow = today + datetime.timedelta(days=1)
        yesterday = today - +datetime.timedelta(days=1)

        create_scheduled_activation(self.circuit, timestamp=yesterday)
        create_scheduled_activation(self.circuit, timestamp=today)
        create_scheduled_activation(self.circuit, timestamp=tomorrow)

        data = [{'active': False, 'amount': 200, 'time': '21:00:49'}]

        request = self.factory.put(self.url, data=data, format='json')
        force_authenticate(request, self.user)
        response = self.view(request, circuit_id=self.circuit.pk)

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertScheduleEqual(data, self.circuit.schedule.all())
コード例 #7
0
    def test_put_circuit_not_owned(self):
        today = datetime.datetime.now(tz=pytz.UTC)
        tomorrow = today + datetime.timedelta(days=1)
        yesterday = today - +datetime.timedelta(days=1)

        create_scheduled_activation(self.circuit, timestamp=yesterday)
        create_scheduled_activation(self.circuit, timestamp=today)
        create_scheduled_activation(self.circuit, timestamp=tomorrow)

        data = [{'active': False, 'amount': 200, 'time': '21:00:49'}]

        user2 = create_user(email="*****@*****.**")

        request = self.factory.put(self.url, data=data, format='json')
        force_authenticate(request, user2)
        response = self.view(request, circuit_id=self.circuit.pk)

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