Exemplo n.º 1
0
    def test_init_no_id(self):
        license = LicenseKey(name='name', key='key')

        self.assertIsNotNone(license)
        self.assertIsNone(license.id)
        self.assertEqual('name', license.name)
        self.assertEqual('key', license.key)
        self.assertEqual({'key': 'key', 'name': 'name'}, license.to_document())
Exemplo n.º 2
0
 def test_from_document_with_id(self):
     license2 = LicenseKey.from_document({'_id': '666'})
     self.assertIsNotNone(license2)
     self.assertIsNotNone(license2.id)
     self.assertEqual('666', license2.id)
     self.assertIsNone(license2.name)
     self.assertIsNone(license2.key)
Exemplo n.º 3
0
 def test_repr_id(self):
     license2 = LicenseKey.from_document({
         '_id': '666',
         'key': 'key',
         'name': 'name'
     })
     self.assertEquals("<LicenseKey(id='666', name='name', key='key')>",
                       str(license2))
Exemplo n.º 4
0
    def test_from_document(self):
        license1 = LicenseKey.from_document({'key': 'key', 'name': 'name'})
        self.assertIsNotNone(license1)
        self.assertIsNone(license1.id)
        self.assertEqual('name', license1.name)
        self.assertEqual('key', license1.key)

        license2 = LicenseKey.from_document({
            '_id': '666',
            'key': 'key',
            'name': 'name'
        })
        self.assertIsNotNone(license2)
        self.assertIsNotNone(license2.id)
        self.assertEqual('666', license2.id)
        self.assertEqual('666', license2.id)
        self.assertEqual('name', license2.name)
        self.assertEqual('key', license2.key)
Exemplo n.º 5
0
    def _process_license_key_line(self, line, verbose=False):
        line = line.strip()
        if line:
            if line.startswith('#') is False:
                splits = line.split("=")
                if len(splits) > 1:
                    key_name = splits[0].strip()
                    # If key has = signs in it, then combine all elements past the first
                    key = "".join(splits[1:]).strip()
                    if verbose is True:
                        print(key_name, "=", key)

                    licensekey = LicenseKey(name=key_name, key=key)
                    self.add_document(licensekey)
                    return True
                else:
                    YLogger.warning(self, "Invalid license key [%s]", line)

        return False
Exemplo n.º 6
0
 def add_licensekey(self, key_name, key):
     licensekey = LicenseKey(name=key_name, key=key)
     return self.add_document(licensekey)
Exemplo n.º 7
0
 def test_repr_no_id(self):
     license1 = LicenseKey.from_document({'key': 'key', 'name': 'name'})
     self.assertEquals("<LicenseKey(id='n/a', name='name', key='key')>",
                       str(license1))
Exemplo n.º 8
0
 def test_from_document_no_id(self):
     license1 = LicenseKey.from_document({'key': 'key', 'name': 'name'})
     self.assertIsNotNone(license1)
     self.assertIsNone(license1.id)
     self.assertEqual('name', license1.name)
     self.assertEqual('key', license1.key)