Esempio n. 1
0
def test_db_file_corrupted():

    with tempfile.TemporaryDirectory() as cachedir:
        unc = 'sqlite:///' + cachedir + '/test.db'

        with mock.patch(
                'ansibullbot.utils.sqlite_utils.C.DEFAULT_DATABASE_UNC', unc):

            # create the initial file
            ADB1 = AnsibullbotDatabase(cachedir=cachedir)
            unc_file = ADB1.unc
            unc_file = unc_file.replace('sqlite:///', '')
            with open(unc_file, 'w') as f:
                f.write('NULLNULLNULLNULL')

            # now try to init again
            ADB2 = AnsibullbotDatabase(cachedir=cachedir)

            assert os.path.exists(ADB2.dbfile)
Esempio n. 2
0
def test_db_file_endswith_version():

    with tempfile.TemporaryDirectory() as cachedir:
        unc = 'sqlite:///' + cachedir + '/test.db'

        with mock.patch(
                'ansibullbot.utils.sqlite_utils.C.DEFAULT_DATABASE_UNC', unc):

            ADB = AnsibullbotDatabase(cachedir=cachedir)

            print(ADB.unc)
            assert ADB.unc.endswith('_' + ADB.VERSION)
Esempio n. 3
0
def test_set_and_get_rate_limit():

    with tempfile.TemporaryDirectory() as cachedir:
        unc = 'sqlite:///' + cachedir + '/test.db'

        with mock.patch(
                'ansibullbot.utils.sqlite_utils.C.DEFAULT_DATABASE_UNC', unc):

            ADB = AnsibullbotDatabase(cachedir=cachedir)

            rl = {'resources': {'core': {'limit': 5000, 'remaining': 5000}}}

            ADB.set_rate_limit(username='******', token='abcd1234', rawjson=rl)
            remaining = ADB.get_rate_limit_remaining(username='******',
                                                     token='abcd1234')
            rl2 = ADB.get_rate_limit_rawjson(username='******', token='abcd1234')
            counter = ADB.get_rate_limit_query_counter(username='******',
                                                       token='abcd1234')

            assert remaining == 5000
            assert rl == rl2
            assert counter == 2
Esempio n. 4
0
import requests
import shutil
from datetime import datetime

import ansibullbot.constants as C

from bs4 import BeautifulSoup

from ansibullbot._pickle_compat import pickle_dump, pickle_load
from ansibullbot._text_compat import to_text
from ansibullbot.decorators.github import RateLimited
from ansibullbot.errors import RateLimitError
from ansibullbot.utils.file_tools import read_gzip_json_file, write_gzip_json_file
from ansibullbot.utils.sqlite_utils import AnsibullbotDatabase

ADB = AnsibullbotDatabase()


class GithubWrapper(object):
    def __init__(self,
                 gh,
                 token=None,
                 username=None,
                 password=None,
                 cachedir=u'~/.ansibullbot/cache'):
        self.gh = gh
        self.token = token
        self.username = username
        self.password = password
        self.cachedir = os.path.expanduser(cachedir)
        self.cachefile = os.path.join(self.cachedir, u'github.pickle')