<commit_before>#!/usr/bin/env python3
"""
Meerkat API Tests

Unit tests for the alerts resource in Meerkat API
"""
import json
import unittest
import meerkat_api
from meerkat_api.test import db_util

class MeerkatAPIAlertsTestCase(unittest.TestCase):

    def setUp(self):
        """Setup for testing"""
        meerkat_api.app.config['TESTING'] = True
        meerkat_api.app.config['API_KEY'] = ""
        self.app = meerkat_api.app.test_client()
        db_util.insert_links(meerkat_api.db.session, "pip_report")

    def tearDown(self):
        pass


    def test_link(self):
        """ test getting one link by it's id"""
        rv = self.app.get('/link/1')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["link"]
        self.assertEqual(data["link_def"], "pip_followup")
        self.assertEqual(data["link_value"], "namru-1")
        self.assertEqual(data["data"],
                         {'outcome': [], 'ventilated': "yes", 'admitted_to_icu': "yes"})

    
    def test_links(self):
        """ Test getting links by type """
        rv = self.app.get('/links/pip_followup')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["links"]
        self.assertEqual(len(data), 4)

        self.assertEqual(data["namru-4"]["to_id"], "uuid:4e46f58e-74fd-42b6-b5ca-1350328152ee")
        self.assertEqual(data["namru-2"]["id"], 2)
        
        
        rv = self.app.get('/links/pip')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["links"]
        self.assertEqual(len(data), 3)
        self.assertEqual(data["namru-2"]["id"], 6)
        self.assertEqual(data["namru-3"]["data"], {"type": ["H1", "H3"]})<commit_msg>Fixing api tests<commit_after>#!/usr/bin/env python3
"""
Meerkat API Tests

Unit tests for the alerts resource in Meerkat API
"""
import json
import unittest
import meerkat_api
from meerkat_api.test import db_util

class MeerkatAPIAlertsTestCase(unittest.TestCase):

    def setUp(self):
        """Setup for testing"""
        meerkat_api.app.config['TESTING'] = True
        meerkat_api.app.config['API_KEY'] = ""
        self.app = meerkat_api.app.test_client()
        db_util.insert_links(meerkat_api.db.session, "pip_report")

    def tearDown(self):
        pass


    def test_link(self):
        """ test getting one link by it's id"""
        rv = self.app.get('/link/1')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["link"]
        self.assertEqual(data["link_def"], "pip_followup")
        self.assertEqual(data["link_value"], "namru-1")
        self.assertEqual(data["data"],
                         {'outcome': [], 'ventilated': "yes", 'admitted_to_icu': "yes"})

    
    def test_links(self):
        """ Test getting links by type """
        rv = self.app.get('/links/pip_followup')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["links"]
        self.assertEqual(len(data), 4)

        self.assertEqual(data["namru-4"]["to_id"], "uuid:4e46f58e-74fd-42b6-b5ca-1350328152ee")
        self.assertEqual(data["namru-2"]["id"], 2)
        
        
        rv = self.app.get('/links/pip')
        self.assertEqual(rv.status_code, 200)
        data = json.loads(rv.data.decode("utf-8"))["links"]
        self.assertEqual(len(data), 3)
        self.assertEqual(data["namru-2"]["id"], 6)
        self.assertEqual(data["namru-3"]["data"], {"type": "Mixed"})
{'fraction_non_alphanumeric': 0.1669491525423729, 'fraction_numerical': 0.025423728813559324, 'mean_word_length': 2.8657205240174672, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, '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': '1660444', 'n_tokens_mistral': 1244, 'n_tokens_neox': 1186, 'n_words': 198}