def test_all_items_are_flushed_to_executor( self, command_processor, executor, user_command, group_command ): config = CommandBuilder.configure( effective_user="******", total_instructions=5 ) command_processor.process( [config, user_command, user_command, group_command, group_command] ) executor.execute_batch.assert_has_calls( [ call( batch=[user_command, user_command], command_type=CommandType.UPSERT, data_type=DataType.USER, default_config=Any.dict(), ), call( batch=[group_command, group_command], command_type=CommandType.UPSERT, data_type=DataType.GROUP, default_config=Any.dict(), ), ] )
def test_command_serialisation_ok(self, commands): """A sanity check that hits most of the behavior of creation. This is a happy path check. We expect this to work.""" ndjson = BulkAPI.to_string(commands) lines = ndjson.strip().split("\n") command_data = [json.loads(line) for line in lines] assert len(command_data) == 4 assert command_data == [ ["configure", Any.dict()], ["upsert", { "data": Any.dict.containing({"type": "user"}) }], ["upsert", { "data": Any.dict.containing({"type": "group"}) }], [ "create", { "data": Any.dict.containing({"type": "group_membership"}) } ], ]
def test_record_result_calls_hook(self, svc): my_hook = Mock(return_value={"my_dict": 1}) svc.record_result(self.GRADING_ID, score=1.5, pre_record_hook=my_hook) my_hook.assert_called_once_with(request_body=Any.dict(), score=1.5) assert self.sent_pox_body()["replaceResultRequest"] == OrderedDict( {"my_dict": "1"})