Exemplo n.º 1
0
class modelsTests(TestCase):
    def setUp(self):
        #populate database
        self.populate = Command()
        self.populate.handle()

    def test_Category(self):
        # They should be 5 categories called
        self.categories = Category.objects.all()
        self.assertEqual(5, len(self.categories))

    def test_Workflow(self):
        # They should be 13 workflows
        workflows = Workflow.objects.all()
        self.assertEqual(13, len(workflows))
        for workflow in workflows:
            categories = workflow.category.all()
            self.assertTrue(len(categories)>0)
            category = categories[0]
            try:
                Category.objects.get(slug=category.slug)
            except Category.DoesNotExist:
                self.assertTrue(False, "category: %s does not exist" %
                                category.slug )
            print("checked: %s" % workflow.name)
Exemplo n.º 2
0
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client   = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()
Exemplo n.º 3
0
class modelsTests(TestCase):
    def setUp(self):
        #populate database
        self.populate = Command()
        self.populate.handle()

    def test_Category(self):
        baseName = CATEGORY
        for itemName in self.populate.data[baseName]:
            try:
                object = Category.objects.get(name=itemName)
            except Category.DoesNotExist:
                self.assertTrue(False,
                                "%s: %s does not exist" % (baseName, itemName))
            print("checked: %s" % itemName)

    def test_User(self):
        baseName = USER
        for itemName in self.populate.data[baseName]:
            try:
                object = User.objects.get(username=itemName)
            except Category.DoesNotExist:
                self.assertTrue(False,
                                "%s: %s does not exist" % (baseName, itemName))
            print("checked: %s" % itemName)

    def test_Workflow(self):
        baseName = WORKFLOW
        for itemName in self.populate.data[baseName]:
            try:
                object = WorkFlow.objects.get(name=itemName)
            except Category.DoesNotExist:
                self.assertTrue(False,
                                "%s: %s does not exist" % (baseName, itemName))
            print("checked: %s" % itemName)
Exemplo n.º 4
0
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()

        #data is a pointer to workflow, users and categories names
        self.data = self.populate.getData()
    def populateDataBase(self):
        populate = Command()
        populate.handle()
        categories = Category.objects.all()
        self.CATEGORYNAME1 = categories[0].name
        self.CATEGORYNAME2 = categories[1].name

        workflows = WorkFlow.objects.all()
        self.workflow1 = workflows[0]
        self.categoryWorkflow1 = \
            Category.objects.filter(workflow=self.workflow1)[0]
Exemplo n.º 6
0
    def uploadWorkflow(self, workflowName, waitFor):
        self.find_element_by_link_text(LABEL_UPLOAD_WORFLOW, waitFor)# click on Upload workflow
        #fill form
        self.find_element_by_id(ID_NAME,"workflow_aaa")
        self.find_element_by_id(ID_KEYWORDS,"key1, key2, key3")
        populate = Command()
        self.find_element_by_id(ID_DESCRIPTION,populate.getParragraph(20,400))
        self.find_element_by_id(ID_VERSION,"1.2")
        self.find_select_element_by_id(ID_CATEGORY, workflowName)

        f=open("/tmp/workflow.json","w")
        f.write(populate.getJson())
        f.close()
        element = self.driver.find_element_by_id("id_json")
        element.send_keys("/tmp/workflow.json")

        self.find_element_by_name(LABEL_SUMIT_WORKFLOW)
