Пример #1
0
class TestDepositAccountValidation(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address

        self.client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

    def test_that_exception_is_raised_when_ethereum_address_has_wrong_length(self):
        with pytest.raises(ValidationError) as exception_info:
            deposit_account = DepositAccount(
                client=self.client,
                ethereum_address=self.payer_ethereum_address + '1'
            )
            deposit_account.clean()
        self.assertIn('ethereum_address', exception_info.value.error_dict)

    def test_that_exception_is_raised_when_ethereum_address_has_wrong_type(self):
        with pytest.raises(ValidationError) as exception_info:
            deposit_account = DepositAccount(
                client=self.client,
                ethereum_address=b'x' * ETHEREUM_ADDRESS_LENGTH
            )
            deposit_account.clean()
        self.assertIn('ethereum_address', exception_info.value.error_dict)

    def test_that_exception_is_not_raised_when_ethereum_address_has_valid_length(self):
        deposit_account = DepositAccount(
            client=self.client,
            ethereum_address=self.payer_ethereum_address
        )
        deposit_account.clean()
        deposit_account.save()
Пример #2
0
    def post(self, request):

        # create user if not exist
        is_new = False
        soft_account = False
        url = "https://oauth2.googleapis.com/tokeninfo?id_token={}".format(
            request.data)
        request = requests.get(url)
        response = json.loads(request.text)
        google_internal_id = response.get('sub')
        if google_internal_id is None:
            return Response('Invalid Token', 400)
        try:
            user = GoogleIdUsers.objects.get(
                sub_google_id=google_internal_id).user
        except GoogleIdUsers.DoesNotExist:

            user = User()
            user.username = response.get('name')
            # provider random default password
            user.password = make_password(
                BaseUserManager().make_random_password())
            user.email = response.get('email')
            user.first_name = response.get('given_name')
            if response.get('family_name') is None:
                user.last_name = ""
            else:
                user.last_name = response.get('family_name')

            is_new = True
            user.save()

            google_sub = GoogleIdUsers()
            google_sub.sub_google_id = google_internal_id
            google_sub.user = user
            google_sub.save()
        try:
            client = Client.objects.get(user=user)
        except Client.DoesNotExist:
            client = Client()
            client.user = user
            client.photo = response.get('picture')
            client.phone = response.get('phone')

            if client.photo is None or client.phone is None:
                soft_account = True
            client.save()
        token = RefreshToken.for_user(
            user)  # generate token without username & password
        response = {
            "is_new": is_new,
            "completeRegistry": soft_account,
            "clientId": client.pk,
            "username": user.username,
            "access_token": str(token.access_token),
            "refresh_token": str(token),
            "user": format_client(client)
        }
        return Response(response)
Пример #3
0
 def handle(self, **options):
     tenant = Client(
         name='Master App.', entity='PF',
         subdomain='public', cpf_cnpj='11111111111',
         email='*****@*****.**'
     )
     tenant.save()
     print 'Ok, created a public schema!'
Пример #4
0
class TestDepositAccountValidation(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address

        self.client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

    def test_that_exception_is_not_raised_when_ethereum_address_has_valid_length(
            self):
        deposit_account = DepositAccount(
            client=self.client, ethereum_address=self.payer_ethereum_address)
        deposit_account.clean()
        deposit_account.save()
Пример #5
0
    def __init__(self):
        # create dummy_user
        user_model = get_user_model()
        dummy_user = user_model.objects.create_user(
                'test_user_username',
                '*****@*****.**',
                'test_password'
        )
        dummy_user.save()
        self.dummy_user = dummy_user

        # create human contact
        dummy_human = Humans()
        dummy_human.user = dummy_user
        dummy_human.department = 'management'
        dummy_human.department = 'general-manager'
        dummy_human.phone = '0123456789'
        dummy_human.address = 'dummy user test address'
        dummy_human.personal_email = '*****@*****.**'
        dummy_human.enrolled = datetime.now()
        dummy_human.save()
        self.dummy_human = dummy_human

        # create a dummy client
        dummy_client = Client()
        dummy_client.name = 'test_client_name'
        dummy_client.manager = self.dummy_human
        dummy_client.save()
        self.dummy_client = dummy_client

        # create a dummy brand
        dummy_brand = Brand()
        dummy_brand.name = 'brand_test_name'
        dummy_brand.client = self.dummy_client
        dummy_brand.save()
        self.dummy_brand = dummy_brand

        # create a dummy project
        dummy_project = Project()
        dummy_project.name = 'test_project_name'
        dummy_project.short_code = "test_prj_dir_name"
        dummy_project.client = self.dummy_client
        dummy_project.brand = self.dummy_brand
        self.dummy_project = dummy_project
Пример #6
0
class DiscardClaimBanksterTest(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        self.task_to_compute = self._get_deserialized_task_to_compute()

        self.client = Client(public_key_bytes=self.PROVIDER_PUBLIC_KEY)
        self.client.clean()
        self.client.save()

        self.deposit_account = DepositAccount()
        self.deposit_account.client = self.client
        self.deposit_account.ethereum_address = self.task_to_compute.requestor_ethereum_address
        self.deposit_account.clean()
        self.deposit_account.save()

        self.deposit_claim = DepositClaim()
        self.deposit_claim.payer_deposit_account = self.deposit_account
        self.deposit_claim.payee_ethereum_address = self.task_to_compute.provider_ethereum_address
        self.deposit_claim.concent_use_case = ConcentUseCase.FORCED_PAYMENT
        self.deposit_claim.amount = 1
        self.deposit_claim.closure_time = parse_timestamp_to_utc_datetime(
            get_current_utc_timestamp())
        self.deposit_claim.full_clean()
        self.deposit_claim.save()

    def test_that_discard_claim_should_return_false_and_not_remove_deposit_claim_if_tx_hash_is_none(
            self):
        claim_removed = discard_claim(self.deposit_claim)

        self.assertFalse(claim_removed)
        self.assertTrue(
            DepositClaim.objects.filter(pk=self.deposit_claim.pk).exists())

    def test_that_discard_claim_should_return_true_and_remove_deposit_claim_if_tx_hash_is_set(
            self):
        self.deposit_claim.tx_hash = 64 * '0'
        self.deposit_claim.clean()
        self.deposit_claim.save()

        claim_removed = discard_claim(self.deposit_claim)

        self.assertTrue(claim_removed)
        self.assertFalse(
            DepositClaim.objects.filter(pk=self.deposit_claim.pk).exists())
Пример #7
0
    def setUp(self):
        super().setUp()
        task_to_compute = self._get_deserialized_task_to_compute()
        self.payer_ethereum_address = task_to_compute.requestor_ethereum_address
        self.payee_ethereum_address = task_to_compute.provider_ethereum_address

        client = Client(public_key_bytes=self.REQUESTOR_PUBLIC_KEY)
        client.clean()
        client.save()

        self.payer_deposit_account = DepositAccount()
        self.payer_deposit_account.client = client
        self.payer_deposit_account.ethereum_address = task_to_compute.requestor_ethereum_address
        self.payer_deposit_account.clean()
        self.payer_deposit_account.save()

        self.deposit_claim = DepositClaim()
        self.deposit_claim.payer_deposit_account = self.payer_deposit_account
        self.deposit_claim.subtask_id = task_to_compute.subtask_id
        self.deposit_claim.payee_ethereum_address = self.payee_ethereum_address
        self.deposit_claim.concent_use_case = ConcentUseCase.FORCED_TASK_RESULT.value
        self.deposit_claim.amount = 1
        self.deposit_claim.tx_hash = encode_hex(MOCK_TRANSACTION.hash)
Пример #8
0
def register(request):
	error_message = False
	if request.POST:

		if request.POST['username']\
			and request.POST['password']\
			and request.POST['password']\
			and request.POST['first_name']\
			and request.POST['last_name']:
			try:
				user = User.objects.create_user(
					request.POST['username'].lower(),
					request.POST['email'].lower(),
					request.POST['password']
				)

				user.first_name = request.POST['first_name']
				user.last_name = request.POST['last_name']
				user.save()

				client = Client(user=user, created=timezone.now())
				client.save()

				user.backend = 'django.contrib.auth.backends.ModelBackend'
				login(request, user)
				return redirect('/dashboard')
			except ValueError as e:
				error_message = e
		else:
			error_message = 'Some fields are required.'

	context = {
		'error_message'	: error_message,
		'user'			: views.user_status(request),
		'shopping_cart'	: views.shopping_cart_status(request)
	}
	return render(request, 'user/register.html', context)
Пример #9
0
    def test_receive_should_accept_valid_message(self):
        message_timestamp = datetime.datetime.now(timezone.utc)
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        new_message.full_clean()
        new_message.save()

        client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.TYPE,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            task_to_compute=task_to_compute_message,
            report_computed_task=new_message,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']))
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.Receive.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()

        response = self.client.post(
            reverse('core:receive'),
            content_type='application/octet-stream',
            data=self._create_client_auth_message(REQUESTOR_PRIVATE_KEY,
                                                  REQUESTOR_PUBLIC_KEY),
        )
        decoded_response = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            new_message.task_id, decoded_response.report_computed_task.
            task_to_compute.compute_task_def['task_id'])
        self.assertEqual(
            new_message.subtask_id, decoded_response.report_computed_task.
            task_to_compute.compute_task_def['subtask_id'])
Пример #10
0
class SettleOverdueAcceptancesBanksterTest(ConcentIntegrationTestCase):
    def setUp(self):
        super().setUp()
        self.get_deposit_value_return_value_default = 15000
        self.task_to_compute = None
        self.subtask_results_accepted_list = None
        self.requestor_client = None
        self.requestor_deposit_account = None
        self.validate_list_of_transaction_mock = None
        self.get_deposit_value_mock = None
        self.get_list_of_payments_mock = None

    def create_subtask_results_accepted_list(self, price, number_of_items=1):
        self.task_to_compute = self._get_deserialized_task_to_compute(
            price=price)
        self.subtask_results_accepted_list = [
            self._get_deserialized_subtask_results_accepted(
                report_computed_task=self.
                _get_deserialized_report_computed_task(
                    timestamp="2018-02-04 10:00:05",
                    task_to_compute=self.task_to_compute))
            for _ in range(number_of_items)
        ]

    def create_client_and_related_deposit_account(self):
        self.requestor_client = Client(
            public_key=self.task_to_compute.requestor_id)
        self.requestor_client.full_clean()
        self.requestor_client.save()

        self.requestor_deposit_account = DepositAccount(
            client=self.requestor_client,
            ethereum_address=self.task_to_compute.requestor_ethereum_address,
        )
        self.requestor_deposit_account.full_clean()
        self.requestor_deposit_account.save()

    def create_deposit_claim(self, amount, tx_hash):
        deposit_claim = DepositClaim(
            payee_ethereum_address=self.task_to_compute.
            provider_ethereum_address,
            payer_deposit_account=self.requestor_deposit_account,
            amount=amount,
            concent_use_case=ConcentUseCase.FORCED_PAYMENT,
            tx_hash=tx_hash,
            closure_time=parse_timestamp_to_utc_datetime(
                get_current_utc_timestamp()),
        )
        deposit_claim.full_clean()
        deposit_claim.save()

    def call_settle_overdue_acceptances_with_mocked_sci_functions(
        self,
        get_deposit_value_return_value=None,
        get_list_of_payments_return_value=None,
    ):
        with freeze_time("2018-02-05 10:00:25"):
            with mock.patch(
                    'core.payments.bankster.validate_list_of_transaction_timestamp'
            ) as self.validate_list_of_transaction_mock:
                with mock.patch(
                        'core.payments.bankster.service.get_deposit_value',
                        return_value=(
                            get_deposit_value_return_value
                            if get_deposit_value_return_value is not None else
                            self.get_deposit_value_return_value_default),
                ) as self.get_deposit_value_mock:
                    with mock.patch(
                            'core.payments.bankster.service.get_list_of_payments',
                            side_effect=[
                                (get_list_of_payments_return_value
                                 if get_list_of_payments_return_value
                                 is not None else
                                 self._get_list_of_settlement_transactions()),
                                self._get_list_of_batch_transactions()
                            ],
                    ) as self.get_list_of_payments_mock:
                        claim_against_requestor = settle_overdue_acceptances(
                            requestor_ethereum_address=self.task_to_compute.
                            requestor_ethereum_address,
                            provider_ethereum_address=self.task_to_compute.
                            provider_ethereum_address,
                            acceptances=self.subtask_results_accepted_list,
                            requestor_public_key=hex_to_bytes_convert(
                                self.task_to_compute.requestor_public_key),
                        )

        return claim_against_requestor

    def assert_mocked_sci_functions_were_called(
            self, get_list_of_payments_call_count=2):
        self.get_deposit_value_mock.assert_called_once()
        self.validate_list_of_transaction_mock.assert_called_once()
        self.assertEqual(self.get_list_of_payments_mock.call_count,
                         get_list_of_payments_call_count)

    def test_that_settle_overdue_acceptances_should_raise_no_unsettled_tasks_exception_when_all_tasks_are_paid_off(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                     3000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000 (does not matter in this case)
        Requestor deposit value:                                15000 (does not matter in this case)

        Amount pending = 3000 - 3000 = 0
        """
        self.create_subtask_results_accepted_list(price=3000)

        with self.assertRaises(BanksterNoUnsettledTasksError):
            self.call_settle_overdue_acceptances_with_mocked_sci_functions()

        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_raise_too_small_requestor_deposit_exception_when_requestor_has_insufficient_funds(
            self):
        """
        In this test we have following calculations
        (functions are mocked, but values are set to better understand calculations):

        TaskToCompute price:                                    12000
        Sum of amounts from list of settlement transactions:    3000
        Sum of amounts from list of transactions:               4000
        Requestor deposit value:                                0
        """

        subtasks_collective_price = 12000
        already_paid_in_transactions = 3000 + 4000

        self.create_subtask_results_accepted_list(
            price=subtasks_collective_price)

        with mock.patch(
                'core.payments.bankster.find_unconfirmed_settlement_payments'):
            with mock.patch('core.payments.bankster.get_provider_payment_info',
                            return_value=(already_paid_in_transactions,
                                          subtasks_collective_price -
                                          already_paid_in_transactions)):
                with self.assertRaises(BanksterTooSmallRequestorDepositError):
                    self.call_settle_overdue_acceptances_with_mocked_sci_functions(
                        get_deposit_value_return_value=0, )

        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000

        Amount pending = 15000 - (3000 + 4000) = 8000
        Payable amount = min(15000, 8000) = 8000
        """
        self.create_subtask_results_accepted_list(price=15000)

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
        )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 8000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid_if_there_was_no_previous_settlement_transactions(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:        0
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                20000

        Amount pending = 15000 - 4000 = 11000
        Payable amount = min(11000, 20000) = 11000
        """
        self.create_subtask_results_accepted_list(price=15000)

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
            get_deposit_value_return_value=20000,
            get_list_of_payments_return_value=[],
        )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 11000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid_when_requesting_payment_for_multiple_subtasks(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                         2 x 7500 = 15000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000

        Amount pending = 15000 - (3000 + 4000) = 8000
        Payable amount = min(8000, 15000) = 8000
        """
        self.create_subtask_results_accepted_list(price=7500,
                                                  number_of_items=2)

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
        )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 8000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_available_on_requestor_deposit_if_it_is_greater_then_left_amount(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                 5000

        Amount pending = 15000 - (3000 + 4000) = 8000
        Payable amount = min(8000, 5000) = 5000
        """
        self.create_subtask_results_accepted_list(price=15000)

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
            get_deposit_value_return_value=5000, )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 5000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid_when_there_are_existing_claims(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:        0
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000
        Sum of existing claims:                                  7000

        Amount pending = 15000 - (4000 + 7000) = 4000
        Payable amount = min(4000, 15000) = 4000
        """
        self.create_subtask_results_accepted_list(price=15000)
        self.create_client_and_related_deposit_account()
        self.create_deposit_claim(
            amount=3000,
            tx_hash=64 * 'A',
        )
        self.create_deposit_claim(
            amount=4000,
            tx_hash=64 * 'B',
        )

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
            get_list_of_payments_return_value=[])

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 4000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid_when_there_are_both_existing_claims_and_payments(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000
        Sum of existing claims:                                  7000

        Amount pending = 15000 - (3000 + 4000 + 7000) = 1000
        Payable amount = min(1000, 15000) = 1000
        """
        self.create_subtask_results_accepted_list(price=15000)
        self.create_client_and_related_deposit_account()
        self.create_deposit_claim(
            amount=3000,
            tx_hash=64 * 'A',
        )
        self.create_deposit_claim(
            amount=4000,
            tx_hash=64 * 'B',
        )

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
        )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 1000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_return_claim_deposit_with_amount_paid_when_there_are_both_existing_claims_and_payments_with_the_same_transaction_hash(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:     2000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000
        Sum of existing claims:                                  6000

        Amount pending = 15000 - (2000 + 4000 + 6000 - 2000) = 5000  // (2000 from claim matching blockchain transaction is ignored)
        Payable amount = min(5000, 15000) = 5000
        """
        self.create_subtask_results_accepted_list(price=15000)
        self.create_client_and_related_deposit_account()

        with freeze_time("2018-02-05 10:00:25"):
            self.create_deposit_claim(
                amount=2000,
                tx_hash=MOCK_TRANSACTION_HASH,
            )

        self.create_deposit_claim(
            amount=4000,
            tx_hash=64 * 'B',
        )

        with freeze_time("2018-02-05 10:00:25"):
            list_of_payments_return_value = [
                self._create_settlement_payment_object(amount=2000, )
            ]

        claim_against_requestor = self.call_settle_overdue_acceptances_with_mocked_sci_functions(
            get_list_of_payments_return_value=list_of_payments_return_value, )

        self.assertIsNotNone(claim_against_requestor.tx_hash)
        self.assertEqual(claim_against_requestor.amount, 5000)
        self.assert_mocked_sci_functions_were_called()

    def test_that_settle_overdue_acceptances_should_raise_exception_if_transaction_from_blockchain_will_not_match_database_claim(
            self):
        """
        In this test we have following calculations:

        TaskToCompute price:                                    15000
        Sum of amounts from list of settlement transactions:     3000
        Sum of amounts from list of transactions:                4000
        Requestor deposit value:                                15000
        Sum of existing claims:                                  7000
        """
        self.create_subtask_results_accepted_list(price=15000)
        self.create_client_and_related_deposit_account()

        self.create_deposit_claim(
            amount=3000,
            tx_hash=MOCK_TRANSACTION_HASH,
        )

        with self.assertRaises(BanksterTransactionMismatchError):
            self.call_settle_overdue_acceptances_with_mocked_sci_functions()

        self.assert_mocked_sci_functions_were_called(
            get_list_of_payments_call_count=1)
Пример #11
0
def checkout(request):
	if not request.user.is_authenticated():
		return redirect('/user/login/')

	name = ''
	sumary = ''
	error_message = False
	total = 0
	currency = 'USD'
	cart = []
	if request.POST:
		name = request.POST['name']
		sumary = request.POST['sumary']
		if name and sumary:
			cart = request.session[settings.SHOPPING_CART_KEY]
			# Check client status
			client = Client.objects.filter(user__id = request.user.id)
			if client: # User is already registered as client
				client = client[0]
			else:
				client = Client(user=request.user, created=timezone.now())
				client.save()
			# Create story and events
			story = Story(
				client = client,
				name = name,
				sumary = sumary,
				created = timezone.now()
			)
			story.save()
			for ev in cart:
				place = Place.objects.get(pk=ev['place'])
				ev = complete_event(ev, place)
				event = Event(
					story = story,
					place = place,
					created = timezone.now(),
					start = ev['start'],
					end = ev['end']
				)
				event.save()
			del request.session[settings.SHOPPING_CART_KEY]
			return redirect('/story/' + str(story.id))

		else:
			error_message = 'Some fields are required.'

	if settings.SHOPPING_CART_KEY in request.session:
		cart = request.session[settings.SHOPPING_CART_KEY]
		i = 0
		for ev in cart:
			place = Place.objects.get(pk=ev['place'])
			ev['index'] = i
			ev = complete_event(ev, place)
			total += ev['price']
			i = i+1

	context = {
		'name'			: name,
		'sumary'		: sumary,
		'total'			: total,
		'currency'		: currency,
		'cart'			: cart,
		'error_message'	: error_message,
		'user'			: views.user_status(request),
		'shopping_cart'	: views.shopping_cart_status(request)
	}
	return render(request, 'story/checkout.html', context)
Пример #12
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = ComputeTaskDefFactory()
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.want_to_compute_task = WantToComputeTaskFactory(
            node_name=1,
            task_id=self._get_uuid(),
            perf_index=3,
            price=4,
            max_resource_size=5,
            max_memory_size=6,
            num_cores=7,
        )
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            want_to_compute_task=self.want_to_compute_task,
            provider_public_key=self._get_provider_hex_public_key(),
            requestor_public_key=self._get_requestor_hex_public_key(),
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.report_computed_task = message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute,
                size=self.size
            )
            self.force_golem_data = message.concents.ForceReportComputedTask(
                report_computed_task=self.report_computed_task
            )
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.type_,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(
            public_key_bytes=self.PROVIDER_PUBLIC_KEY
        )
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(
            public_key_bytes=self.REQUESTOR_PUBLIC_KEY
        )
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id                  = self.compute_task_def['task_id'],
            subtask_id               = self.compute_task_def['subtask_id'],
            report_computed_task     = new_message,
            task_to_compute          = task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            ack_report_computed_task = stored_ack_report_computed_task,
            state                    = Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider                 = client_provider,
            requestor                = client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(self.compute_task_def['deadline'])
        )
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()
Пример #13
0
    def test_receive_should_return_first_messages_in_order_they_were_added_to_queue_if_the_receive_queue_contains_only_force_report_and_its_past_deadline(self):
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.type_,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.tasks.AckReportComputedTask(
            report_computed_task=self.report_computed_task
        )

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(
            public_key_bytes=self.PROVIDER_PUBLIC_KEY
        )
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(
            public_key_bytes=self.REQUESTOR_PUBLIC_KEY
        )
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id                  = self.compute_task_def['task_id'],
            subtask_id               = self.compute_task_def['subtask_id'],
            report_computed_task     = new_message,
            task_to_compute          = task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            ack_report_computed_task = stored_ack_report_computed_task,
            state                    = Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider                 = client_provider,
            requestor                = client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(self.compute_task_def['deadline'])
        )
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.Receive.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()

        new_message_inbox_out_of_band = PendingResponse(
            response_type=PendingResponse.ResponseType.VerdictReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox_out_of_band.full_clean()
        new_message_inbox_out_of_band.save()

        with freeze_time("2017-11-17 12:00:00"):
            response = self.send_request(
                url='core:receive',
                data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            self.REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message, message.concents.ForceReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(decoded_message.timestamp, self._create_timestamp_from_string("2017-11-17 12:00:00"))
        self.assertEqual(decoded_message.report_computed_task.task_to_compute.compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(decoded_message.report_computed_task.task_to_compute.sig, self.task_to_compute.sig)

        with freeze_time("2017-11-17 12:00:00"):
            response = self.send_request(
                url='core:receive',
                data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            self.REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message, message.concents.VerdictReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(decoded_message.timestamp, self._create_timestamp_from_string("2017-11-17 12:00:00"))
        self.assertEqual(decoded_message.ack_report_computed_task.report_computed_task.task_to_compute.compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(decoded_message.ack_report_computed_task.report_computed_task.task_to_compute.sig,
                         self.task_to_compute.sig)
Пример #14
0
    def test_receive_should_accept_valid_message(self):
        message_timestamp = parse_timestamp_to_utc_datetime(get_current_utc_timestamp())
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.header.type_,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        new_message.full_clean()
        new_message.save()

        client_provider = Client(
            public_key_bytes=self.PROVIDER_PUBLIC_KEY
        )
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(
            public_key_bytes=self.REQUESTOR_PUBLIC_KEY
        )
        client_requestor.full_clean()
        client_requestor.save()

        want_to_compute_message = StoredMessage(
            type=self.want_to_compute_task.header.type_,
            timestamp=message_timestamp,
            data=self.want_to_compute_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        want_to_compute_message.full_clean()
        want_to_compute_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.header.type_,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
            protocol_version=settings.GOLEM_MESSAGES_VERSION,
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        subtask = Subtask(
            task_id                 = self.compute_task_def['task_id'],
            subtask_id              = self.compute_task_def['subtask_id'],
            task_to_compute         = task_to_compute_message,
            want_to_compute_task=want_to_compute_message,
            report_computed_task    = new_message,
            state                   = Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider                = client_provider,
            requestor               = client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(self.compute_task_def['deadline'])
        )
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.Receive.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()

        response = self.send_request(
            url='core:receive',
            data=self._create_client_auth_message(self.REQUESTOR_PRIVATE_KEY, self.REQUESTOR_PUBLIC_KEY),
        )
        decoded_response = load(
            response.content,
            self.REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
        )
        self.assertEqual(response.status_code, 200)
        self.assertEqual(new_message.task_id,
                         decoded_response.report_computed_task.task_to_compute.compute_task_def['task_id'])
        self.assertEqual(new_message.subtask_id,
                         decoded_response.report_computed_task.task_to_compute.compute_task_def['subtask_id'])
Пример #15
0
    def setUp(self):
        super().setUp()
        self.compute_task_def = message.ComputeTaskDef()
        self.compute_task_def['task_id'] = '1'
        self.compute_task_def['subtask_id'] = '1'
        self.compute_task_def['deadline'] = get_current_utc_timestamp() - 60
        self.task_to_compute = tasks.TaskToComputeFactory(
            compute_task_def=self.compute_task_def,
            provider_public_key=PROVIDER_PUBLIC_KEY,
            requestor_public_key=REQUESTOR_PUBLIC_KEY,
            price=0,
        )
        self.size = 58

        with freeze_time("2017-11-17 10:00:00"):
            self.force_golem_data = message.ForceReportComputedTask(
                report_computed_task=message.tasks.ReportComputedTask(
                    task_to_compute=self.task_to_compute, size=self.size))
        message_timestamp = datetime.datetime.now(timezone.utc)
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        new_message.full_clean()
        new_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.TYPE,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.AckReportComputedTask(
            report_computed_task=message.tasks.ReportComputedTask(
                task_to_compute=self.task_to_compute, ))

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            report_computed_task=new_message,
            task_to_compute=task_to_compute_message,
            ack_report_computed_task=stored_ack_report_computed_task,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']))
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()
Пример #16
0
    def test_receive_should_return_first_messages_in_order_they_were_added_to_queue_if_the_receive_queue_contains_only_force_report_and_its_past_deadline(
            self):
        message_timestamp = datetime.datetime.now(timezone.utc)
        new_message = StoredMessage(
            type=self.force_golem_data.report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=self.force_golem_data.report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        new_message.full_clean()
        new_message.save()

        task_to_compute_message = StoredMessage(
            type=self.task_to_compute.TYPE,
            timestamp=message_timestamp,
            data=self.task_to_compute.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        task_to_compute_message.full_clean()
        task_to_compute_message.save()

        ack_report_computed_task = message.AckReportComputedTask(
            report_computed_task=message.ReportComputedTask(
                task_to_compute=self.task_to_compute, ))

        stored_ack_report_computed_task = StoredMessage(
            type=ack_report_computed_task.TYPE,
            timestamp=message_timestamp,
            data=ack_report_computed_task.serialize(),
            task_id=self.compute_task_def['task_id'],  # pylint: disable=no-member
            subtask_id=self.compute_task_def['subtask_id'],  # pylint: disable=no-member
        )
        stored_ack_report_computed_task.full_clean()
        stored_ack_report_computed_task.save()

        client_provider = Client(public_key_bytes=PROVIDER_PUBLIC_KEY)
        client_provider.full_clean()
        client_provider.save()

        client_requestor = Client(public_key_bytes=REQUESTOR_PUBLIC_KEY)
        client_requestor.full_clean()
        client_requestor.save()

        subtask = Subtask(
            task_id=self.compute_task_def['task_id'],
            subtask_id=self.compute_task_def['subtask_id'],
            report_computed_task=new_message,
            task_to_compute=task_to_compute_message,
            ack_report_computed_task=stored_ack_report_computed_task,
            state=Subtask.SubtaskState.REPORTED.name,  # pylint: disable=no-member
            provider=client_provider,
            requestor=client_requestor,
            result_package_size=self.size,
            computation_deadline=parse_timestamp_to_utc_datetime(
                self.compute_task_def['deadline']))
        subtask.full_clean()
        subtask.save()

        new_message_inbox = PendingResponse(
            response_type=PendingResponse.ResponseType.ForceReportComputedTask.
            name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.Receive.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox.full_clean()
        new_message_inbox.save()

        new_message_inbox_out_of_band = PendingResponse(
            response_type=PendingResponse.ResponseType.
            VerdictReportComputedTask.name,  # pylint: disable=no-member
            client=client_requestor,
            queue=PendingResponse.Queue.ReceiveOutOfBand.name,  # pylint: disable=no-member
            subtask=subtask,
        )
        new_message_inbox_out_of_band.full_clean()
        new_message_inbox_out_of_band.save()

        with freeze_time("2017-11-17 12:00:00"):
            response = self.client.post(
                reverse('core:receive'),
                content_type='application/octet-stream',
                data=self._create_client_auth_message(REQUESTOR_PRIVATE_KEY,
                                                      REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message,
                              message.concents.ForceReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            decoded_message.timestamp,
            int(dateutil.parser.parse("2017-11-17 12:00:00").timestamp()))
        self.assertEqual(decoded_message.report_computed_task.task_to_compute.
                         compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(
            decoded_message.report_computed_task.task_to_compute.sig,
            self.task_to_compute.sig)

        with freeze_time("2017-11-17 12:00:00"):
            response = self.client.post(
                reverse('core:receive_out_of_band'),
                content_type='application/octet-stream',
                data=self._create_client_auth_message(REQUESTOR_PRIVATE_KEY,
                                                      REQUESTOR_PUBLIC_KEY),
            )

        decoded_message = load(
            response.content,
            REQUESTOR_PRIVATE_KEY,
            CONCENT_PUBLIC_KEY,
            check_time=False,
        )

        self.assertIsInstance(decoded_message,
                              message.concents.VerdictReportComputedTask)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(
            decoded_message.timestamp,
            int(dateutil.parser.parse("2017-11-17 12:00:00").timestamp()))
        self.assertEqual(decoded_message.ack_report_computed_task.
                         report_computed_task.task_to_compute.compute_task_def,
                         self.task_to_compute.compute_task_def)  # pylint: disable=no-member
        self.assertEqual(
            decoded_message.ack_report_computed_task.report_computed_task.
            task_to_compute.sig, self.task_to_compute.sig)
Пример #17
0
def populate():

    #Fashion House

    f1 = Fashion_House(fashion_name="Chanel", debrief_received=False)
    f2 = Fashion_House(fashion_name="Dior", debrief_received=True)
    f3 = Fashion_House(fashion_name="Lancel", debrief_received=False)
    f4 = Fashion_House(fashion_name="Gucci", debrief_received=False)
    f5 = Fashion_House(fashion_name="LVMH", debrief_received=True)
    f6 = Fashion_House(fashion_name="Louis Vuitton", debrief_received=True)

    f1.save()
    f2.save()
    f3.save()
    f4.save()
    f5.save()
    f6.save()

    # Event

    e1 = Event(title="Du style en croks",
               date_debut='2019-12-12T15:00:00Z',
               date_fin='2019-12-17T15:00:00Z',
               description=
               "Bienvenue a notre événement voici un sommaire des activites :",
               place="Paris",
               fashion_name=f1)
    e2 = Event(title="Hiver neige",
               date_debut='2020-11-12T15:00:00Z',
               date_fin='2020-11-17T15:00:00Z',
               description=
               "Bienvenue a notre événement voici un sommaire des activites :",
               place="Russie",
               fashion_name=f2)

    e1.save()
    e2.save()

    #One_to_One

    o1 = One_to_One(date='2019-12-12T15:00:00Z',
                    salon=10,
                    staff="Paul JP",
                    title=e1)
    o2 = One_to_One(date='2019-12-12T15:00:00Z',
                    salon=10,
                    staff="Marie JP",
                    title=e2)
    o3 = One_to_One(date='2019-12-12T15:00:00Z',
                    salon=10,
                    staff="Kevin JP",
                    title=e1)
    o4 = One_to_One(date='2019-12-12T15:00:00Z',
                    salon=10,
                    staff="Pierre JP",
                    title=e2)

    o1.save()
    o2.save()
    o3.save()
    o4.save()

    #Activity

    a1 = Activity(title="Restaut à la Giraffe ",
                  date_act='2019-12-13T00:00:00Z',
                  supplier_name="Chantal",
                  adress="89 rue de rivoli",
                  budget=100,
                  real_price=150,
                  cancelation_policy_deadline=48,
                  cancelation_policy_fees=0.8,
                  contact_name="Fabris",
                  phone_number="0604157343",
                  mail_adress="*****@*****.**",
                  status="cf",
                  typ_act="1")
    a2 = Activity(title="Tour Eiffel de nuit ",
                  date_act='2019-12-15T00:00:00Z',
                  supplier_name="Charly",
                  adress="17 rue des étudiants",
                  budget=200,
                  real_price=0,
                  cancelation_policy_deadline=72,
                  cancelation_policy_fees=0.6,
                  contact_name="Fabris",
                  phone_number="0604157343",
                  mail_adress="*****@*****.**",
                  status="cnf",
                  typ_act="2")
    a3 = Activity(title="Spa massage",
                  date_act='2019-12-17T00:00:00Z',
                  supplier_name="Joseph",
                  adress="50 rue de rivoli",
                  budget=1000,
                  real_price=800,
                  cancelation_policy_deadline=48,
                  cancelation_policy_fees=0.5,
                  contact_name="Fabris",
                  phone_number="0604157343",
                  mail_adress="*****@*****.**",
                  status="f",
                  typ_act="4")

    a1.save()
    a2.save()
    a3.save()

    #Concierge

    c1 = Concierge(login="******",
                   mdp="0001",
                   name="Jean",
                   last_name="Concierge")
    c2 = Concierge(login="******",
                   mdp="0002",
                   name="Kevin",
                   last_name="Concierge")
    c3 = Concierge(login="******",
                   mdp="0003",
                   name="Marie",
                   last_name="Concierge")

    c1.save()
    c2.save()
    c3.save()
    c1.list_events.add(e1, e2)
    c2.list_events.add(e1)
    c3.list_events.add(e2)

    #Chauffeur

    t1 = Chauffeur(name="Karim",
                   last_name="Uber",
                   langue="Fr",
                   lieu_depart="Paris Roissy",
                   lieu_arrivee="Carlton",
                   consigne="Ne pas perdre le client de vue",
                   horaire_chauffeur='2019-12-12T15:00:00Z')

    t1.save()

    #Hotel

    h1 = Hotel(reservation_nb=5,
               date_debut='2019-12-12T15:00:00Z',
               date_fin='2019-12-12T15:00:00Z',
               room_type="Suite Deluxe",
               tarif=500,
               estimated_budget=550,
               paid_by_JP=2,
               paid_by_client=3,
               night_booked_jp=2,
               night_booked_client=3,
               welcome_pack_arrived=True)

    h1.save()

    #Planning

    p1 = Planning(nights_booked=5,
                  digital_planning=True,
                  language="EN",
                  travel_fees=500)
    p2 = Planning(nights_booked=3, language="FR", travel_fees=500)
    p3 = Planning(nights_booked=2,
                  digital_planning=True,
                  language="EN",
                  travel_fees=2000)
    p4 = Planning(nights_booked=4,
                  digital_planning=True,
                  language="EN",
                  travel_fees=500)

    p2.save()
    p3.save()
    p4.save()
    p1.save()

    p1.list_activities.add(a1)
    p1.list_driver.add(t1)
    p1.list_hotel.add(h1)

    p2.list_activities.add(a2)
    p2.list_driver.add(t1)
    p2.list_hotel.add(h1)

    p3.list_activities.add(a3)
    p3.list_driver.add(t1)
    p3.list_hotel.add(h1)

    #Client

    cl1 = Client(name="Jacques",
                 last_name="Dupont",
                 zone="Asie",
                 contact_principal="*****@*****.**",
                 langue="En",
                 budget_jour=500,
                 budget_semaine=5000,
                 plan=p1,
                 date=o1,
                 telephone="0664587985",
                 date_arrival='2019-12-12T15:00:00Z',
                 date_leave='2019-12-17T15:00:00Z',
                 status='al')
    cl2 = Client(name="Hiba",
                 last_name="Beldi",
                 zone="Moyen-Orient",
                 langue="Arabe",
                 budget_jour=150,
                 budget_semaine=1500,
                 date=o2,
                 plan=p2,
                 telephone="0664152465",
                 date_arrival='2019-12-13T15:00:00Z',
                 date_leave='2019-12-16T15:00:00Z',
                 status='mn')
    cl3 = Client(name="Jérémie",
                 last_name="Bencini",
                 zone="Arctique",
                 langue="Anglais",
                 budget_jour=3000,
                 budget_semaine=30000,
                 date=o3,
                 plan=p3,
                 telephone="0668358476",
                 date_arrival='2019-12-11T15:00:00Z',
                 date_leave='2019-12-19T15:00:00Z',
                 status='mn')
    cl4 = Client(name="Diane",
                 last_name="Du Peloux",
                 zone="Afrique",
                 langue="Français",
                 budget_jour=300,
                 budget_semaine=3000,
                 date=o4,
                 plan=p4,
                 telephone="0542487945",
                 date_arrival='2019-12-14T15:00:00Z',
                 date_leave='2019-12-20T15:00:00Z',
                 status='al')

    cl1.save()
    cl2.save()
    cl3.save()
    cl4.save()

    cl1.title.add(e1)
    cl2.title.add(e1)
    cl3.title.add(e2)
    cl4.title.add(e2)

    #Hospitality_packs
    hp1 = Hospitality_Pack(collection="Printemps 2020",
                           horaires_dispo_concierge="Lundi-Dimance: 7h-23h",
                           title=e1)

    hp1.save()

    hp1.list_services.add(a1)