Esempio n. 1
0
    def test_addMenuItem_incomplete(self):
        nc = NetworkController()
        data = {"id": "a", "name": "b"}

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error,
                         consts.ERROR_FAILED_DATABASE_ADD_INCOMPLETE_DATA)
Esempio n. 2
0
    def test_truncateProviders_good(self):
        nc = NetworkController()
        key = "AS62ELRB5F0709LERPHZD06JWC0P8QSC"

        response = nc.truncateProviders(key)
        self.assertEqual(response.error, consts.NO_ERROR)

        response = nc.getAllProviders(key)
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(len(response.payload), 0)
Esempio n. 3
0
    def test_truncateProviders_unauthorized(self):
        nc = NetworkController()

        key = "DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3"  # provider key
        response = nc.truncateProviders(key)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)

        key = "asd"  # invalid key
        response = nc.truncateProviders(key)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 4
0
    def test_setService_good(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "code": "b",
            "provider": "c",
            "member": "d",
            "comment": "e",
            "status": "f",
            "date": "g"
        }

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        nc.setService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a", {"name": "c"})
        response = nc.getService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)
        response.payload.pop("received")  # no way to know what this should be
        self.assertEqual(
            response.payload, {
                "id": "a",
                "code": "b",
                "provider": "c",
                "member": "d",
                "comment": "e",
                "status": "f",
                "date": "g"
            })
Esempio n. 5
0
    def test_setMember_duplicate(self):
        nc = NetworkController()

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMember(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "aaaa",
                "name": "b",
                "address": "c",
                "city": "d",
                "state": "e",
                "zip": "f",
                "status": consts.STATUS_UNBANNED
            })
        nc.addMember(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "bbbb",
                "name": "b",
                "address": "c",
                "city": "d",
                "state": "e",
                "zip": "f",
                "status": consts.STATUS_UNBANNED
            })
        response = nc.setMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "aaaa",
                                {"id": "bbbb"})
        self.assertEqual(response.error, consts.ERROR_DUPLICATE_ID)
Esempio n. 6
0
    def test_setMember_good(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f",
            "status": consts.STATUS_UNBANNED
        }

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        nc.setMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a", {"name": "c"})
        response = nc.getMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(
            response.payload, {
                "id": "a",
                "name": "c",
                "address": "c",
                "city": "d",
                "state": "e",
                "zip": "f",
                "status": consts.STATUS_UNBANNED
            })
Esempio n. 7
0
    def test_setService_duplicate(self):
        nc = NetworkController()

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addService(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "a",
                "code": "b",
                "provider": "c",
                "member": "d",
                "comment": "e",
                "status": "f",
                "date": "g"
            })
        nc.addService(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "b",
                "code": "b",
                "provider": "c",
                "member": "d",
                "comment": "e",
                "status": "f",
                "date": "g"
            })
        response = nc.setService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a",
                                 {"id": "b"})
        self.assertEqual(response.error, consts.ERROR_DUPLICATE_ID)
Esempio n. 8
0
    def test_addProvider_incomplete(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e"
        }

        nc.truncateProviders("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addProvider("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error,
                         consts.ERROR_FAILED_DATABASE_ADD_INCOMPLETE_DATA)
Esempio n. 9
0
    def test_setKey_goodByUnhashedUak(self):
        nc = NetworkController()
        data = {"id": "a", "level": "b", "name": "c"}

        nc.truncateKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        nc.setKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a", {"name": "c"})
        response = nc.getKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(response.payload["level"], "b")
        self.assertEqual(response.payload["name"], "c")
Esempio n. 10
0
    def test_addService_unauthorized(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "code": "b",
            "provider": "c",
            "member": "d",
            "comment": "e",
            "status": "f",
            "date": "g"
        }

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addService("asdf", data)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 11
0
    def test_addService_incomplete(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "code": "b",
            "provider": "c",
            "member": "d",
            "comment": "e",
            "status": "f"
        }

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error,
                         consts.ERROR_FAILED_DATABASE_ADD_INCOMPLETE_DATA)
Esempio n. 12
0
 def __init__(self, nc=""):
     # initialize the parent class with a NetworkController Object
     if nc == "":
         nc = NetworkController()
     super().__init__(nc)
     # defaults variables
     self.key = "Default"
Esempio n. 13
0
    def test_validateKeyGood(self):
        nc = NetworkController()
        key = "AS62ELRB5F0709LERPHZD06JWC0P8QSC"

        response = nc.validateKey(key)
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(response.payload, consts.KEY_ROOT)

        key = "DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3"
        response = nc.validateKey(key)
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(response.payload, consts.KEY_PROVIDER)

        key = "asdfasdf"
        response = nc.validateKey(key)
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(response.payload, consts.KEY_INVALID)
Esempio n. 14
0
    def test_setMenuItem_good(self):
        nc = NetworkController()
        data = {"id": "a", "name": "b", "fee": "100"}

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        nc.setMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a", {"name": "c"})
        response = nc.getMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(response.payload, {
            "id": "a",
            "name": "c",
            "fee": "100"
        })
