예제 #1
0
파일: utils_test.py 프로젝트: google/upvote
    def testNoExemptions_WithStateFilter(self):

        user = test_utils.CreateUser()
        test_utils.CreateSantaHosts(4, primary_user=user.nickname)

        actual_exms = model_utils.GetExemptionsForUser(
            user.email, state=constants.EXEMPTION_STATE.APPROVED)
        self.assertListEqual([], actual_exms)
예제 #2
0
def CreateTestEntities(email_addr):
    """Create some test Datastore data if specified, but only if running locally.

  Note that this code doesn't (and shouldn't) delete any existing entities.
  The risk of such code being accidentally triggered in prod is too great, so
  if local entities need to be deleted, use the local Datastore viewer (e.g.
  http://127.0.0.1:8000/datastore).

  Args:
    email_addr: Email address of the local users for whom test data should
        be created.

  Raises:
    NotRunningLocally: if called anywhere other than a local deployment.
  """
    if not utils.RunningLocally():
        raise NotRunningLocally

    # Create a user entity with all available roles.
    user = base.User.GetOrInsert(email_addr=email_addr)
    base.User.SetRoles(email_addr, constants.USER_ROLE.SET_ALL)

    username = user_map.EmailToUsername(email_addr)

    # Create associated SantaHosts for the user.
    santa_hosts = test_utils.CreateSantaHosts(2, primary_user=username)

    # For each SantaHost, create some SantaEvents.
    for santa_host in santa_hosts:
        for santa_blockable in test_utils.CreateSantaBlockables(5):

            parent_key = model_utils.ConcatenateKeys(user.key, santa_host.key,
                                                     santa_blockable.key)
            test_utils.CreateSantaEvent(
                santa_blockable,
                executing_user=username,
                event_type=constants.EVENT_TYPE.BLOCK_BINARY,
                host_id=santa_host.key.id(),
                parent=parent_key)

    # Create associated Bit9Hosts for the user.
    bit9_hosts = test_utils.CreateBit9Hosts(2, users=[username])

    # For each Bit9Host, create some Bit9Events.
    for bit9_host in bit9_hosts:
        for bit9_binary in test_utils.CreateBit9Binaries(5):

            parent_key = model_utils.ConcatenateKeys(user.key, bit9_host.key,
                                                     bit9_binary.key)
            test_utils.CreateBit9Event(
                bit9_binary,
                executing_user=username,
                event_type=constants.EVENT_TYPE.BLOCK_BINARY,
                host_id=bit9_host.key.id(),
                parent=parent_key)
예제 #3
0
파일: utils_test.py 프로젝트: google/upvote
    def testNoExemptions_WithoutStateFilter(self):

        user = test_utils.CreateUser()
        test_utils.CreateSantaHosts(4, primary_user=user.nickname)

        self.assertListEqual([], model_utils.GetExemptionsForUser(user.email))