def test_serialize_returns_dict_with_passed_values(self):
        expectedData = {
            'id': None,
            'accountType': AccountTypes.Dropbox,
            'identifier': 'MyIdentifier',
            'cryptoKey': 'sixteen byte key',
            'data': {
                "myDataKey": "myDataValue"
            }
        }

        testAccount = AccountData(**expectedData)
        serialized = testAccount.serialize()

        self.assertEqual(type(serialized), dict)
        self.assertEqual(serialized, expectedData)
Exemplo n.º 2
0
    def test_isFormValid_returns_false_on_missing_cryptoKey(self):
        testAccountSpecificData = {
            "type": "service_account",
            "project_id": "testID",
            "private_key_id": "testPrivKeyID",
            "private_key": "testPrivKey",
            "client_email": "testEmail",
            "client_id": "testClientID",
            "auth_uri": "testAuthUri",
            "token_uri": "testTokenUri",
            "auth_provider_x509_cert_url": "testCertProviderUri",
            "client_x509_cert_url": "testCertUri"
        }

        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.GoogleDrive,
                "identifier": "testAccount",
                "cryptoKey": "",
                "data": testAccountSpecificData,
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)

        self.assertFalse(self.testAccountForm.isFormValid())
Exemplo n.º 3
0
    def test_reset_clears_account_specific_data_and_only_that(self):
        testAccountSpecificData = {
            "type": "service_account",
            "project_id": "testID",
            "private_key_id": "testPrivKeyID",
            "private_key": "testPrivKey",
            "client_email": "testEmail",
            "client_id": "testClientID",
            "auth_uri": "testAuthUri",
            "token_uri": "testTokenUri",
            "auth_provider_x509_cert_url": "testCertProviderUri",
            "client_x509_cert_url": "testCertUri"
        }

        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.GoogleDrive,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": testAccountSpecificData,
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)
        self.testAccountForm.reset()

        componentAccountData = self.testAccountForm.getAccountData()
        self.assertEqual(componentAccountData.accountType,
                         testAccountData.accountType)
        self.assertEqual(componentAccountData.identifier, "")
        self.assertEqual(componentAccountData.cryptoKey, "")
        self.assertEqual(componentAccountData.data, {})
        self.assertEqual(componentAccountData.id, testAccountData.id)
Exemplo n.º 4
0
 def getAccountData(self):
     accountIdenfitifer = self._identifierInput.text().strip()
     cryptoKey = self._cryptoInput.text().strip()
     return AccountData(id=self._id,
                        accountType=self._accountType,
                        identifier=accountIdenfitifer,
                        cryptoKey=cryptoKey,
                        data=self.__formData)
Exemplo n.º 5
0
 def getAccountData(self):
     accountIdenfitifer = self._identifierInput.text().strip()
     apiToken = self._tokenInput.text().strip()
     cryptoKey = self._cryptoInput.text().strip()
     return AccountData(id=self._id,
                        accountType=self._accountType,
                        identifier=accountIdenfitifer,
                        cryptoKey=cryptoKey,
                        data={'apiToken': apiToken})
Exemplo n.º 6
0
 def __addBlankAccount(self):
     blankAccountData = AccountData(AccountTypes.Dropbox, "New Account", "",
                                    {"apiToken": ""})
     self.__addAccountWidget(blankAccountData)
     new_account_index = len(self.__accountCardWidgets) - 1
     self.__selectAccount(new_account_index)
     if len(self.__accountCardWidgets) == 8:
         self.__addAccountButton.hide()
     self.accountListValidityChanged.emit(False)
Exemplo n.º 7
0
    def test_isFormValid_returns_false_on_missing_drive_credentials(self):
        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.GoogleDrive,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": {},
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)

        self.assertFalse(self.testAccountForm.isFormValid())
Exemplo n.º 8
0
    def test_isFormValid_returns_false_on_missing_apiToken(self):
        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.Dropbox,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": {
                    "apiToken": ""
                },
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)

        self.assertFalse(self.testAccountForm.isFormValid())
Exemplo n.º 9
0
    def test_isFormValid_returns_true_on_valid_account_data(self):
        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.Dropbox,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": {
                    "apiToken": "testAPIToken"
                },
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)

        self.assertTrue(self.testAccountForm.isFormValid())
Exemplo n.º 10
0
 def __onAccountsRetrieved(self, response):
     serializedAccounts = [
         AccountData(id=raw['id'],
                     identifier=raw['identifier'],
                     accountType=raw['accountType'],
                     cryptoKey=raw['cryptoKey'],
                     data=raw['data']) for raw in response['accounts']
     ]
     self._serviceHub.networkStatusChannel.disconnect(
         self.__onNetworkStatusChanged)
     self._serviceHub.disconnectServer()
     self.__inited = True
     self.__accountsWidget.setAccounts(serializedAccounts)
     self.__loadingWidget.hide()
     self.__accountsWidget.show()
