Exemplo n.º 1
0
    def test_register_mutation_nonunique_email(self):
        request = self.request()
        query = """
        mutation {
          register(
                email: "*****@*****.**",
                password: "******",
            )
          {
            ok
            errors
          }
        }
        """

        expectation = {
            'register': {
                'ok': False,
                'errors': ['email', 'Email already registered.']
            }
        }
        # execute once to create user
        result = schema.execute(query, context_value=self.request())
        self.assertTrue(result.data['register']['ok'])

        # execute again to trigger duplicate email
        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.errors)
        self.assertEqual(result.data, expectation)
Exemplo n.º 2
0
    def test_make_move_on_owned_game(self):
        request = self.request()
        user = User.objects.get(pk=3)
        request.user = user

        query = """
        mutation {
          startGame(gameType: "beginner") {
            ok
            gameState {
                id
            }
          }
        }
        """

        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.errors)
        game_state = GameState.objects.get(
            pk=result.data['startGame']['gameState']['id'])

        move_query = """
        mutation {
          makeMove(id: %s, position: 0, action: FLAG) {
            ok
            gameState {
                id
            }
          }
        }
        """ % game_state.id
        result = schema.execute(move_query, context_value=request)
        self.assertIsNone(result.errors)
        self.assertEqual(result.data['makeMove']['ok'], True)
Exemplo n.º 3
0
    def test_login_mutation_error(self):
        request = self.request()

        query = """
        mutation {
            login(
                email: "*****@*****.**",
                password: "******"
            ) {
                ok
                errors
                user {
                    email
                }
            }
        }
        """

        result = schema.execute(query, context_value=request)
        result = schema.execute(query, context_value=request)
        self.assertIsNotNone(result.data['login']['errors'])
        self.assertIsNone(result.data['login']['user'])
Exemplo n.º 4
0
    def test_start_game_without_a_user(self):
        request = self.request()
        request.user = AnonymousUser()
        query = """
        mutation {
          startGame(gameType: "beginner") {
            ok
            gameState {
                id
            }
          }
        }
        """

        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.errors)
        self.assertEqual(result.data['startGame']['ok'], True)
        self.assertIsNotNone(result.data['startGame']['gameState']['id'])
Exemplo n.º 5
0
    def test_register_mutation_success(self):
        request = self.request()
        query = """
        mutation {
          register(
                email: "*****@*****.**",
                password: "******",
            )
          {
            ok
            errors
          }
        }
        """

        expectation = {'register': {'ok': True, 'errors': None}}
        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.errors)
        self.assertEqual(result.data, expectation)
Exemplo n.º 6
0
    def test_login_mutation_success(self):
        request = self.request()
        query = """
        mutation {
            login(
                email: "*****@*****.**",
                password: "******"
            ) {
                ok
                errors
                user {
                    email
                }
            }
        }
        """

        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.data['login']['errors'])
        self.assertEqual(result.data['login']['user']['email'],
                         '*****@*****.**')
Exemplo n.º 7
0
    def test_start_game_with_a_user(self):
        request = self.request()
        user = User.objects.get(pk=3)
        request.user = user

        query = """
        mutation {
          startGame(gameType: "beginner") {
            ok
            gameState {
                id
            }
          }
        }
        """

        result = schema.execute(query, context_value=request)
        self.assertIsNone(result.errors)
        self.assertEqual(result.data['startGame']['ok'], True)
        self.assertIsNotNone(result.data['startGame']['gameState']['id'])

        game_state = GameState.objects.get(
            pk=result.data['startGame']['gameState']['id'])
        self.assertEqual(game_state.owning_player, user)