Ejemplo n.º 1
0
 def _test_response_body(self, body: dict):
     # Response Body should contain 'self', 'email', 'profile_picture'
     # and the names 'first_name' and 'last_name', both which should be present,
     # even if their value is NULL
     assert all_keys_present(
         body, (
             "self", "email", "first_name", "last_name", "profile_picture"
         )
     )
     assert all_keys_present(
         body.get("profile_picture"), ("image", "background")
     )
Ejemplo n.º 2
0
def test__all_keys_present():
    assert all_keys_present(
        {"okay": 2}, ("okay",)
    )
    assert all_keys_present(
        {"okay": 2, "random": "bruh"}, ("okay",)
    )
    assert all_keys_present(
        {"okay": 2, "random": "bruh"}, ("random", "okay")
    )

    assert not all_keys_present(
        {"okay": 2, "random": "bruh"}, ("okay",), strict=True
    )
Ejemplo n.º 3
0
 def test010_cors_preflight(self):
     viewname = "tokens:obtain_delete"
     url = reverse(viewname)
     res = self.client.options(url,
                               HTTP_ORIGIN="http://example.org",
                               Access_Control_Request_Method="POST")
     self.assertEqual(res.status_code, status.HTTP_200_OK)
     assert all_keys_present(res._headers,
                             ('access-control-allow-origin', ),
                             strict=False)
Ejemplo n.º 4
0
    def test010_encode_declarative(self, data_dump_path):
        with open(data_dump_path, "w") as fout:
            json.dump(
                [self.declarative_instance],
                fout,
                indent=4,
                cls=SqlaDeclarativeEncoder
            )

        with open(data_dump_path, "r") as fin:
            content = json.load(fin)
            assert type(content) == list
            assert len(content) == 1
            assert all_keys_present(
                content[0],
                ("pk", "age", "name", "date_of_birth"),
                strict=True
            )
Ejemplo n.º 5
0
 def test010_cors_preflight(self):
     """
     GIVEN I am on a different domain
         than the one this application is hosted on
     WHEN I make a CORS preflight request
     THEN I should receive the proper CORS headers in the response
     """
     viewname = "tokens:obtain_delete"
     url = reverse(viewname)
     res = self.client.options(
         url,
         HTTP_ORIGIN="http://example.org",
         Access_Control_Request_Method="POST"
     )
     self.assertEqual(res.status_code, status.HTTP_200_OK)
     assert all_keys_present(
         res._headers,
         ('access-control-allow-origin',),
         strict=False
     )
Ejemplo n.º 6
0
 def _test_response_body(self, body: dict):
     assert all_keys_present(body,
                             ("title", "primary_color", "secondary_color",
                              "start", "end", "allDay", "self"))
     # Make sure these two attributes really do not get output
     assert not all_keys_present(body, ("creator", "id"))