Exemplo n.º 11
0
    def test_callBack_sets_retrieved_account_list_into_underlying_accountListComponent(
            self, mockGetInstance, fakeAccountsWidget):
        testAccountData = AccountData(AccountTypes.Dropbox, "fakeAccount",
                                      "sixteen byte key",
                                      {"apiToken": "fakeAPIToken"}, 1)
        self.fakeAccountsWidget.accounts = [testAccountData]
        fakeAccountsWidget.return_value = self.fakeAccountsWidget
        fakeHub = MagicMock()
        mockGetInstance.return_value = fakeHub

        component = SetupAccountsWrapperWidget()
        accountData = component.getFormData()

        self.assertEqual(len(accountData), 1)

        self.assertEqual(testAccountData.accountType,
                         accountData[0].accountType)
        self.assertEqual(testAccountData.identifier, accountData[0].identifier)
        self.assertEqual(testAccountData.cryptoKey, accountData[0].cryptoKey)
        self.assertEqual(testAccountData.data, accountData[0].data)
        self.assertEqual(testAccountData.id, accountData[0].id)
Exemplo n.º 12
0
    def test_reset_clears_account_specific_data_and_only_that(self):
        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.Dropbox,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": {
                    "apiToken": "testAPIToken"
                },
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)
        self.testAccountForm.reset()

        componentAccountData = self.testAccountForm.getAccountData()

        self.assertEqual(componentAccountData.accountType,
                         testAccountData.accountType)
        self.assertEqual(componentAccountData.identifier, "")
        self.assertEqual(componentAccountData.cryptoKey, "")
        self.assertEqual(componentAccountData.data, {"apiToken": ""})
        self.assertEqual(componentAccountData.id, testAccountData.id)
Exemplo n.º 13
0
    def test_invalidate_removes_all_accounts_and_shows_loading_icon_and_resets_network_service(
            self, mockGetInstance, fakeAccountsWidget):
        testAccountData = AccountData(AccountTypes.Dropbox, "fakeAccount",
                                      "sixteen byte key",
                                      {"apiToken": "fakeAPIToken"}, 1)
        self.fakeAccountsWidget.accounts = [testAccountData]
        fakeAccountsWidget.return_value = self.fakeAccountsWidget
        fakeHub = MagicMock()
        fakeHub.isNetworkServiceRunning.return_value = True
        mockGetInstance.return_value = fakeHub

        component = SetupAccountsWrapperWidget()

        self.assertEqual(len(component.getFormData()),
                         len(self.fakeAccountsWidget.accounts))

        component.invalidate()

        self.assertEqual(self.fakeAccountsWidget.accounts, [])
        self.assertTrue(fakeHub.isNetworkServiceRunning.called)
        self.assertTrue(fakeHub.shutdownNetwork.called)
        self.assertTrue(fakeHub.initNetworkService.called)
Exemplo n.º 14
0
    def test_setAccountData_sets_data(self):
        testAccountData = AccountData(
            **{
                "accountType": AccountTypes.Dropbox,
                "identifier": "testAccount",
                "cryptoKey": "sixteen byte key",
                "data": {
                    "apiToken": "testAPIToken"
                },
                "id": 1
            })
        self.testAccountForm.setAccountData(testAccountData)

        componentAccountData = self.testAccountForm.getAccountData()

        self.assertEqual(testAccountData.accountType,
                         componentAccountData.accountType)
        self.assertEqual(testAccountData.identifier,
                         componentAccountData.identifier)
        self.assertEqual(testAccountData.cryptoKey,
                         componentAccountData.cryptoKey)
        self.assertEqual(testAccountData.data, componentAccountData.data)
        self.assertEqual(testAccountData.id, componentAccountData.id)
Exemplo n.º 15
0
 def setUp(self):
     fakeDriveCreds = {"client_email": "testEmail", "private_key": "fakePrivateKey"}
     testAccountData = AccountData(accountType=AccountTypes.GoogleDrive, identifier="testDriveAccount", cryptoKey="sixteen byte key", data=fakeDriveCreds)
     self.accountTester = DriveAccountTester(testAccountData)
Exemplo n.º 16
0
 def setUp(self):
     testAccountData = AccountData(accountType=AccountTypes.Dropbox, identifier="testDropboxAccount", cryptoKey="sixteen byte key", data={"apiToken": "testApiToken"})
     self.accountTester = DropboxAccountTester(testAccountData)