Exemplo n.º 7
0
class FindTests(TestCase):
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client   = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()


    def test_0_workflow_list(self): #CHECK
        #firts check all workflows
        this_function_name = sys._getframe().f_code.co_name
        print ("executing: %s" % this_function_name)
        # WORKFLOW_LIST returns all  workflows
        # If you set follow = True the client will follow any redirects
        response = self._client.get(reverse(WORKFLOW_LIST),
                                    follow=True)

        # Check that all categories and workflow are in the returned page
        workflows = Workflow.objects.all()
        self.assertEqual(13, len(workflows))

        # if pagination implemented fill free to use
        # for workflow in workflows[:10]:
        for workflow in workflows:
            self.assertIn(workflow.name, str(response.content))
            print ("    assert: %s"%workflow.name)

    def test_1_workflow_category(self):
        # firts check all workflows related with a category
        print "executing: ", sys._getframe().f_code.co_name
        categories = Category.objects.all()
        category = categories[0]
        response = self._client.get(reverse(WORKFLOW_LIST_BY_CARTEGORY,
                                            kwargs={'category_slug':category.slug}))

        workflows = Workflow.objects.filter(category=category)
        for itemName in workflows:
            self.assertIn("%s</a>"%itemName.name,str(response.content))
            print("    assert: %s in %s" % (itemName.name, category.name))

        # django Q objects have being designed to make complex queries
        # in this case search for objects NOT equal to a given category
        workflows = Workflow.objects.filter(~Q(category=category))
        for itemName in workflows:
            self.assertNotIn("%s</a>"%itemName.name,str(response.content))
            print("    assert: %s NOT in %s" % (itemName.name, category.name))

    def test_2_workflow_detail(self):
        print "executing: ", sys._getframe().f_code.co_name
        # getworkflow detail
        baseName = WORKFLOW
        workflows = Workflow.objects.all()
        for workflow in workflows:
            response = self._client.get(reverse(WORKFLOW_DETAIL,
                                                kwargs={'id':workflow.id,
                                                        'slug':workflow.slug}))
            self.assertIn(KEYWORDS,str(response.content))
            self.assertIn(DESCRIPTION,str(response.content))
            self.assertIn(workflow.name,str(response.content))
            self.assertIn(workflow.description, response.content.decode("utf-8"))
            self.assertTrue(len(workflow.description) > 16 )
            print ("Assert workflow %s" % workflow)

    def test_4_workflow_search(self):
        #search for a workflow workflow_search/
        print "executing: ", sys._getframe().f_code.co_name
        workflows = Workflow.objects.all()
        for workflow in workflows:
            response = self._client.post(reverse(WORKFLOW_SEARCH),
                                                {'byName': 'byName',
                                                 'key': workflow.slug})
            print ("Search for workflow %s" % workflow.slug)
            self.assertIn(workflow.name,str(response.content))
            self.assertIn(workflow.description,
                          response.content.decode("utf-8"))
Exemplo n.º 8
0
 def setUp(self):
     #populate database
     self.populate = Command()
     self.populate.handle()
Exemplo n.º 9
0
class UploadTests(TestCase):
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()

        # data is a pointer to workflow, users and categories names
        # self.data = self.populate.getData()

    def test_0_form_workflow_add_manually(self):
        # test just the form
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file_dict = {
            NAME_JSON: SimpleUploadedFile(upload_file.name, upload_file.read())
        }

        # get category IDs for the select Category field
        categories = Category.objects.all()
        category0 = categories[0]
        category1 = categories[1]
        #category0 = Category.objects.get(name=self.data[CATEGORY][0])
        #category1 = Category.objects.get(name=self.data[CATEGORY][1])
        # new workflow name
        workFlowName = 'workflow999'
        data_dict = {
            NAME_NAME: workFlowName,
            NAME_CATEGORY: [category0.id, category1.id],
            NAME_KEYWORDS: self.populate.getParragraph(1, 14),
            NAME_DESCRIPTION: self.populate.getParragraph(23, 123),
            NAME_VERSION: '3.1415',
        }

        # form with fieldfields has two independent dictionaries
        form = WorkFlowFormBase(data=data_dict, files=file_dict)
        self.assertTrue(form.is_valid(), form.errors)
        if form.is_valid():
            file_data = form.cleaned_data["json"].read().decode("utf-8")
            # modify object json value
            form.instance.json = file_data
        newWorkflow = form.save()
        self.assertEqual(newWorkflow.name, workFlowName)

    def test_4_view_workflow_add_manually(self):
        # Now test views
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file = SimpleUploadedFile(upload_file.name, upload_file.read())

        workFlowName = 'workflow999'
        categories = Category.objects.all()
        category0 = categories[0]
        category1 = categories[1]
        #        category0 = Category.objects.get(name=self.data[CATEGORY][0])
        #        category1 = Category.objects.get(name=self.data[CATEGORY][1])

        version = '3.1415'
        response = self._client.post(reverse(WORKFLOW_ADD_MANUALLY),
                                     data={
                                         NAME_NAME:
                                         workFlowName,
                                         NAME_KEYWORDS:
                                         self.populate.getParragraph(1, 14),
                                         NAME_CATEGORY:
                                         [category0.id, category1.id],
                                         NAME_DESCRIPTION:
                                         self.populate.getParragraph(23, 123),
                                         NAME_VERSION:
                                         version,
                                         NAME_JSON:
                                         file
                                     })
        workflow = WorkFlow.objects.get(name=workFlowName)
        self.assertEqual(workflow.versionInit, version)
