<commit_before>import unittest
from webtest import TestApp
from dataactbroker.app import createApp

class BaseTest(unittest.TestCase):
    """ Test login, logout, and session handling """

    def setUp(self):
        """Set up broker unit tests."""
        app = createApp()
        app.config['TESTING'] = True
        self.app = TestApp(app)

    def tearDown(self):
        """Tear down broker unit tests."""
        #TODO: delete jobs and submissions from db

    def login(self):
        """Log user into broker."""
        #TODO: put user data in pytest fixture; put credentials in config file
        user = {"username": "user3", "password": "<PASSWORD>"}
        return self.app.post_json("/v1/login/", user)

    def login_admin(self):
        """Log an admin user into broker."""
        #TODO: put user data in pytest fixture; put credentials in config file
        user = {"username": "admin_email", "password": "<PASSWORD>"}
        response = self.app.post_json("/v1/login/", user)
        return response

    def login_user(self, username, password):
        #TODO: combine with login()
        user = {"username": username, "password": password}
        return self.app.post_json("/v1/login/", user)

    def logout(self):
        """Log user out of broker."""
        return self.app.post("/v1/logout/", {})

    def session_route(self):
        """Get session."""
        return self.app.get("/v1/session/")

    def check_response(self, response, status, message=None):
        """Perform common tests on API responses."""
        self.assertEqual(response.status_code, status)
        self.assertEqual(response.headers.get("Content-Type"), "application/json")
        try:
            self.assertIsInstance(response.json, dict)
        except AttributeError:
            self.fail("Response is missing JSON component")
        json = response.json
        if message:
            self.assertEqual(message, json["message"])
<commit_msg>use accounts from the usertests config and setup script<commit_after>import unittest
from webtest import TestApp
from dataactbroker.app import createApp

class BaseTest(unittest.TestCase):
    """ Test login, logout, and session handling """

    def setUp(self):
        """Set up broker unit tests."""
        app = createApp()
        app.config['TESTING'] = True
        self.app = TestApp(app)

    def tearDown(self):
        """Tear down broker unit tests."""
        #TODO: delete jobs and submissions from db

    def login(self):
        """Log an agency user (non-admin) into broker."""
        #TODO: put user data in pytest fixture; put credentials in config file
        user = {"username": "<EMAIL>", "password": "<PASSWORD>"}
        return self.app.post_json("/v1/login/", user)

    def login_admin(self):
        """Log an admin user into broker."""
        #TODO: put user data in pytest fixture; put credentials in config file
        user = {"username": "<EMAIL>", "password": "<PASSWORD>"}
        response = self.app.post_json("/v1/login/", user)
        return response

    def login_user(self, username, password):
        #TODO: combine with login()
        user = {"username": username, "password": password}
        return self.app.post_json("/v1/login/", user)

    def logout(self):
        """Log user out of broker."""
        return self.app.post("/v1/logout/", {})

    def session_route(self):
        """Get session."""
        return self.app.get("/v1/session/")

    def check_response(self, response, status, message=None):
        """Perform common tests on API responses."""
        self.assertEqual(response.status_code, status)
        self.assertEqual(response.headers.get("Content-Type"), "application/json")
        try:
            self.assertIsInstance(response.json, dict)
        except AttributeError:
            self.fail("Response is missing JSON component")
        json = response.json
        if message:
            self.assertEqual(message, json["message"])

{'fraction_non_alphanumeric': 0.13053319919517103, 'fraction_numerical': 0.002766599597585513, 'mean_word_length': 2.6722068328716526, 'pattern_counts': {'":': 12, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4181002', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1076, 'n_words': 337}