Esempio n. 1
0
    def test_dataset_sources(self):
        def qref():
            queue = formqueue_services.get_next(user)
            return queue.pk if queue else None

        user = auth_models.User.objects.create_user('u1')
        agent = core_factories.AgentFactory(title='Agent 7')
        dataset = core_factories.DatasetFactory(title='Dataset 14',
                                                agent=agent)

        resp = self.app.get('/datasets/agent-7/dataset-14/update/', user='******')
        resp.form['sources'] = 'New dataset\nhttp://example.com/1\n'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(
            resp.location,
            'http://localhost:80/datasets/create/?qref=%d' % qref())

        # Add first primary dataset
        resp = resp.follow()
        self.assertEqual(resp.form['title'].value, 'New dataset')
        self.assertEqual(resp.form['link'].value, '')
        resp.form['agent'] = agent.pk
        resp.form['maturity_level'] = '3'
        resp.form['description'] = 'Dataset 3.'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(
            resp.location,
            'http://localhost:80/datasets/create/?qref=%d' % qref())
        self.assertEqual(
            [ds.get_absolute_url() for ds in dataset.sources.all()], [
                '/datasets/agent-7/new-dataset/',
            ])

        # Add second primary dataset
        resp = resp.follow()
        self.assertEqual(resp.form['title'].value, '')
        self.assertEqual(resp.form['link'].value, 'http://example.com/1')
        resp.form['title'] = 'Example dataset'
        resp.form['agent'] = agent.pk
        resp.form['maturity_level'] = '3'
        resp.form['description'] = 'Example dataset.'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(qref(), None)
        self.assertEqual(resp.location,
                         'http://localhost:80/datasets/agent-7/dataset-14/')
        self.assertEqual(
            [ds.get_absolute_url() for ds in dataset.sources.all()], [
                '/datasets/agent-7/new-dataset/',
                '/datasets/agent-7/example-dataset/',
            ])
Esempio n. 2
0
    def test_dataset_like(self):
        auth_models.User.objects.create_user('u1')
        agent = core_factories.AgentFactory(title='Agent 1')
        dataset = core_factories.DatasetFactory(title='Ds 1', agent=agent)
        self.assertEqual(dataset.likes, 0)

        resp = self.app.get('/likes/dataset/%d/toggle/' % dataset.pk,
                            user='******')
        self.assertEqual(resp.json, {'status': 'ok'})
        self.assertEqual(get(dataset).likes, 1)

        resp = self.app.get('/likes/dataset/%d/toggle/' % dataset.pk,
                            user='******')
        self.assertEqual(resp.json, {'status': 'ok'})
        self.assertEqual(get(dataset).likes, 0)
Esempio n. 3
0
    def test_success(self):
        agent = core_factories.AgentFactory(title='Agent 1')
        dataset = core_factories.DatasetFactory(title='Dataset 1', agent=agent)

        data = {
            'title':
            'Project 1',
            'agent':
            agent.pk,
            'datasets': ('http://localhost:80/datasets/agent-1/dataset-1/\n'
                         'http://example.com/lint/to/dataset/\n'),
            'description':
            'Project description.',
        }
        form = frontpage_forms.ProjectForm(data)
        self.assertTrue(form.is_valid(), form.errors.as_text())
        self.assertEqual(form.cleaned_data['datasets'], [
            ('http://localhost:80/datasets/agent-1/dataset-1/', dataset),
            ('http://example.com/lint/to/dataset/', None),
        ])
Esempio n. 4
0
    def test_dataset_update(self):
        agent = core_factories.AgentFactory(title='Org 1')
        core_factories.DatasetFactory(title='My dataset',
                                      agent=agent,
                                      user=self.user)

        resp = self.app.get('/datasets/org-1/my-dataset/update/', user='******')
        resp.form['title'] = 'My dataset (updated)'
        resp.form['agent'] = agent.pk
        resp.form['maturity_level'] = '2'
        resp.form['link'] = 'http://example.com/updated/'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)

        dataset = core_models.Dataset.objects.get(agent__slug='org-1',
                                                  slug='my-dataset')
        self.assertEqual(dataset.title, 'My dataset (updated)')
        self.assertEqual(dataset.maturity_level, 2)
        self.assertEqual(dataset.link, 'http://example.com/updated/')