Exemplo n.º 10
0
class FindTests(TestCase):
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()

        #data is a pointer to workflow, users and categories names
        self.data = self.populate.getData()

    def test_0_workflow_list(self):
        #firts check all workflows
        print("test_workflow_list:")
        # WORKFLOW_LIST returns all  workflows
        # If you set follow = True the client will follow any redirects
        response = self._client.get(reverse(WORKFLOW_LIST), follow=True)

        # Check that all categories and workflow are in the returned page
        baseName = CATEGORY
        for itemName in self.data[baseName]:
            self.assertIn(itemName, str(response.content))
            print("    assert: %s" % itemName)
        baseName = WORKFLOW
        for itemName in self.data[baseName]:
            self.assertIn(itemName, str(response.content))
            print("    assert: %s" % itemName)

    def test_1_workflow_category(self):
        # firts check all workflows related with a category
        print("test_workflow_category")
        baseName = CATEGORY
        category = Category.objects.get(name=self.data[baseName][0])
        response = self._client.get(
            reverse(WORKFLOW_LIST_BY_CARTEGORY,
                    kwargs={'category_slug': category.slug}))

        workflows = WorkFlow.objects.filter(category=category)
        for itemName in workflows:
            self.assertIn("%s</a>" % itemName.name, str(response.content))
            print("    assert: %s in %s" % (itemName.name, category.name))

        # django Q objects have being designed to make complex queries
        # in this case search for objects NOT equal to a given category
        workflows = WorkFlow.objects.filter(~Q(category=category))
        for itemName in workflows:
            self.assertNotIn("%s</a>" % itemName.name, str(response.content))
            print("    assert: %s NOT in %s" % (itemName.name, category.name))

    def test_2_workflow_detail(self):
        print("test_workflow_detail.")
        # getworkflow detail
        baseName = WORKFLOW
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        print("    workflow %s has been seem %d times" %
              (workflow.name, workflow.views))
        response = self._client.get(
            reverse(WORKFLOW_DETAIL,
                    kwargs={
                        'id': workflow.id,
                        'slug': workflow.slug
                    }))
        self.assertIn(workflow.name, str(response.content))
        self.assertIn(workflow.description, response.content.decode("utf-8"))
        # get workflow detail again, viewsshould be 1
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        self.assertEqual(workflow.views, 1)
        print("    workflow %s has been seem %d times" %
              (workflow.name, workflow.views))
        response = self._client.get(
            reverse(WORKFLOW_DETAIL,
                    kwargs={
                        'id': workflow.id,
                        'slug': workflow.slug
                    }))
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        # get workflow detail again, views should be 2
        self.assertEqual(workflow.views, 2)
        print("    workflow %s has been seem %d times" %
              (workflow.name, workflow.views))

    def test_3_workflow_download(self):
        print("test_3_workflow_download.")
        baseName = WORKFLOW
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])

        # download workflow & get workflow again
        # downloads should be 1 after download
        print("    workflow %s has been seem %d times" %
              (workflow.name, workflow.downloads))
        self.assertEqual(workflow.downloads, 0)
        response = self._client.get(
            reverse(WORKFLOW_DOWNLOAD,
                    kwargs={
                        'id': workflow.id,
                        'slug': workflow.slug
                    }))
        # reload workflow
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        print("    workflow %s has been seem %d times" %
              (workflow.name, workflow.downloads))
        self.assertEqual(workflow.downloads, 1)
        self.assertIn(self.populate.getJson(),
                      response.content.decode("utf-8"))

        # try the non-count version of download
        # download should not be incremented
        response = self._client.get(
            reverse(WORKFLOW_DOWNLOAD_NO_COUNT,
                    kwargs={
                        'id': workflow.id,
                        'slug': workflow.slug
                    }))
        # reload workflow
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        print("    workflow %s has been seem %d times (No count)" %
              (workflow.name, workflow.downloads))
        self.assertEqual(workflow.downloads, 1)
        self.assertIn(self.populate.getJson(),
                      response.content.decode("utf-8"))

    def test_4_workflow_search(self):
        #search for a workflow workflow_search/
        print("test_4_workflow_search.")
        baseName = WORKFLOW
        workflow = WorkFlow.objects.get(name=self.data[baseName][0])
        response = self._client.post(reverse(WORKFLOW_SEARCH), {
            'byName': 'byName',
            'key': workflow.slug
        })
        print("   ByName search for workflow %s" % workflow.slug)
        self.assertIn(workflow.name, str(response.content))
        self.assertIn(workflow.description, response.content.decode("utf-8"))

        valueToSearch = workflow.keywords[:5]
        response = self._client.post(reverse(WORKFLOW_SEARCH), {
            'byKeyWord': 'byKeyWord',
            'key': workflow.slug
        })
        print("   ByKeyWord search for %s" % valueToSearch)
        self.assertIn(workflow.name, str(response.content))
