Пример #1
0
 def test_get_single(self):
     response = self.client.get(
         reverse("pl_sandbox:sandbox-specs-detail", args=(self.specs.pk, )))
     expected = {
         "status": True,
         "row": dgeq.serialize(self.specs),
     }
     self.assertEqual(200, response.status_code)
     self.assertEqual(expected, response.json())
Пример #2
0
def poll_specifications(sandbox_pk: int) -> None:
    """Poll specifications of a sandbox and send it to the correct group."""
    sandbox = Sandbox.objects.get(pk=sandbox_pk)
    sandbox_specs, container_specs = async_to_sync(
        sandbox.poll_specifications)()
    channel_layer = get_channel_layer()

    async_to_sync(channel_layer.group_send)(
        f"sandbox_sandbox_specs_{sandbox_pk}", {
            'type': 'sandbox_specs',
            'specs': DjangoJSONEncoder().encode(dgeq.serialize(sandbox_specs))
        })
    async_to_sync(channel_layer.group_send)(
        f"sandbox_container_specs_{sandbox_pk}", {
            'type': 'container_specs',
            'specs': DjangoJSONEncoder().encode(
                dgeq.serialize(container_specs))
        })
Пример #3
0
 def test_get_single(self):
     command_result = self.client.get(
         reverse("pl_sandbox:command-results-detail",
                 args=(self.command_result.pk, )))
     expected = {
         "status": True,
         "row": dgeq.serialize(self.command_result),
     }
     self.assertEqual(200, command_result.status_code)
     self.assertEqual(expected, command_result.json())
Пример #4
0
def poll_usage(sandbox_pk: int) -> None:
    """Poll usage of a sandbox and send it to the correct group."""
    sandbox = Sandbox.objects.get(pk=sandbox_pk)
    usage = async_to_sync(sandbox.poll_usage)()
    channel_layer = get_channel_layer()

    async_to_sync(channel_layer.group_send)(
        f"sandbox_usage_{sandbox_pk}", {
            'type': 'sandbox_usage',
            'usage': DjangoJSONEncoder().encode(dgeq.serialize(usage))
        })
Пример #5
0
    def test_get_collection(self):
        sandbox_dummy1 = Sandbox.objects.create(name="Dummy 1",
                                                url="http://localhost:7777",
                                                enabled=True)
        Sandbox.objects.create(name="Dummy 2",
                               url="http://localhost:7778",
                               enabled=False)
        response = self.client.get(reverse("pl_sandbox:sandbox-list"),
                                   data={"enabled": "1"})
        expected = {
            "status":
            True,
            "rows": [
                dgeq.serialize(self.sandbox),
                dgeq.serialize(sandbox_dummy1),
            ]
        }

        self.assertEqual(200, response.status_code)
        self.assertDictEqual(expected, response.json())
Пример #6
0
 def test_get_single(self):
     response = self.client.get(
         reverse("pl_sandbox:request-detail", args=(self.request.pk, )))
     # Encode and decode the expected output so that the date format match
     expected = json.loads(DjangoJSONEncoder().encode({
         "status":
         True,
         "row":
         dgeq.serialize(self.request),
     }))
     self.assertEqual(200, response.status_code)
     self.assertEqual(expected, response.json())
Пример #7
0
    def test_delete(self):
        sandbox_dummy1 = Sandbox.objects.create(name="Dummy 1",
                                                url="http://localhost:7777",
                                                enabled=True)
        expected = {
            "status": True,
            "row": dgeq.serialize(sandbox_dummy1),
        }

        response = self.client.delete(
            reverse("pl_sandbox:sandbox-detail", args=(sandbox_dummy1.pk, )))
        self.assertEqual(200, response.status_code)
        self.assertDictEqual(expected, response.json())
Пример #8
0
 def test_post_ok(self):
     data = {
         "name": "Dummy 1",
         "url": "http://localhost:7777",
         "enabled": False
     }
     response = self.client.post(reverse("pl_sandbox:sandbox-list"),
                                 data=data,
                                 content_type="application/json")
     expected = {
         "status": True,
         "row": dgeq.serialize(Sandbox.objects.get(name="Dummy 1"))
     }
     self.assertEqual(201, response.status_code)
     self.assertDictEqual(expected, response.json())
Пример #9
0
 def test_patch(self):
     sandbox_dummy1 = Sandbox.objects.create(name="Dummy 1",
                                             url="http://localhost:7777",
                                             enabled=True)
     data = {"name": "Modified"}
     response = self.client.patch(reverse("pl_sandbox:sandbox-detail",
                                          args=(sandbox_dummy1.pk, )),
                                  data=data,
                                  content_type="application/json")
     sandbox_dummy1.refresh_from_db()
     expected = {
         "status": True,
         "row": dgeq.serialize(sandbox_dummy1),
     }
     self.assertEqual(200, response.status_code)
     self.assertDictEqual(expected, response.json())
     self.assertEqual("Modified", response.json()["row"]["name"])