Esempio n. 5
0
    def test_update_project(self):
        def qref():
            queue = formqueue_services.get_next(user)
            return queue.pk if queue else None

        user = auth_models.User.objects.create_user('u1')
        agent = core_factories.AgentFactory(title='Agent 7')
        dataset = core_factories.DatasetFactory(title='Dataset 14',
                                                agent=agent)
        project = core_factories.ProjectFactory(title='My project',
                                                agent=agent)
        project.datasets.add(dataset)

        resp = self.app.get('/projects/agent-7/my-project/update/', user='******')
        resp.form['datasets'] = resp.form['datasets'].value + '\n' + (
            'New dataset\n')
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(
            resp.location,
            'http://localhost:80/datasets/create/?qref=%d' % qref())

        resp = resp.follow()
        self.assertEqual(resp.form['title'].value, 'New dataset')
        self.assertEqual(resp.form['link'].value, '')
        resp.form['agent'] = agent.pk
        resp.form['maturity_level'] = '3'
        resp.form['description'] = 'Dataset 3.'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(qref(), None)
        self.assertEqual(resp.location,
                         'http://localhost:80/projects/agent-7/my-project/')
        self.assertEqual(
            [ds.get_absolute_url() for ds in project.datasets.all()], [
                '/datasets/agent-7/dataset-14/',
                '/datasets/agent-7/new-dataset/',
            ])
Esempio n. 6
0
    def create(self, data):
        project_agent = core_factories.AgentFactory(title='Project agent')

        for agent, (dataset, stars, dataset_likes), (project,
                                                     project_likes) in data:
            try:
                agent = core_models.Agent.objects.get(title=agent)
            except core_models.Agent.DoesNotExist:
                agent = core_factories.AgentFactory(title=agent)

            try:
                dataset = core_models.Dataset.objects.get(title=dataset)
            except core_models.Dataset.DoesNotExist:
                dataset = core_factories.DatasetFactory(
                    title=dataset,
                    agent=agent,
                    maturity_level=stars,
                    likes=dataset_likes,
                )
            else:
                self.assertEqual(dataset.agent_id, agent.pk)
                self.assertEqual(dataset.maturity_level, stars)
                self.assertEqual(dataset.likes, dataset_likes)

            if project != 'NN':
                try:
                    project = core_models.Project.objects.get(title=project)
                except core_models.Project.DoesNotExist:
                    project = core_factories.ProjectFactory(
                        title=project,
                        agent=project_agent,
                        likes=project_likes)
                else:
                    self.assertEqual(project.agent_id, project_agent.pk)
                    self.assertEqual(project.likes, project_likes)

                project.datasets.add(dataset)
Esempio n. 7
0
    def test_queue(self):  # pylint: disable=too-many-statements
        def qref():
            queue = formqueue_services.get_next(user)
            return queue.pk if queue else None

        user = auth_models.User.objects.create_user('u1')

        # Project form
        resp = self.app.get('/projects/create/', user='******')
        resp.form['title'] = 'My project'
        resp.form['agent'] = 'Org 1'
        resp.form['description'] = 'My project description.'
        resp.form['datasets'] = ('New dataset\n'
                                 'http://example.com/dataset/1\n')
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(
            resp.location,
            'http://localhost:80/datasets/create/?qref=%d' % qref())
        self.assertEqual(
            list(
                core_models.Project.objects.values_list(
                    'slug', 'title', 'agent__title')), [
                        ('my-project', 'My project', 'Org 1'),
                    ])

        project = core_models.Project.objects.get(slug='my-project')
        self.assertEqual(
            list(project.datasets.values_list('title', flat=True)), [])

        # First dataset form
        resp = resp.follow()
        self.assertEqual(resp.form['title'].value, 'New dataset')
        self.assertEqual(resp.form['link'].value, '')
        resp.form['agent'] = 'Org 2'
        resp.form['maturity_level'] = '3'
        resp.form['link'] = 'http://example.com/dataset/2'
        resp.form['description'] = 'New dataset.'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(
            resp.location,
            'http://localhost:80/datasets/create/?qref=%d' % qref())
        self.assertEqual(
            list(
                core_models.Dataset.objects.values_list(
                    'slug', 'title', 'agent__title')), [
                        ('new-dataset', 'New dataset', 'Org 2'),
                    ])

        project = core_models.Project.objects.get(slug='my-project')
        self.assertEqual(
            list(project.datasets.values_list('title', flat=True)),
            ['New dataset'])

        # Second dataset form
        resp = resp.follow()
        self.assertEqual(resp.form['title'].value, '')
        self.assertEqual(resp.form['link'].value,
                         'http://example.com/dataset/1')
        resp.form['title'] = 'Dataset 2'
        resp.form['agent'] = str(
            core_models.Agent.objects.get(title='Org 2').pk)
        resp.form['maturity_level'] = '3'
        resp.form['description'] = 'Dataset 2.'
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(qref(), None)
        self.assertEqual(resp.location,
                         'http://localhost:80/projects/org-1/my-project/')

        qs = core_models.Dataset.objects.order_by('slug')
        self.assertEqual(list(qs.values_list('slug', 'title', 'agent__title')),
                         [
                             ('dataset-2', 'Dataset 2', 'Org 2'),
                             ('new-dataset', 'New dataset', 'Org 2'),
                         ])

        project = core_models.Project.objects.get(slug='my-project')
        self.assertEqual(
            list(project.datasets.values_list('title', flat=True)),
            ['New dataset', 'Dataset 2'])
        self.assertEqual(project.user.username, user.username)

        # Update existing project
        agent = core_factories.AgentFactory(title='Agent 7')
        dataset = core_factories.DatasetFactory(title='Dataset 14',
                                                agent=agent)
        resp = self.app.get(project.get_absolute_url() + 'update/', user='******')
        self.assertEqual(resp.form['datasets'].value,
                         ('http://localhost:80/datasets/org-2/new-dataset/\n'
                          'http://localhost:80/datasets/org-2/dataset-2/\n'))

        resp.form['title'] = 'My project (updated)'
        resp.form['datasets'] = (
            'http://localhost:80/datasets/org-2/dataset-2/\n'
            'http://localhost:80%s\n' % dataset.get_absolute_url())
        resp = resp.form.submit()

        self.assertEqual(resp.status_int, 302)
        self.assertEqual(qref(), None)
        self.assertEqual(resp.location,
                         'http://localhost:80/projects/org-1/my-project/')

        project = core_models.Project.objects.get(slug='my-project')
        dataset_urls = [ds.get_absolute_url() for ds in project.datasets.all()]
        self.assertEqual(dataset_urls, [
            '/datasets/org-2/dataset-2/',
            dataset.get_absolute_url(),
        ])
