Ejemplo n.º 1
0
def test_show_articles_action(admin_client):
    topics = TopicFactory.create_batch(5)
    selected = choice(topics)
    ArticleFactory.create_batch(10)

    url = reverse("admin:lynx_topic_changelist")
    data = {
        "post": "yes",
        "_selected_action": [selected.pk],
        "action": "show_articles",
    }

    response = admin_client.post(url, data, follow=True)

    request = response.request
    slugs = selected.slug

    assert request["PATH_INFO"] == reverse("admin:lynx_article_changelist")
    assert request["QUERY_STRING"] == f"topics__slug__in={slugs}"
Ejemplo n.º 2
0
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()

            # delete geographic information
            Country.objects.all().delete()
            Region.objects.all().delete()
            Area.objects.all().delete()
            Place.objects.all().delete()

            User.objects.filter().exclude(is_superuser=True).delete()

        # create regional data
        places = list()
        for i in range(0, 10):
            places.append(PlaceFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(
                    name="Shelter" + str(random.randint(0, 9)),
                    place=places[random.randint(0,
                                                len(places) - 1)],
                    additional_info=LOREM)
                need = NeedFactory.create(starting_time=self.gen_date(hour=i -
                                                                      1,
                                                                      day=day),
                                          ending_time=self.gen_date(hour=i,
                                                                    day=day),
                                          topic=topic,
                                          location=location)
                # assign random volunteer for each need
                reg_user = ShiftHelperFactory.create(need=need)
                reg_user.save()
Ejemplo n.º 3
0
def test_merge_topics_action(admin_client):
    topics = TopicFactory.create_batch(5)
    article = ArticleFactory(topics=topics)
    selected = choice(topics)

    url = reverse("admin:lynx_topic_changelist")
    data = {
        "post": "yes",
        "_selected_action": [topic.pk for topic in topics],
        "action": "merge_topics",
        "selected": selected.pk,
    }

    admin_client.post(url, data, follow=True)

    # Merged topics are deleted
    actual = [topic.pk for topic in Topic.objects.all()]
    assert actual == [selected.pk]

    # Merged topics are replaced
    actual = [topic.pk for topic in article.topics.all()]
    assert actual == [selected.pk]
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()

            # delete geographic information
            Country.objects.all().delete()
            Region.objects.all().delete()
            Area.objects.all().delete()
            Place.objects.all().delete()

            User.objects.filter().exclude(is_superuser=True).delete()

        # create regional data
        places = list()
        for i in range(0,10):
            places.append(PlaceFactory.create())

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(
                    name="Shelter" + str(random.randint(0,9)),
                    place=places[random.randint(0,len(places)-1)],
                    additional_info=LOREM
                )
                need = NeedFactory.create(
                    starting_time=self.gen_date(hour=i-1, day=day),
                    ending_time=self.gen_date(hour=i, day=day),
                    topic=topic,
                    location=location
                )
                # assign random volunteer for each need
                reg_user = ShiftHelperFactory.create(need=need)
                reg_user.save()
Ejemplo n.º 5
0
    def handle(self, *args, **options):
        if options['flush']:
            print "delete all data in app tables"
            RegistrationProfile.objects.all().delete()
            Need.objects.all().delete()
            Location.objects.all().delete()
            Topics.objects.all().delete()
            User.objects.filter().exclude(is_superuser=True).delete()

        # create shifts for number of days
        for day in range(0, options['days'][0]):
            for i in range(2, 23):
                topic = TopicFactory.create(title=random.choice(HELPTOPICS))
                location = LocationFactory.create(name="Shelter" + str(random.randint(0,9)), additional_info=LOREM)
                need = NeedFactory.create(
                    starting_time=self.gen_date(hour=i-1, day=day),
                    ending_time=self.gen_date(hour=i, day=day),
                    topic=topic,
                    location=location
                )
                # assign random volunteer for each need
                reg_user = RegistrationProfileFactory.create()
                reg_user.needs.add(need)
                reg_user.save()
Ejemplo n.º 6
0
def articles(author):
    LabelFactory.create_batch(5)
    SourceFactory.create_batch(20)
    TopicFactory.create_batch(20)
    return ArticleFactory.create_batch(100, authors=[author])
Ejemplo n.º 7
0
def articles():
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    NotificationFactory.create_batch(20)
    return ArticleFactory.create_batch(100)
Ejemplo n.º 8
0
def articles(source):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(20)
    return ArticleFactory.create_batch(100, source=source)
Ejemplo n.º 9
0
def topic():
    return TopicFactory()
Ejemplo n.º 10
0
def topics():
    return TopicFactory.create_batch(100)
Ejemplo n.º 11
0
def articles(today):
    LabelFactory.create_batch(5)
    AuthorFactory.create_batch(10)
    TopicFactory.create_batch(10)
    SourceFactory.create_batch(10)
    return ArticleFactory.create_batch(10, date=today)