<commit_before>from bson.json_util import loads, dumps
from testsuite import DataBaseTestCase


class ExtApiTest(DataBaseTestCase):

    def test_item_filter(self):
        # insufficient privileges -> redirect to login
        rv = self.open_with_auth('/ext/items', username='worker', method='POST',
                                 data=dict(filter='{"partno": "TE0001a"}'))
        self.assertEqual(302, rv.status_code)
        self.assertIn('/login', rv.location)
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict(filter='{"partno": "TE0001a"}'))
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertTrue(data.get('ok'))
        self.assertEqual(['LP0001'], data.get('serials'))
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict(filter='{"$partno": "TE0001a"}'))
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertFalse(data.get('ok'))
        self.assertIn('unknown top level operator: $partno', data.get('message'))
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict(filt='{"$partno": "TE0001a"}'))
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertFalse(data.get('ok'))
        self.assertIn('missing filter', data.get('message'))

    def test_item_info(self):
        # insufficient privileges -> redirect to login
        rv = self.open_with_auth('/ext/items/LP0001', username='worker')
        self.assertEqual(302, rv.status_code)
        self.assertIn('/login', rv.location)
        rv = self.open_with_auth('/ext/items/LP0001')
        self.assertEqual(200, rv.status_code)
        obj = loads(rv.data.decode('utf-8'))
        refobj = {
            '_id': 'LP0001',
            'partno': 'TE0001a',
            'available': True,
            'status': '',
            'comments': []
        }<commit_msg>fix broken test on Ubuntu<commit_after>from bson.json_util import loads, dumps
from testsuite import DataBaseTestCase


class ExtApiTest(DataBaseTestCase):

    def test_item_filter(self):
        # insufficient privileges -> redirect to login
        rv = self.open_with_auth('/ext/items', username='worker', method='POST',
                                 data=dict(filter='{"partno": "TE0001a"}'))
        self.assertEqual(302, rv.status_code)
        self.assertIn('/login', rv.location)
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict(filter='{"partno": "TE0001a"}'))
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertTrue(data.get('ok'))
        self.assertEqual(['LP0001'], data.get('serials'))
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict())
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertFalse(data.get('ok'))
        self.assertIn('missing filter', data.get('message'))
        rv = self.open_with_auth('/ext/items', username='viewer', method='POST',
                                 data=dict(filt='{"$partno": "TE0001a"}'))
        self.assertEqual(200, rv.status_code)
        data = loads(rv.data.decode('utf-8'))
        self.assertFalse(data.get('ok'))
        self.assertIn('missing filter', data.get('message'))

    def test_item_info(self):
        # insufficient privileges -> redirect to login
        rv = self.open_with_auth('/ext/items/LP0001', username='worker')
        self.assertEqual(302, rv.status_code)
        self.assertIn('/login', rv.location)
        rv = self.open_with_auth('/ext/items/LP0001')
        self.assertEqual(200, rv.status_code)
        obj = loads(rv.data.decode('utf-8'))
        refobj = {
            '_id': 'LP0001',
            'partno': 'TE0001a',
            'available': True,
            'status': '',
            'comments': []
        }
{'fraction_non_alphanumeric': 0.15936160076226774, 'fraction_numerical': 0.0266793711291091, 'mean_word_length': 2.427755102040816, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7182686', 'n_tokens_mistral': 1304, 'n_tokens_neox': 1214, 'n_words': 202}