def test_api_service_pkg_get_all(self):
     ServicePackageModel(servicePackageId="13",
                         servicedId="2",
                         servicedDesigner="2",
                         servicedVersion="2",
                         servicePackageUri="13.csar",
                         servicedModel="").save()
     ServicePackageModel(servicePackageId="14",
                         servicedId="3",
                         servicedDesigner="3",
                         servicedVersion="3",
                         servicePackageUri="14.csar",
                         servicedModel="").save()
     resp = self.client.get(PARSER_BASE_URL + "/service_packages")
     self.assertEqual(resp.status_code, status.HTTP_200_OK)
 def test_service_pkg_get_all(self):
     ServicePackageModel(servicePackageId="13",
                         servicedId="2",
                         servicedDesigner="2",
                         servicedVersion="2",
                         servicePackageUri="13.csar",
                         servicedModel="").save()
     ServicePackageModel(servicePackageId="14",
                         servicedId="3",
                         servicedDesigner="3",
                         servicedVersion="3",
                         servicePackageUri="14.csar",
                         servicedModel="").save()
     csars = ServicePackage().get_csars()
     self.assertEqual(2, len(csars))
    def test_service_pkg_parser(self, mock_parse_sd):
        ServicePackageModel(servicePackageId="8", servicedId="2").save()
        mock_parse_sd.return_value = json.JSONEncoder().encode({"a": "b"})

        inputs = []
        ret = ServicePackage().parse_serviced("8", inputs)
        self.assertTrue({"model": '{"c": "d"}'}, ret)
 def test_service_pkg_normal_delete(self):
     ServicePackageModel(servicePackageId="8", servicedId="2").save()
     sp = ServicePackageModel.objects.filter(servicePackageId=8)
     self.assertEqual(1, len(sp))
     ServicePackage().delete_csar("8")
     sp = ServicePackageModel.objects.filter(servicePackageId=8)
     self.assertEqual(0, len(sp))
 def test_service_pkg_distribute_when_pkg_exists(self):
     ServicePackageModel(servicePackageId="1", servicedId="2").save()
     csar_id = "1"
     try:
         ServicePackage().on_distribute(csar_id)
     except PackageHasExistsException as e:
         self.assertEqual("Service CSAR(1) already exists.", e.args[0])
 def test_api_service_pkg_distribute_when_pkg_exists(self):
     ServicePackageModel(servicePackageId="1", servicedId="2").save()
     resp = self.client.post(PARSER_BASE_URL + "/service_packages",
                             {"csarId": "1"},
                             format='json')
     self.assertEqual(resp.status_code, status.HTTP_400_BAD_REQUEST)
     self.assertEqual("Service CSAR(1) already exists.",
                      resp.data["errorMessage"])
 def test_service_pkg_get_one(self):
     ServicePackageModel(servicePackageId="14",
                         servicedId="2",
                         servicedDesigner="3",
                         servicedVersion="4",
                         servicePackageUri="14.csar",
                         servicedModel="").save()
     csar = ServicePackage().get_csar(14)
     self.assertEqual(14, csar['csarId'])
 def test_api_service_pkg_normal_delete(self):
     ServicePackageModel(servicePackageId="8", servicedId="2").save()
     resp = self.client.delete(PARSER_BASE_URL + "/service_packages/8")
     self.assertEqual(resp.status_code, status.HTTP_204_NO_CONTENT)