Exemplo n.º 1
0
    def testOffsetIsRelativeToFilteredResultsWhenFilterIsPresent(self):
        for i in range(5):
            self.CreateHunt(description="foo_hunt_%d" % i)

        for i in range(3):
            self.CreateHunt(description="bar_hunt_%d" % i)

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            description_contains="bar", active_within="1d", offset=1),
                                     token=self.token)
        self.assertLen(result.items, 2)
        for item in result.items:
            self.assertIn("bar", item.description)

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            description_contains="bar", active_within="1d", offset=2),
                                     token=self.token)
        self.assertLen(result.items, 1)
        for item in result.items:
            self.assertIn("bar", item.description)

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            description_contains="bar", active_within="1d", offset=3),
                                     token=self.token)
        self.assertEmpty(result.items)
Exemplo n.º 2
0
    def Run(self):
        if data_store.RelationalDBEnabled():
            replace = {}
            for i in range(0, 2):
                with test_lib.FakeTime((1 + i) * 1000):
                    hunt_id = self.CreateHunt(description="hunt_%d" % i)
                    if i % 2:
                        hunt.StopHunt(hunt_id)

                    replace[hunt_id] = "H:00000%d" % i
        else:
            replace = {}
            for i in range(0, 2):
                with test_lib.FakeTime((1 + i) * 1000):
                    with self.CreateHunt(description="hunt_%d" %
                                         i) as hunt_obj:
                        if i % 2:
                            hunt_obj.Stop()

                        replace[hunt_obj.urn.Basename()] = "H:00000%d" % i

        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(),
                   replace=replace)
        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(count=1),
                   replace=replace)
        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(offset=1, count=1),
                   replace=replace)
Exemplo n.º 3
0
 def testRaisesIfDescriptionContainsFilterUsedWithoutActiveWithinFilter(
         self):
     self.assertRaises(
         ValueError,
         self.handler.Handle,
         hunt_plugin.ApiListHuntsArgs(description_contains="foo"),
         token=self.token)
Exemplo n.º 4
0
    def Run(self):
        replace = {}
        for i in range(0, 2):
            with test_lib.FakeTime((1 + i) * 1000):
                hunt_id = self.CreateHunt(description="hunt_%d" % i)
                if i % 2:
                    hunt.StopHunt(hunt_id)

                replace[hunt_id] = "H:00000%d" % i

        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(),
                   replace=replace)
        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(count=1),
                   replace=replace)
        self.Check("ListHunts",
                   args=hunt_plugin.ApiListHuntsArgs(offset=1, count=1),
                   replace=replace)
Exemplo n.º 5
0
    def testHandlesListOfHuntObjects(self):
        for i in range(10):
            self.CreateHunt(description="hunt_%d" % i)

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(),
                                     token=self.token)
        descriptions = set(r.description for r in result.items)

        self.assertLen(descriptions, 10)
        for i in range(10):
            self.assertIn("hunt_%d" % i, descriptions)
Exemplo n.º 6
0
    def testFiltersHuntsByDescriptionContainsMatch(self):
        for i in range(5):
            self.CreateHunt(description="foo_hunt_%d" % i)

        for i in range(3):
            self.CreateHunt(description="bar_hunt_%d")

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            description_contains="foo", active_within="1d"),
                                     token=self.token)
        self.assertLen(result.items, 5)
        for item in result.items:
            self.assertIn("foo", item.description)

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            description_contains="bar", active_within="1d"),
                                     token=self.token)
        self.assertLen(result.items, 3)
        for item in result.items:
            self.assertIn("bar", item.description)
Exemplo n.º 7
0
    def testFiltersHuntsByCreator(self):
        for i in range(5):
            self.CreateHunt(description="foo_hunt_%d" % i, creator="user-foo")

        for i in range(3):
            self.CreateHunt(description="bar_hunt_%d" % i, creator="user-bar")

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            created_by="user-foo", active_within="1d"),
                                     token=self.token)
        self.assertLen(result.items, 5)
        for item in result.items:
            self.assertEqual(item.creator, "user-foo")

        result = self.handler.Handle(hunt_plugin.ApiListHuntsArgs(
            created_by="user-bar", active_within="1d"),
                                     token=self.token)
        self.assertLen(result.items, 3)
        for item in result.items:
            self.assertEqual(item.creator, "user-bar")
Exemplo n.º 8
0
  def testHandlesSubrangeOfListOfHuntObjects(self):
    for i in range(1, 11):
      with test_lib.FakeTime(i * 1000):
        self.CreateHunt(description="hunt_%d" % i)

    result = self.handler.Handle(
        hunt_plugin.ApiListHuntsArgs(offset=2, count=2), token=self.token)
    create_times = [r.created.AsMicrosecondsSinceEpoch() for r in result.items]

    self.assertEqual(len(create_times), 2)
    self.assertEqual(create_times[0], 8 * 1000000000)
    self.assertEqual(create_times[1], 7 * 1000000000)
Exemplo n.º 9
0
  def testHuntListIsSortedInReversedCreationTimestampOrder(self):
    for i in range(1, 11):
      with test_lib.FakeTime(i * 1000):
        self.CreateHunt(description="hunt_%d" % i)

    result = self.handler.Handle(
        hunt_plugin.ApiListHuntsArgs(), token=self.token)
    create_times = [r.created.AsMicrosecondsSinceEpoch() for r in result.items]

    self.assertEqual(len(create_times), 10)
    for index, expected_time in enumerate(reversed(range(1, 11))):
      self.assertEqual(create_times[index], expected_time * 1000000000)
Exemplo n.º 10
0
  def testFiltersHuntsByActivityTime(self):
    for i in range(1, 11):
      with test_lib.FakeTime(i * 60):
        self.CreateHunt(description="hunt_%d" % i)

    with test_lib.FakeTime(10 * 60 + 1):
      result = self.handler.Handle(
          hunt_plugin.ApiListHuntsArgs(active_within="2m"), token=self.token)

    create_times = [r.created for r in result.items]

    self.assertEqual(len(create_times), 2)
    self.assertEqual(create_times[0], 10 * 60 * 1000000)
    self.assertEqual(create_times[1], 9 * 60 * 1000000)
Exemplo n.º 11
0
 def testRaisesIfCreatedByFilterUsedWithoutActiveWithinFilter(self):
     self.assertRaises(ValueError,
                       self.handler.Handle,
                       hunt_plugin.ApiListHuntsArgs(created_by="user-bar"),
                       token=self.token)