Esempio n. 15
0
    def test_addMenuItem_unauthorized(self):
        nc = NetworkController()
        data = {"id": "a", "name": "b", "fee": "100"}

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addMenuItem("DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3", data)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addMenuItem("asdf", data)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 16
0
    def test_getKey_unauthorized(self):
        nc = NetworkController()
        data = {"id": "a", "level": "b", "name": "c"}

        nc.truncateKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.getKey("asdf", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 17
0
    def test_getMenuItem_nonexistent(self):
        nc = NetworkController()
        data = {"id": "a", "name": "b", "fee": "100"}

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.getMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "b")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 18
0
    def test_getKey_nonexistent(self):
        nc = NetworkController()
        data = {"id": "a", "level": "b", "name": "c"}

        nc.truncateKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.getKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "b")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 19
0
    def test_addMenuItem_duplicate(self):
        nc = NetworkController()
        data = {"id": "a", "name": "b", "fee": "100"}

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error, consts.ERROR_DUPLICATE_ID)
Esempio n. 20
0
    def test_removeKey_goodByHash(self):
        nc = NetworkController()

        nc.truncateKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
            "id": "a",
            "level": "b",
            "name": "c"
        })

        response = nc.getAllKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        id = response.payload[0]["id"]
        response = nc.removeKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", id)

        self.assertEqual(response.error, consts.NO_ERROR)
        response = nc.getAllKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        self.assertEqual(len(response.payload), 0)
Esempio n. 21
0
    def test_removeMenuItem_good(self):
        nc = NetworkController()

        nc.truncateMenu("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
            "id": "a",
            "name": "b",
            "fee": "100"
        })
        response = nc.removeMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)

        response = nc.getMenuItem("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 22
0
    def test_removeKey_unauthorized(self):
        nc = NetworkController()

        nc.truncateKeys("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addKey("AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
            "uak": "a",
            "level": "b",
            "name": "c"
        })
        response = nc.removeKey("DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)

        response = nc.removeKey("asd", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 23
0
    def test_addProvider_good(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f"
        }

        nc.truncateProviders("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addProvider("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error, consts.NO_ERROR)

        response = nc.getAllProviders("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        self.assertEqual(response.error, consts.NO_ERROR)
        self.assertEqual(len(response.payload), 1)
        self.assertEqual(
            response.payload[0], {
                "id": "a",
                "name": "b",
                "address": "c",
                "city": "d",
                "state": "e",
                "zip": "f"
            })
Esempio n. 24
0
    def test_removeMember_good(self):
        nc = NetworkController()

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMember(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "a",
                "name": "b",
                "address": "c",
                "city": "d",
                "state": "e",
                "zip": "f"
            })
        response = nc.removeMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)

        response = nc.getMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 25
0
    def test_addMember_unauthorized(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f"
        }

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addMember("DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3", data)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        response = nc.addMember("asdf", data)
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 26
0
    def test_addProvider_duplicate(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f"
        }

        nc.truncateProviders("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addProvider("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.addProvider("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        self.assertEqual(response.error, consts.ERROR_DUPLICATE_ID)
Esempio n. 27
0
    def test_getProvider_unauthorized(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f"
        }

        nc.truncateProviders("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addProvider("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.getProvider("asdf", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)
Esempio n. 28
0
    def test_getMember_nonexistent(self):
        nc = NetworkController()
        data = {
            "id": "a",
            "name": "b",
            "address": "c",
            "city": "d",
            "state": "e",
            "zip": "f"
        }

        nc.truncateMembers("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", data)
        response = nc.getMember("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "b")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 29
0
    def test_removeService_good(self):
        nc = NetworkController()

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addService(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "a",
                "code": "b",
                "provider": "c",
                "member": "d",
                "comment": "e",
                "status": "f",
                "date": "g"
            })
        response = nc.removeService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.NO_ERROR)

        response = nc.getService("AS62ELRB5F0709LERPHZD06JWC0P8QSC", "a")
        self.assertEqual(response.error, consts.ERROR_NONEXISTENT_ENTRY)
Esempio n. 30
0
    def test_removeService_unauthorized(self):
        nc = NetworkController()

        nc.truncateServices("AS62ELRB5F0709LERPHZD06JWC0P8QSC")
        nc.addService(
            "AS62ELRB5F0709LERPHZD06JWC0P8QSC", {
                "id": "a",
                "code": "b",
                "provider": "c",
                "member": "d",
                "comment": "e",
                "status": "f",
                "date": "g"
            })
        response = nc.removeService("DDPR0TG8EF760QR2J7IUF3UFIRXXL4E3", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)

        response = nc.removeService("asd", "a")
        self.assertEqual(response.error, consts.ERROR_UNAUTHORIZED_OPERATION)