Exemplo n.º 11
0
class UploadTests(TestCase):
    def setUp(self):
        # The test client is a Python class that acts as a dummy Web browser
        self._client = Client()

        # populate database
        self.populate = Command()
        self.populate.handle()

        # data is a pointer to workflow, users and categories names
        self.data = self.populate.getData()

    def test_0_form_workflow_add_manually(self):
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file_dict = {
            NAME_JSON: SimpleUploadedFile(upload_file.name, upload_file.read())
        }

        # get category IDs for the select Category field
        category0 = Category.objects.get(name=self.data[CATEGORY][0])
        category1 = Category.objects.get(name=self.data[CATEGORY][1])
        # new workflow name
        workFlowName = 'workflow999'
        data_dict = {
            NAME_NAME: workFlowName,
            NAME_CATEGORY: [category0.id, category1.id],
            NAME_KEYWORDS: self.populate.getParragraph(1, 14),
            NAME_DESCRIPTION: self.populate.getParragraph(23, 123),
            NAME_VERSION: '3.1415',
        }

        # form with fieldfields has two independent dictionaries
        form = WorkFlowManualForm(data=data_dict, files=file_dict)
        self.assertTrue(form.is_valid(), form.errors)
        if form.is_valid():
            file_data = form.cleaned_data["json"].read().decode("utf-8")
            # modify object json value
            form.instance.json = file_data
        newWorkflow = form.save()
        self.assertEqual(newWorkflow.name, workFlowName)

        # Note that we are ignoring recaptcha
        # there is no simple way to automatize it

    def test_1_form_workflowProgStep1_add(self):
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file_dict = {
            NAME_JSON: SimpleUploadedFile(upload_file.name, upload_file.read())
        }

        # new workflow name
        workFlowName = 'workflow999'
        data_dict = {
            NAME_VERSION: '3.141592',
        }
        # form with fieldfields has two independent dictionaries
        # we are testing the form not the views
        form = WorkFlowProgStep1Form(data=data_dict, files=file_dict)
        self.assertTrue(form.is_valid(), form.errors)

    def test_2_form_workflowProgStep2_add(self):
        # get category IDs for the select Category field
        category0 = Category.objects.get(name=self.data[CATEGORY][0])
        category1 = Category.objects.get(name=self.data[CATEGORY][1])
        # new workflow name
        workFlowName = 'workflow999'
        data_dict = {
            NAME_NAME: workFlowName,
            NAME_CATEGORY: [category0.id, category1.id],
            NAME_KEYWORDS: self.populate.getParragraph(1, 14),
            NAME_DESCRIPTION: self.populate.getParragraph(23, 123),
            NAME_VERSION: '3.1415',
        }

        # form with fieldfields has two independent dictionaries
        form = WorkFlowProgStep2Form(data=data_dict, )
        self.assertTrue(form.is_valid(), form.errors)
        if form.is_valid():
            file_data = self.populate.getJson()
            # modify object json 2alue
            form.instance.json = file_data
        newWorkflow = form.save()
        self.assertEqual(newWorkflow.name, workFlowName)

        # Note that we are ignoring recaptcha
        # there is no simple way to automatize it

    # Now test views

    def test_4_view_workflow_add_manually(self):
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file = SimpleUploadedFile(upload_file.name, upload_file.read())

        workFlowName = 'workflow999'
        category0 = Category.objects.get(name=self.data[CATEGORY][0])
        category1 = Category.objects.get(name=self.data[CATEGORY][1])

        version = '3.1415'
        response = self._client.post(reverse(WORKFLOW_ADD_MANUALLY),
                                     data={
                                         NAME_NAME:
                                         workFlowName,
                                         NAME_KEYWORDS:
                                         self.populate.getParragraph(1, 14),
                                         NAME_CATEGORY:
                                         [category0.id, category1.id],
                                         NAME_DESCRIPTION:
                                         self.populate.getParragraph(23, 123),
                                         NAME_VERSION:
                                         version,
                                         NAME_JSON:
                                         file
                                     })
        workflow = WorkFlow.objects.get(name=workFlowName)
        self.assertEqual(workflow.versionInit, version)

    def test_5_view_workflow_add_programatically(self):
        # create auxiliary json file
        jsonFileName = "/tmp/workflow.json"
        f = open(jsonFileName, "w")
        f.write(self.populate.getJson())
        f.close()
        upload_file = open(jsonFileName, "rb")
        file = SimpleUploadedFile(upload_file.name, upload_file.read())

        workFlowName = 'workflow999'
        category0 = Category.objects.get(name=self.data[CATEGORY][0])
        category1 = Category.objects.get(name=self.data[CATEGORY][1])

        version = '3.1415'
        response = self._client.post(reverse(WORKFLOW_PROG_STEP1),
                                     data={
                                         NAME_VERSION: version,
                                         NAME_JSON: file
                                     })
        self.assertIn("jsonFileName", response.content.decode("utf-8"))
        _dict = json.loads(response.content.decode("utf-8"))

        # call with GET (send filename)
        fileNameUrl = "?jsonFileName=%s&versionInit=%s" % \
                      (_dict['jsonFileName'], version)
        response = self._client.get(reverse(WORKFLOW_PROG_STEP2) + fileNameUrl)

        # workflow should not be available yet.
        try:
            workflow = WorkFlow.objects.get(name=workFlowName)
            self.assertTrue(False, "This workflow should not exist")
        except ObjectDoesNotExist:
            pass

        # call with POST (send metadata)
        response = self._client.post(
            reverse(WORKFLOW_PROG_STEP2),
            data={
                NAME_NAME: workFlowName,
                NAME_KEYWORDS: self.populate.getParragraph(1, 14),
                NAME_CATEGORY: [category0.id, category1.id],
                NAME_DESCRIPTION: self.populate.getParragraph(23, 123),
                NAME_VERSION: version,  # from json
                # NAME_JSON: file - in session variable
            })
        workflow = WorkFlow.objects.get(name=workFlowName)
        self.assertEqual(workflow.versionInit, version)
Exemplo n.º 12
0
 def populateDataBase(self):
     populate = Command()
     populate.handle()
     #data = populate.getData()
     self.CATEGORYNAME = (Category.objects.all()[0]).name
 def populateDataBase(self):
     populate = Command()
     populate.handle()
     data = populate.getData()
     self.CATEGORYNAME = data[CATEGORY][0]