<commit_before># Copyright (C) 2015 Google Inc., authors, and contributors <see AUTHORS file>
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
# Created By: <EMAIL>
# Maintained By: <EMAIL>

from ggrc.app import app
from ggrc.services.common import Resource
from ggrc import services
import inspect
import flask
import logging


# style: should the class name be all capitals?
class Api():

  def __init__(self):
    self.tc = app.test_client()
    self.tc.get("/login")
    self.resource = Resource()
    self.service_dict = {s.model_class.__name__: s.name
                         for s in services.all_services()}
    self.headers = {'Content-Type': 'application/json',
                    "X-Requested-By": "gGRC"
                    }
    self.user_headers = {}

  def set_user(self, person=None):
    # Refresh the person instance from the db:
    person = person.__class__.query.get(person.id)
    if person:
      self.user_headers = {
          "X-ggrc-user": self.resource.as_json({
              "name": person.name,
              "email": person.email,
          })
      }
    else:
      self.user_headers = {}

    self.tc.get("/logout")
    self.tc.get("/login", headers=self.user_headers)

  def get_service(self, obj):
    if inspect.isclass(obj):
      return self.service_dict[obj.__name__]
    else:
      return self.service_dict[obj.__class__.__name__]<commit_msg>Flush session after setting a user<commit_after># Copyright (C) 2015 Google Inc., authors, and contributors <see AUTHORS file>
# Licensed under http://www.apache.org/licenses/LICENSE-2.0 <see LICENSE file>
# Created By: <EMAIL>
# Maintained By: <EMAIL>

from ggrc import db
from ggrc.app import app
from ggrc.services.common import Resource
from ggrc import services
import inspect
import flask
import logging


# style: should the class name be all capitals?
class Api():

  def __init__(self):
    self.tc = app.test_client()
    self.tc.get("/login")
    self.resource = Resource()
    self.service_dict = {s.model_class.__name__: s.name
                         for s in services.all_services()}
    self.headers = {'Content-Type': 'application/json',
                    "X-Requested-By": "gGRC"
                    }
    self.user_headers = {}

  def set_user(self, person=None):
    # Refresh the person instance from the db:
    person = person.__class__.query.get(person.id)
    if person:
      self.user_headers = {
          "X-ggrc-user": self.resource.as_json({
              "name": person.name,
              "email": person.email,
          })
      }
    else:
      self.user_headers = {}

    self.tc.get("/logout")
    self.tc.get("/login", headers=self.user_headers)
    db.session.commit()
    db.session.flush()

  def get_service(self, obj):
    if inspect.isclass(obj):
      return self.service_dict[obj.__name__]
    else:
      return self.service_dict[obj.__class__.__name__]
{'fraction_non_alphanumeric': 0.12114989733059549, 'fraction_numerical': 0.004106776180698152, 'mean_word_length': 2.617574257425743, 'pattern_counts': {'":': 8, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4712106', 'n_tokens_mistral': 925, 'n_tokens_neox': 902, 'n_words': 226}