Esempio n. 1
0
 def setUp(self):
     super().setUp()
     self.fixture = ApiKey()
     self.fixture.set_key("testkey")
     self.fixture.set_description("Test Key")
     self.db.add(self.fixture)
     self.db.commit()
Esempio n. 2
0
 def test_api_key(self):
     key = ApiKey()
     key.set_key("testkey")
     key.set_description("Test Key")
     self.db.add(key)
     self.fixture.add_api_key(key)
     self.db.commit()
     self.assertEqual(1, self.fixture.api_keys.count(), "counts are same")
     self.assertIn(key, self.fixture.api_keys, "key not found")
Esempio n. 3
0
class ApiKeyTest(BaseTest):
    def setUp(self):
        super().setUp()
        self.fixture = ApiKey()
        self.fixture.set_key("testkey")
        self.fixture.set_description("Test Key")
        self.db.add(self.fixture)
        self.db.commit()

    def test_id(self):
        self.assertEqual(1, self.fixture.get_id(), "id's do not match")

    def test_description(self):
        self.assertEqual("Test Key", self.fixture.get_description(),
                         "names do not match")

    def test_null_description(self):
        with self.assertRaises(Exception):
            self.fixture.set_description(None)

    def test_empty_description(self):
        with self.assertRaises(Exception):
            self.fixture.set_description("")

    def test_key_hashing(self):
        self.fixture.set_key('cat')
        self.assertFalse(self.fixture.check_key('dog'))
        self.assertTrue(self.fixture.check_key('cat'))

    def test_parent_user(self):
        user = User()
        user.set_first_name("First")
        user.set_last_name("Last")
        user.set_email("email")
        user.set_password("password")
        user.set_role(Role.USER)
        self.db.add(user)
        self.db.commit()
        user.add_api_key(self.fixture)
        self.assertEqual(user, self.fixture.user, "users are not the same")

    def test_parent_server(self):
        server = Server()
        server.set_name("Test")
        server.set_ip_address("127.0.0.1")
        server.set_port(5000)
        server.set_periodicity(5000)
        self.db.add(server)
        self.db.commit()
        server.add_api_key(self.fixture)
        self.assertEqual(server, self.fixture.server,
                         "servers are not the same")

    def test_to_dict(self):
        expected = {"id": 1, "description": "Test Key"}
        result = self.fixture.to_dict()
        self.assertDictEqual(expected, result, "dicts not the same")

    def test_update(self):
        expected = {"id": 1, "description": "Test Key2", "key": "New Key"}
        self.fixture.update(expected)
        self.assertEqual(expected["description"],
                         self.fixture.get_description())
        self.assertTrue(self.fixture.check_key(expected['key']))

    def test_create_from_json(self):
        expected = {"id": 1, "description": "Test Key2", "key": "New Key"}
        self.fixture = ApiKey(expected)
        self.assertEqual(expected["description"],
                         self.fixture.get_description())
        self.assertTrue(self.fixture.check_key(expected['key']))

    def test_repr(self):
        self.assertEqual("API Key: Test Key", self.fixture.__repr__(),
                         "repr not same")

    def test_str(self):
        self.assertEqual("API Key: Test Key", str(self.fixture),
                         "string representation not same")
Esempio n. 4
0
 def test_create_from_json(self):
     expected = {"id": 1, "description": "Test Key2", "key": "New Key"}
     self.fixture = ApiKey(expected)
     self.assertEqual(expected["description"],
                      self.fixture.get_description())
     self.assertTrue(self.fixture.check_key(expected['key']))