Esempio n. 8
0
def populatedb():
    user = auth_models.User.objects.create_superuser(
        'superuser',
        '*****@*****.**',
        'secret',
        first_name='Super',
        last_name='User',
    )

    agent = core_factories.AgentFactory(title='Agent', user=user)

    seimas = core_factories.AgentFactory(title='Lietuvos Respublikos Seimas',
                                         user=user)
    ta = core_factories.DatasetFactory(title='Teisės aktų duomenys',
                                       maturity_level=1,
                                       agent=seimas,
                                       user=user)
    bd = core_factories.DatasetFactory(title='Balsavimų duomenys',
                                       maturity_level=1,
                                       agent=seimas,
                                       user=user)
    sn = core_factories.DatasetFactory(title='Seimo narių duomenys',
                                       maturity_level=1,
                                       agent=seimas,
                                       user=user)
    sd = core_factories.DatasetFactory(title='Seimo darbotvarkės duomenys',
                                       maturity_level=0,
                                       agent=seimas,
                                       user=user)

    rc = core_factories.AgentFactory(title='Registrų Centras', user=user)
    ad = core_factories.DatasetFactory(title='Adresų duomenys',
                                       maturity_level=0,
                                       agent=rc,
                                       user=user)

    archyvas = core_factories.AgentFactory(title='Lietuvos Istorijos Archyvas',
                                           user=user)
    md = core_factories.DatasetFactory(
        title='Gimimo, Mirties ir Santuokos metrikai',
        maturity_level=1,
        agent=archyvas,
        user=user)

    ms = core_factories.ProjectFactory(title='manoSeimas.lt',
                                       description='Aprašymas.',
                                       agent=agent,
                                       user=user)
    ms.datasets.add(ta)
    ms.datasets.add(bd)
    ms.datasets.add(sn)
    ms.datasets.add(sd)
    ms.datasets.add(ad)

    teisynas = core_factories.ProjectFactory(title='teisynas.lt',
                                             description='Aprašymas.',
                                             agent=agent,
                                             user=user)
    teisynas.datasets.add(ta)
    teisynas.datasets.add(sn)

    osm = core_factories.ProjectFactory(title='Open Street Map',
                                        description='Atviras žemėlapis',
                                        agent=agent,
                                        user=user)
    osm.datasets.add(ad)

    mskaitm = core_factories.ProjectFactory(
        title='Metrikų skaitmeninimas',
        description='Metrikų skaitmeninimas.',
        agent=agent,
        user=user)
    mskaitm.datasets.add(md)
    mskaitm.datasets.add(ad)
Esempio n. 9
0
    def test_dataset_details(self):
        agent = core_factories.AgentFactory(title='Org 1')
        core_factories.DatasetFactory(title='My dataset', agent=agent)

        self.app.get('/datasets/org-1/my-dataset/', user='******')