Exemple #1
0
 def test_project_to_codes(self):
     n = Code(filePathAndName="filename", created=timezone.now())
     n.save()
     p = Project(name="MyFirstProject",
                 creator=User.objects.get(username="******"),
                 create_date=timezone.now())
     p.save()
     n.projects.add(p)
     n.save()
     self.assertEqual(n.projects.all()[0].name, "MyFirstProject")
Exemple #2
0
 def test_codes_to_project(self):
     n2 = Code(
         filePathAndName = "filename",
         created = timezone.now()
     )
     n2.save()
     p2 = Project(
         name="MyFirstProject", 
         creator=User.objects.get(username="******"),
         create_date=timezone.now()
     )
     p2.save()
     p2.codes.add(n2)
     p2.save()
     self.assertEqual(n2.projects.all()[0].name,"MyFirstProject");
Exemple #3
0
 def test_project_to_codes(self):
     n = Code(
         filePathAndName = "filename",
         created = timezone.now()
     )
     n.save()
     p = Project(
         name="MyFirstProject", 
         creator=User.objects.get(username="******"),
         create_date=timezone.now()
     )
     p.save()
     n.projects.add(p)
     n.save()
     self.assertEqual(n.projects.all()[0].name,"MyFirstProject");
Exemple #4
0
 def test_page_to_project(self):
     p = Project(
         name="MyFirstProject",
         creator=User.objects.get(username="******"),
         create_date=timezone.now()
     )
     p.save()
     page = Page(
         page_name="pagename",
         page_create_date=timezone.now(),
         page_modify_date=timezone.now(),
     )
     page.save()
     p.page_set.add(page)
     p.save()
     self.assertEqual(p.page_set.all()[0].page_name,"pagename")
Exemple #5
0
    def test_project_contributors(self):

        user = User.objects.get(username="******")

        # Creating a project under anon and adding anon as a contributor
        p = Project(
            name="MyFirstProject", 
            creator=user,
            create_date=timezone.now()
         )
        p.save()
        p.contributors.add(user)
        p.save()

        # Check if anon is a contributor
        project = Project.objects.all().filter(creator=user)[0]
        self.assertEqual("anon",project.contributors.all()[0].username);
Exemple #6
0
 def test_projectcode_to_page(self):
     p = Project(name="MyFirstProject",
                 creator=User.objects.get(username="******"),
                 create_date=timezone.now())
     p.save()
     c = Code(filePathAndName="filename", created=timezone.now())
     c.save()
     page = Page(
         page_name="pagename",
         page_create_date=timezone.now(),
         page_modify_date=timezone.now(),
     )
     page.save()
     page.project = p
     page.code_set.add(c)
     page.save()
     self.assertEqual(page.project.name, "MyFirstProject")
     self.assertEqual(page.code_set.all()[0].filePathAndName, "filename")
Exemple #7
0
    def test_create_project(self):

        user = User.objects.get(username="******")

        # Creating a project under anon
        Project(name="MyFirstProject",
                creator=user,
                create_date=timezone.now()).save()

        # Check if project has been added to database
        project = Project.objects.all().filter(creator=user)[0]
        self.assertEqual("MyFirstProject", project.name)
Exemple #8
0
    def test_projectcode_to_page(self):
        p = Project(
            name="MyFirstProject",
            creator=User.objects.get(username="******"),
            create_date=timezone.now()
        )
        p.save()
        c = Code(
            filePathAndName="filename",
            created=timezone.now()

        )
        c.save()
        page = Page(
            page_name="pagename",
            page_create_date=timezone.now(),
            page_modify_date=timezone.now(),
        )
        page.save()
        page.project=p
        page.code_set.add(c)
        page.save()
        self.assertEqual(page.project.name,"MyFirstProject")
        self.assertEqual(page.code_set.all()[0].filePathAndName,"filename")
Exemple #9
0
 def test_codes_to_project(self):
     n2 = Code(filePathAndName="filename", created=timezone.now())
     n2.save()
     p2 = Project(name="MyFirstProject",
                  creator=User.objects.get(username="******"),
                  create_date=timezone.now())
     p2.save()
     p2.codes.add(n2)
     p2.save()
     self.assertEqual(n2.projects.all()[0].name, "MyFirstProject")
Exemple #10
0
 def test_page_to_project(self):
     p = Project(name="MyFirstProject",
                 creator=User.objects.get(username="******"),
                 create_date=timezone.now())
     p.save()
     page = Page(
         page_name="pagename",
         page_create_date=timezone.now(),
         page_modify_date=timezone.now(),
     )
     page.save()
     p.page_set.add(page)
     p.save()
     self.assertEqual(p.page_set.all()[0].page_name, "pagename")
Exemple #11
0
    def test_project_contributors(self):

        user = User.objects.get(username="******")

        # Creating a project under anon and adding anon as a contributor
        p = Project(name="MyFirstProject",
                    creator=user,
                    create_date=timezone.now())
        p.save()
        p.contributors.add(user)
        p.save()

        # Check if anon is a contributor
        project = Project.objects.all().filter(creator=user)[0]
        self.assertEqual("anon",
                         project.contributors.all()[0].username)
Exemple #12
0
def handle_user_post(operation, **kwargs):
    try:
        if operation == 'add': # Add a new project
            project = Project(
                name=kwargs['project_name'], 
                creator=kwargs['user'],
                hidden=kwargs['hidden'],
                create_date=timezone.now()
             )
            project.save()
            # project.contributors.add(kwargs['user'])
            # project.save()
        elif operation == 'rm': # Delete the given project and all associated pieces
            project = Project.objects.get(creator=kwargs['user'], name=kwargs['project_name']) # Specific project
            pages = Page.objects.all().filter(project=project)
            for page in pages:
                Code.objects.get(page=page).delete()
                page.delete()
            project.delete()
    except (User.DoesNotExist, Project.DoesNotExist, Page.DoesNotExist, Code.DoesNotExist):
        pass