Esempio n. 1
0
    def test_service_database_setting(self):
        from services.utils import mypool

        expected_name = settings.DATABASES['default']['NAME']
        assert 'test' in expected_name
        assert settings.SERVICES_DATABASE['NAME'] == expected_name

        connection = mypool.connect()
        cursor = connection.cursor()
        cursor.execute('SELECT DATABASE();')
        assert cursor.fetchone()[0] == expected_name
        connection.close()
Esempio n. 2
0
    def is_valid(self):
        # If you accessing this from unit tests, then before calling
        # is valid, you can assign your own cursor.
        if not self.cursor:
            self.conn = mypool.connect()
            self.cursor = self.conn.cursor()

        data = self.data
        # Version can be blank.
        data['version'] = data.get('version', '')
        for field in ['reqVersion', 'id', 'appID', 'appVersion']:
            if field not in data:
                return False

        app = applications.APP_GUIDS.get(data['appID'])
        if not app:
            return False

        data['app_id'] = app.id

        sql = """SELECT id, status, addontype_id, guid FROM addons
                 WHERE guid = %(guid)s AND
                       inactive = 0 AND
                       status NOT IN (%(STATUS_DELETED)s, %(STATUS_DISABLED)s)
                 LIMIT 1;"""
        self.cursor.execute(
            sql,
            {
                'guid': self.data['id'],
                'STATUS_DELETED': base.STATUS_DELETED,
                'STATUS_DISABLED': base.STATUS_DISABLED,
            },
        )
        result = self.cursor.fetchone()
        if result is None:
            return False

        data['id'], data['addon_status'], data['type'], data['guid'] = result
        data['version_int'] = version_int(data['appVersion'])

        if 'appOS' in data:
            for k, v in PLATFORM_NAMES_TO_CONSTANTS.items():
                if k in data['appOS']:
                    data['appOS'] = v
                    break
            else:
                data['appOS'] = None

        return True
Esempio n. 3
0
 def __init__(self, locale, id_, qs=None):
     self.conn, self.cursor = None, None
     self.from_gp = qs == 'src=gp'
     self.data = {
         'locale': locale,
         'id': id_,
         # If we came from getpersonas.com, then look up by `persona_id`.
         # Otherwise, look up `addon_id`.
         'primary_key': 'persona_id' if self.from_gp else 'addon_id',
         'atype': base.ADDON_PERSONA,
         'row': {}
     }
     if not self.cursor:
         self.conn = mypool.connect()
         self.cursor = self.conn.cursor()
Esempio n. 4
0
 def __init__(self, locale, id_, qs=None):
     self.conn, self.cursor = None, None
     self.from_gp = qs == 'src=gp'
     self.data = {
         'locale': locale,
         'id': id_,
         # If we came from getpersonas.com, then look up by `persona_id`.
         # Otherwise, look up `addon_id`.
         'primary_key': 'persona_id' if self.from_gp else 'addon_id',
         'atype': base.ADDON_PERSONA,
         'row': {}
     }
     if not self.cursor:
         self.conn = mypool.connect()
         self.cursor = self.conn.cursor()
Esempio n. 5
0
 def __init__(self, locale, id_, qs=None):
     self.conn, self.cursor = None, None
     self.from_gp = qs == "src=gp"
     self.data = {
         "locale": locale,
         "id": id_,
         # If we came from getpersonas.com, then look up by `persona_id`.
         # Otherwise, look up `addon_id`.
         "primary_key": "persona_id" if self.from_gp else "addon_id",
         "atype": base.ADDON_PERSONA,
         "row": {},
     }
     if not self.cursor:
         self.conn = mypool.connect()
         self.cursor = self.conn.cursor()
Esempio n. 6
0
    def is_valid(self):
        # If you accessing this from unit tests, then before calling
        # is valid, you can assign your own cursor.
        if not self.cursor:
            self.conn = mypool.connect()
            self.cursor = self.conn.cursor()

        data = self.data
        # Version can be blank.
        data['version'] = data.get('version', '')
        for field in ['reqVersion', 'id', 'appID', 'appVersion']:
            if field not in data:
                return False

        app = applications.APP_GUIDS.get(data['appID'])
        if not app:
            return False

        data['app_id'] = app.id

        sql = """SELECT id, status, addontype_id, guid FROM addons
                 WHERE guid = %(guid)s AND
                       inactive = 0 AND
                       status NOT IN (%(STATUS_DELETED)s, %(STATUS_DISABLED)s)
                 LIMIT 1;"""
        self.cursor.execute(sql, {
            'guid': self.data['id'],
            'STATUS_DELETED': base.STATUS_DELETED,
            'STATUS_DISABLED': base.STATUS_DISABLED,
        })
        result = self.cursor.fetchone()
        if result is None:
            return False

        data['id'], data['addon_status'], data['type'], data['guid'] = result
        data['version_int'] = version_int(data['appVersion'])

        if 'appOS' in data:
            for k, v in PLATFORM_NAMES_TO_CONSTANTS.items():
                if k in data['appOS']:
                    data['appOS'] = v
                    break
            else:
                data['appOS'] = None

        return True
Esempio n. 7
0
    def is_valid(self):
        # If you accessing this from unit tests, then before calling
        # is valid, you can assign your own cursor.
        if not self.cursor:
            self.conn = mypool.connect()
            self.cursor = self.conn.cursor()

        data = self.data
        # Version can be blank.
        data['version'] = data.get('version', '')
        for field in ['reqVersion', 'id', 'appID', 'appVersion']:
            if field not in data:
                return False

        app = applications.APP_GUIDS.get(data['appID'])
        if not app:
            return False

        data['app_id'] = app.id

        sql = """SELECT `id`, `status`, `addontype_id`, `guid` FROM `addons`
                 WHERE `guid` = %(guid)s AND
                       `inactive` = 0 AND
                       `status` NOT IN (%(STATUS_DELETED)s, %(STATUS_DISABLED)s)
                 LIMIT 1;"""
        self.cursor.execute(
            sql,
            {
                'guid': self.data['id'],
                'STATUS_DELETED': base.STATUS_DELETED,
                'STATUS_DISABLED': base.STATUS_DISABLED,
            },
        )
        result = self.cursor.fetchone()
        if result is None:
            return False

        data['id'], data['addon_status'], data['type'], data['guid'] = result
        data['version_int'] = version_int(data['appVersion'])
        return True
Esempio n. 8
0
    def test_mypool_encoding(self):
        from services.utils import mypool

        connection = mypool.connect()
        assert connection.connection.encoding == 'utf8'
        connection.close()
Esempio n. 9
0
 def __init__(self, locale, id_, qs=None):
     self.from_gp = qs == 'src=gp'
     self.addon_id = id_
     self.cursor = mypool.connect().cursor()
Esempio n. 10
0
 def __init__(self, locale, id_, qs=None):
     self.from_gp = qs == 'src=gp'
     self.addon_id = id_
     self.cursor = mypool.connect().cursor()