Ejemplo n.º 1
0
 def test_user_accounts_query(self):
     response = graphql_query('''
         query{
           userAccounts{
             name
           }
         }
         ''',
                              client=self.client)
     content = json.loads(response.content)
     self.assertResponseNoErrors(response)
     self.assertEqual('testAccount',
                      content['data']['userAccounts'][0]['name'])
Ejemplo n.º 2
0
    def query(self, query, user=None, **kwargs):
        if user is not None:
            self.client.login(username=user.username, password=user.username)

        response = graphql_query(
            query,
            client=self.client,
            graphql_url='/graphql/',
            **kwargs,
        )

        if user is not None:
            self.client.logout()

        return response
Ejemplo n.º 3
0
def test_cur_user_info_query_not_auth(client):
    res = graphql_query(
        '''
        query {
            curUserInfo {
                id
                username
            }
        }
        ''',
        client=client,
    )
    assert res.status_code == 200
    content = json.loads(res.content)
    assert 'errors' in content
Ejemplo n.º 4
0
def test_get_all_configurations(
    client: Client,
    db: MockFixture,
) -> None:
    configurations = [ConfigurationFactory() for _ in range(2)]
    expected_configurations = {
        (configuration.id, configuration.name)
        for configuration in configurations
    }
    response = graphql_query(
        """
        query {
            configurations {
                id
                name
                Producers {
                    id
                    name
                    parameters
                }
                Consumers {
                    id
                    name
                    parameters
                }
                users {
                    id
                }
                MessageFilters {
                    id
                }
            }
        }
        """,
        client=client,
    )
    content = json.loads(response.content)

    assert 'errors' not in content

    actual_configurations = {
        (int(configuration['id']), configuration['name'])
        for configuration in content['data']['configurations']
    }

    assert actual_configurations == expected_configurations
Ejemplo n.º 5
0
def test_create_configuration(
    db: MockFixture,
    client: Client,
) -> None:
    producers = [ProducerModelFactory() for _ in range(2)]
    consumers = [ConsumerModelFactory() for _ in range(2)]
    users = [UserFactory() for _ in range(2)]
    response = graphql_query(
        """
        mutation {
            configuration(
                input: {
                    name: "fuck_muasdltiplit"
                    Consumers: [""" + ','.join(str(consumer.id) for consumer in consumers) + """]
                    Producers: [""" + ','.join(str(producer.id) for producer in producers) + """]
                    users: [""" + ','.join(str(user.id) for user in users) + """]
                }
            ) {
            configuration {
                id
                name
                Producers {
                    id
                }
                Consumers {
                    id
                }
                users {
                    id
                }
                MessageFilters {
                    id
                }
            }
            }
        }
        """,
        client=client,
    )
    content = json.loads(response.content)

    assert 'errors' not in content
 def func(*args, **kwargs):
     return graphql_query(*args, **kwargs, client=client)
 def graphql_query_with_client(*args, **kwargs):
     return graphql_query(*args, **kwargs, client=client)
Ejemplo n.º 8
0
 def wrapper(*args, **kwargs):
     return graphql_query(*args, **kwargs, client=client)
Ejemplo n.º 9
0
 def func(*args, **kwargs):
     return graphql_query(*args,
                          **kwargs,
                          client=admin_client,
                          graphql_url='/universe')
Ejemplo n.º 10
0
 def func(*args, **kwargs):
     return graphql_query(*args, **kwargs, client=client, headers=auth_headers)
Ejemplo n.º 11
0
def client_query(client):
    """Create GraphQL django client."""
    return lambda *args, **kwargs: graphql_query(
        *args, **kwargs, client=client)
Ejemplo n.º 12
0
 def __init__(self, query: str, variables={}):
     self.response = graphql_query(query, variables=variables)
     self.content = loads(self.response.content)