コード例 #1
0
 def setUp(self):
     call_command_with_output("initdevice", "MyCentralDevice", "")
     self.zone = Zone.objects.create(name="MyZone")
     key = crypto.Key()
     self.remote_device = Device.objects.create(name="RemoteDevice", public_key=key.get_public_key_string())
     self.remote_device.key = key
     self.device_zone = DeviceZone.objects.create(zone=self.zone, device=self.remote_device)
     self.facility = Facility.objects.create(name="MyFacility")
     self.facility.sign(device=self.remote_device)
     self.facility.save(imported=True)
コード例 #2
0
 def test_no_options(self):
     try:
         (out, err, rc) = call_command_with_output('createmodel', 'some.model')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e),
                                  "Please specify input data as a json string")
コード例 #3
0
 def test_no_options(self):
     try:
         (out, err, rc) = call_command_with_output('readmodel', 'some.model')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e),
                                  "Please specify --id to fetch model.")
コード例 #4
0
 def test_no_args(self):
     try:
         (out, err, rc) = call_command_with_output('readmodel')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e),
                                  "Please specify model class name.")
コード例 #5
0
 def test_no_options(self):
     try:
         (out, err, rc) = call_command_with_output('readmodel',
                                                   'some.model')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e),
                                  "Please specify --id to fetch model.")
コード例 #6
0
 def test_no_options(self):
     try:
         (out, err, rc) = call_command_with_output('createmodel',
                                                   'some.model')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(
             str(e), "Please specify input data as a json string")
コード例 #7
0
    def test_fetch_model(self):
        MODEL_NAME = 'kalite.facility.models.Facility'
        facility_name = 'kir1'
        # Create a Facility object first that will be fetched.
        facility = Facility(name=facility_name)
        facility.save()

        (out, err, rc) = call_command_with_output('readmodel',
                                                  MODEL_NAME,
                                                  id=facility.id)
        data_map = json.loads(out)
        self.assertEquals(data_map['name'], facility_name)
コード例 #8
0
    def test_save_model(self):
        MODEL_NAME = 'kalite.facility.models.Facility'
        (out, err, rc) = call_command_with_output('createmodel',
                                                  MODEL_NAME,
                                                  json_data='{"name" : "kir1"}')
        self.assertEquals(rc, 0)
        module_path, model_name = MODEL_NAME.rsplit(".", 1)
        module = importlib.import_module(module_path)
        model = getattr(module, model_name)

        data = model.objects.get(pk=out.strip())
        self.assertEquals(data.name, "kir1")
コード例 #9
0
    def test_fetch_model(self):
        MODEL_NAME = 'kalite.facility.models.Facility'
        facility_name = 'kir1'
        # Create a Facility object first that will be fetched.
        facility = Facility(name=facility_name)
        facility.save()

        (out, err, rc) = call_command_with_output('readmodel',
                                                  MODEL_NAME,
                                                  id=facility.id)
        data_map = json.loads(out)
        self.assertEquals(data_map['name'], facility_name)
コード例 #10
0
    def test_save_model(self):
        MODEL_NAME = 'kalite.facility.models.Facility'
        (out, err,
         rc) = call_command_with_output('createmodel',
                                        MODEL_NAME,
                                        json_data='{"name" : "kir1"}')
        self.assertEquals(rc, 0)
        module_path, model_name = MODEL_NAME.rsplit(".", 1)
        module = importlib.import_module(module_path)
        model = getattr(module, model_name)

        data = model.objects.get(pk=out.strip())
        self.assertEquals(data.name, "kir1")
コード例 #11
0
 def test_no_args(self):
     try:
         (out, err, rc) = call_command_with_output('readmodel')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e), "Please specify model class name.")
コード例 #12
0
 def test_no_args(self):
     try:
         (out, err, rc) = call_command_with_output('createmodel')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e), "No args specified")
コード例 #13
0
 def test_no_args(self):
     try:
         (out, err, rc) = call_command_with_output('createmodel')
         self.assertFail()
     except CommandError as e:
         self.assertRegexpMatches(str(e), "No args specified")