<commit_before>import json
import unittest

from libsaas.executors import test_executor
from libsaas.services import ducksboard


class DucksboardTestCase(unittest.TestCase):

    def setUp(self):
        self.executor = test_executor.use()
        self.executor.set_response(b'{}', 200, {})

        self.service = ducksboard.Ducksboard('apikey', 'pass')

    def serialize(self, data):
        return json.dumps(data)

    def expect(self, uri, method=None, params=None, subdomain=None):
        if not subdomain:
            domain = 'app.ducksboard.com/api'
        else:
            domain = '{0}.ducksboard.com/values'.format(subdomain)

        self.assertEqual(self.executor.request.uri,
                         'https://{0}/{1}'.format(domain, uri))
        if method:
            self.assertEqual(method, self.executor.request.method)
        if params:
            self.assertEqual(self.executor.request.params, params)

    def test_dashboard(self):
        self.service.dashboards().get()
        self.expect('dashboards/', 'GET')

        dashboard = {'name': 'x'}
        self.service.dashboards().create(dashboard)
        self.expect('dashboards/', 'POST', self.serialize(dashboard))

        self.service.dashboard('slug').update(dashboard)
        self.expect('dashboards/slug', 'PUT', self.serialize(dashboard))

        self.service.dashboard('slug').delete()
        self.expect('dashboards/slug', 'DELETE')

        self.service.dashboard('slug').accessed()
        self.expect('dashboards/slug/accessed', 'POST')<commit_msg>tests: add a test for using a Ducksboard service with no password<commit_after>import json
import unittest

from libsaas.executors import test_executor
from libsaas.services import ducksboard


class DucksboardTestCase(unittest.TestCase):

    def setUp(self):
        self.executor = test_executor.use()
        self.executor.set_response(b'{}', 200, {})

        self.service = ducksboard.Ducksboard('apikey', 'pass')

    def serialize(self, data):
        return json.dumps(data)

    def expect(self, uri, method=None, params=None, subdomain=None):
        if not subdomain:
            domain = 'app.ducksboard.com/api'
        else:
            domain = '{0}.ducksboard.com/values'.format(subdomain)

        self.assertEqual(self.executor.request.uri,
                         'https://{0}/{1}'.format(domain, uri))
        if method:
            self.assertEqual(method, self.executor.request.method)
        if params:
            self.assertEqual(self.executor.request.params, params)

    def test_default_password(self):
        s = ducksboard.Ducksboard('apikey')
        s.user().get()

        self.assertEqual(self.executor.request.headers['Authorization'],
                         'Basic YXBpa2V5Og==')

    def test_dashboard(self):
        self.service.dashboards().get()
        self.expect('dashboards/', 'GET')

        dashboard = {'name': 'x'}
        self.service.dashboards().create(dashboard)
        self.expect('dashboards/', 'POST', self.serialize(dashboard))

        self.service.dashboard('slug').update(dashboard)
        self.expect('dashboards/slug', 'PUT', self.serialize(dashboard))

        self.service.dashboard('slug').delete()
        self.expect('dashboards/slug', 'DELETE')

        self.service.dashboard('slug').accessed()
        self.expect('dashboards/slug/accessed', 'POST')
{'fraction_non_alphanumeric': 0.13832938388625593, 'fraction_numerical': 0.004146919431279621, 'mean_word_length': 2.798650168728909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '2608444', 'n_tokens_mistral': 1000, 'n_tokens_neox': 992, 'n_words': 168}