Example #1
0
  def testAttacker(self):
    iatkeps = [AttackerEnvironmentProperties(self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],self.iAttackers[0]["theEnvironmentProperties"][0]["theMotives"],self.iAttackers[0]["theEnvironmentProperties"][0]["theCapabilities"]),AttackerEnvironmentProperties(self.iAttackers[0]["theEnvironmentProperties"][1]["theName"],self.iAttackers[0]["theEnvironmentProperties"][1]["theRoles"],self.iAttackers[0]["theEnvironmentProperties"][1]["theMotives"],self.iAttackers[0]["theEnvironmentProperties"][1]["theCapabilities"])]
    iatk = AttackerParameters(self.iAttackers[0]["theName"], self.iAttackers[0]["theDescription"], self.iAttackers[0]["theImage"],[],iatkeps)
    b = Borg()
    b.dbProxy.addAttacker(iatk)
    oAttackers = b.dbProxy.getAttackers()
    o = oAttackers[self.iAttackers[0]["theName"]]
    self.assertEqual(iatk.name(), o.name())
    self.assertEqual(iatk.description(),o.description())
    self.assertEqual(iatk.image(),o.image())
    oatkeps = o.environmentProperties()
    self.assertEqual(iatkeps[0].name(), oatkeps[0].name())
    self.assertEqual(str(iatkeps[0].roles()[0]), str(oatkeps[0].roles()[0]))
    self.assertEqual(str(iatkeps[0].roles()[0]), o.roles('Day','')[0])
    self.assertEqual(iatkeps[0].roles(), list(o.roles('','Maximise')))
    self.assertEqual(str(iatkeps[0].motives()[0]), str(oatkeps[0].motives()[0]))
    self.assertEqual(str(iatkeps[0].motives()[0]), str(o.motives('Day','')[0]))
    self.assertEqual(iatkeps[0].motives(), list(o.motives('','Maximise')))
    self.assertEqual(str(iatkeps[0].capabilities()[0][0]), str(oatkeps[0].capabilities()[0][0]))
    self.assertEqual(str(iatkeps[0].capabilities()[0][1]), str(oatkeps[0].capabilities()[0][1]))
    self.assertEqual(iatkeps[0].capabilities()[0][0], o.capability('Day','')[0][0])
    self.assertEqual(iatkeps[0].capabilities()[0][0], list(o.capability('','Maximise'))[0][0])

    iatk.theName = 'Updated name'
    iatk.setId(o.id())
    b.dbProxy.updateAttacker(iatk)
    oAttackers = b.dbProxy.getAttackers()
    o = oAttackers["Updated name"]
    self.assertEqual(o.name(),'Updated name')


    b.dbProxy.deleteAttacker(o.id())
Example #2
0
 def parameters(self):
     parameters = AttackerParameters(self.theAttackerName,
                                     self.theAttackerDescription,
                                     self.theAttackerImage, self.theTags,
                                     self.theEnvironmentProperties)
     parameters.setId(self.theAttackerId)
     return parameters
