Skip to content
Snippets Groups Projects
Select Git revision
  • dea90c87ea8c11a78aa4727187021311175645b8
  • test default protected
  • master protected
  • original
  • pirati-backup protected
  • beta-2
  • beta-1
  • v3.1.4
  • v3.1.3
  • v3.1.2
  • v3.1.1
  • v3.1.0
  • v3.0.16
  • v3.0.15
  • v3.0.14
  • v3.0.13
  • v3.0.12
  • v3.0.11
  • v3.0.10
  • v3.0.9
  • v3.0.8
  • v3.0.7
  • v3.0.6
  • v3.0.5
  • v3.0.4
25 results

0001_initial.py

Blame
  • test_authors.py 8.07 KiB
    import pytest
    
    from openlobby.core.models import User
    
    from ..dummy import prepare_reports
    from ..utils import call_api
    
    
    pytestmark = [pytest.mark.django_db, pytest.mark.usefixtures('django_es')]
    
    
    def test_all(client, snapshot):
        prepare_reports()
        User.objects.create(id=4, is_author=False, username='x')
        query = """
        query {
            authors {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    
    def test_first(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors (first: 2) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    
    def test_first_after(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors (first: 1, after: "MQ==") {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    
    def test_last(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors (last: 2) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    
    def test_last_before(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors (last: 1, before: "Mw==") {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    
    def test_with_reports(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors {
                edges {
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                        reports {
                            totalCount
                            edges {
                                cursor
                                node {
                                    id
                                    date
                                    published
                                    title
                                    body
                                    receivedBenefit
                                    providedBenefit
                                    ourParticipants
                                    otherParticipants
                                    isDraft
                                    extra
                                }
                            }
                        }
                    }
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    def test_sort_by_last_name(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors(sort: LAST_NAME) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    def test_sort_by_last_name_reversed(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors(sort: LAST_NAME, reversed: true) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    def test_sort_by_total_reports(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors(sort: TOTAL_REPORTS, reversed: false) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    def test_sort_by_total_reports_reversed(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors(sort: TOTAL_REPORTS, reversed: true) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)
    
    def test_sort_by_default_reversed(client, snapshot):
        prepare_reports()
        query = """
        query {
            authors(reversed: true) {
                totalCount
                edges {
                    cursor
                    node {
                        id
                        firstName
                        lastName
                        hasCollidingName
                        totalReports
                        extra
                    }
                }
                pageInfo {
                    hasPreviousPage
                    hasNextPage
                    startCursor
                    endCursor
                }
            }
        }
        """
        response = call_api(client, query)
        snapshot.assert_match(response)