def test_import_success(self, mock_config, mock_get): """If the bot is created we return 201 and bot info with AIID.""" # Configure the mock mock_get.return_value = self.created mock_config.return_value = {'API_LONG_POLLING': 300} response = post_import_ai( self.token, factory.build(dict, FACTORY_CLASS=AIImportJSON)) self.assertEqual(response['status']['code'], 201) self.assertEqual(self.created['aiid'], response['aiid'])
def test_anonymous(self, mock_config, mock_get): """Anonymous user shouldn't be able to POST""" mock_config.return_value = {'API_LONG_POLLING': 300} # Configure the mock mock_get.return_value = factory.build( dict, FACTORY_CLASS=UnauthorizedFactory) response = post_import_ai(False, {}) self.assertEqual(response['status']['code'], 401)
def test_registered(self, mock_config, mock_get): """Registered user can POST an Import JSON""" mock_config.return_value = {'API_LONG_POLLING': 300} # Configure the mock mock_get.return_value = factory.build(dict, FACTORY_CLASS=SuccessFactory) response = post_import_ai(self.token, {}) self.assertEqual(response['status']['code'], 201)
def test_import_existing_name(self, mock_config, mock_get): """ If a bot with the same name exists, API returns information about it """ mock_config.return_value = {'API_LONG_POLLING': 300} # Configure the mock mock_get.return_value = factory.build(dict, FACTORY_CLASS=NameExistsFactory) response = post_import_ai( self.token, factory.build(dict, FACTORY_CLASS=AIImportJSON)) self.assertEqual(response['status']['code'], 400) self.assertEqual(response['status']['info'], 'A bot with that name already exists')
def save(self, *args, **kwargs): data = self.cleaned_data['ai_data'] return post_import_ai(ai_data=data, **kwargs)