Example #3
0
    def testAttacker(self):
        iatkeps = [
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][0]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][0]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][0]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [0]["theCapabilities"]),
            AttackerEnvironmentProperties(
                self.iAttackers[0]["theEnvironmentProperties"][1]["theName"],
                self.iAttackers[0]["theEnvironmentProperties"][1]["theRoles"],
                self.iAttackers[0]["theEnvironmentProperties"][1]
                ["theMotives"], self.iAttackers[0]["theEnvironmentProperties"]
                [1]["theCapabilities"])
        ]
        iatk = AttackerParameters(self.iAttackers[0]["theName"],
                                  self.iAttackers[0]["theDescription"],
                                  self.iAttackers[0]["theImage"], [], iatkeps)
        b = Borg()
        b.dbProxy.addAttacker(iatk)
        oAttackers = b.dbProxy.getAttackers()
        o = oAttackers[self.iAttackers[0]["theName"]]
        self.assertEqual(iatk.name(), o.name())
        self.assertEqual(iatk.description(), o.description())
        self.assertEqual(iatk.image(), o.image())
        oatkeps = o.environmentProperties()
        self.assertEqual(iatkeps[0].name(), oatkeps[0].name())
        self.assertEqual(str(iatkeps[0].roles()[0]),
                         str(oatkeps[0].roles()[0]))
        self.assertEqual(str(iatkeps[0].roles()[0]), o.roles('Day', '')[0])
        self.assertEqual(iatkeps[0].roles(), list(o.roles('', 'Maximise')))
        self.assertEqual(str(iatkeps[0].motives()[0]),
                         str(oatkeps[0].motives()[0]))
        self.assertEqual(str(iatkeps[0].motives()[0]),
                         str(o.motives('Day', '')[0]))
        self.assertEqual(iatkeps[0].motives(), list(o.motives('', 'Maximise')))
        self.assertEqual(str(iatkeps[0].capabilities()[0][0]),
                         str(oatkeps[0].capabilities()[0][0]))
        self.assertEqual(str(iatkeps[0].capabilities()[0][1]),
                         str(oatkeps[0].capabilities()[0][1]))
        self.assertEqual(iatkeps[0].capabilities()[0][0],
                         o.capability('Day', '')[0][0])
        self.assertEqual(iatkeps[0].capabilities()[0][0],
                         list(o.capability('', 'Maximise'))[0][0])

        iatk.theName = 'Updated name'
        iatk.setId(o.id())
        b.dbProxy.updateAttacker(iatk)
        oAttackers = b.dbProxy.getAttackers()
        o = oAttackers["Updated name"]
        self.assertEqual(o.name(), 'Updated name')

        b.dbProxy.deleteAttacker(o.id())
Example #4
0
    def update_attacker(self, attacker, name):
        attacker_params = AttackerParameters(
            name=attacker.theName,
            desc=attacker.theDescription,
            image=attacker.theImage,
            tags=attacker.theTags,
            properties=attacker.theEnvironmentProperties)

        try:
            attackerId = self.db_proxy.getDimensionId(name, 'attacker')
            attacker_params.setId(attackerId)
            self.db_proxy.updateAttacker(attacker_params)
        except DatabaseProxyException as ex:
            self.close()
            raise ARMHTTPError(ex)
        except ARMException as ex:
            self.close()
            raise ARMHTTPError(ex)
Example #5
0
  def update_attacker(self, attacker, name):
    attacker_params = AttackerParameters(
      name=attacker.theName,
      desc=attacker.theDescription,
      image=attacker.theImage,
      tags=attacker.theTags,
      properties=attacker.theEnvironmentProperties
    )

    try:
      attackerId = self.db_proxy.getDimensionId(name,'attacker')
      attacker_params.setId(attackerId)
      self.db_proxy.updateAttacker(attacker_params)
    except DatabaseProxyException as ex:
      self.close()
      raise ARMHTTPError(ex)
    except ARMException as ex:
      self.close()
      raise ARMHTTPError(ex)
Example #6
0
    def update_attacker(self, attacker, name):
        found_attacker = self.get_attacker_by_name(name, simplify=False)

        attacker_params = AttackerParameters(
            name=attacker.theName,
            desc=attacker.theDescription,
            image=attacker.theImage,
            tags=attacker.theTags,
            properties=attacker.theEnvironmentProperties)
        attacker_params.setId(found_attacker.theId)

        try:
            self.db_proxy.updateAttacker(attacker_params)
        except DatabaseProxyException as ex:
            self.close()
            raise ARMHTTPError(ex)
        except ARMException as ex:
            self.close()
            raise ARMHTTPError(ex)
Example #7
0
    def update_attacker(self, attacker, name):
        found_attacker = self.get_attacker_by_name(name, simplify=False)

        attacker_params = AttackerParameters(
            name=attacker.theName,
            desc=attacker.theDescription,
            image=attacker.theImage,
            tags=attacker.theTags,
            properties=attacker.theEnvironmentProperties
        )
        attacker_params.setId(found_attacker.theId)

        try:
            self.db_proxy.updateAttacker(attacker_params)
        except DatabaseProxyException as ex:
            self.close()
            raise ARMHTTPError(ex)
        except ARMException as ex:
            self.close()
            raise ARMHTTPError(ex)
Example #8
0
 def parameters(self):
   parameters = AttackerParameters(self.theAttackerName,self.theAttackerDescription,self.theAttackerImage,self.theTags,self.theEnvironmentProperties)
   parameters.setId(self.theAttackerId)
   return parameters