示例#1
0
 def test_diff(self):
     s1 = ["a", "b", "c", "d"]
     s2 = ["a", "c"]
     x1 = Scopes(s1)
     x2 = Scopes(s2)
     x3 = x1.diff(x2)
     self.assertCountEqual(x3.scopes, ["b", "d"])
 def test_getters(self):
     dt = pytz.utc.localize(datetime.utcnow())
     x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                       "token1", dt)
     self.assertEqual(x.team_id, "TEST01")
     self.assertEqual(x.user_id, "U101")
     self.assertEqual(x.team_name, "team1")
     self.assertEqual(x.scopes, Scopes("scope1"))
     self.assertEqual(x.token, "token1")
     self.assertEqual(x.last_update, dt)
示例#3
0
 def test_add(self):
     s1 = ["a", "b", "c"]
     s2 = ["d", "e", "a"]
     x1 = Scopes(s1)
     self.assertIsInstance(x1, Scopes)
     x2 = Scopes(s2)
     self.assertIsInstance(x2, Scopes)
     x3 = x1 + x2
     self.assertIsInstance(x3, Scopes)
     self.assertCountEqual(x3.scopes, ["a", "b", "c", "d", "e"])
    def test_store_1(self):
        dt = pytz.utc.localize(datetime.utcnow())
        x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                          "token1", dt)

        x.store(self.connection)
        # store again to verify overwriting existing works
        x.store(self.connection)

        y = Authorization("TEST01", "U102", "team2", "user2", Scopes("scope2"),
                          "token2", dt)
        y.store(self.connection)
 def test_json_serialization(self):
     dt = pytz.utc.localize(datetime.utcnow())
     x = Authorization("TEST01", "U101", "team1", "user1",
                       Scopes(["scope1"]), "token1", dt)
     json_str = x.json_dumps()
     y = Authorization.json_loads(json_str)
     self.assertEqual(x, y)
    def test_count(self):
        TestAuthorization.remove_test_data()

        # first should be zero
        self.assertEqual(
            Authorization.get_count_for_team(self.connection, "TEST01"), 0)
        # now lets create and store two objects
        x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                          "token1")

        x.store(self.connection)

        y = Authorization("TEST01", "U102", "team2", "user1", Scopes("scope2"),
                          "token2")
        y.store(self.connection)

        # should be 2
        self.assertEqual(
            Authorization.get_count_for_team(self.connection, "TEST01"), 2)
    def test_get_team_name(self):
        # fetching a team name that exits
        x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                          "token1")
        x.store(self.connection)
        team_name = Authorization.fetch_workspace_name(self.connection,
                                                       "TEST01")
        self.assertEqual(team_name, x.team_name)

        # trying to fetch a team name that does not exist
        team_name = Authorization.fetch_workspace_name(self.connection,
                                                       "does not exit")
        self.assertIsNone(team_name)
    def test_fetch_normal(self):
        """store and then fetch same record. check if its identical"""
        x = Authorization("TEST01", "U101", "team1", "user2", Scopes("scope1"),
                          "token1")
        x.store(self.connection)

        y = Authorization.fetchFromDb(self.connection, "TEST01", "U101")
        self.assertEqual(x.team_id, y.team_id)
        self.assertEqual(x.user_id, y.user_id)
        self.assertEqual(x.team_name, y.team_name)
        self.assertEqual(x.scopes, y.scopes)
        self.assertEqual(x.token, y.token)
        self.assertEqual(x.last_update, y.last_update)
    def test_delete(self):
        x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                          "token1", pytz.utc.localize(datetime.utcnow()))
        x.store(self.connection)

        y = Authorization.fetchFromDb(self.connection, "TEST01", "U101")
        self.assertEqual(x.team_id, y.team_id)
        self.assertEqual(x.user_id, y.user_id)
        self.assertEqual(x.team_name, y.team_name)
        self.assertEqual(x.scopes, y.scopes)
        self.assertEqual(x.token, y.token)

        x.delete(self.connection)
        y = Authorization.fetchFromDb(self.connection, "TEST01", "U101")
        self.assertIsNone(y)
示例#10
0
    def test_add_scope(self):
        s = ["a", "b", "c"]
        x = Scopes(s)

        # add good scope
        x.add("d")
        self.assertCountEqual(x.scopes, ["a", "b", "c", "d"])

        # add bad scope
        with self.assertRaises(ValueError):
            x.add("b,")
 def test_is_owner_true(self):
     x = Authorization("TEST01", "U101", "team1", "user1",
                       Scopes(["scope1", Scopes.SCOPE_COMMANDS]), "token1")
     self.assertTrue(x.is_owner())
示例#12
0
    def test_eq(self):
        s1 = Scopes(["a", "b", "c", "d"])
        s2 = Scopes(["a", "b", "c", "d"])

        self.assertEqual(s1, s2)
示例#13
0
 def test_create_ignore_empty_string_multiple(self):
     x = Scopes.create_from_string("ab,,x,,a")
     self.assertEqual(x.get_count(), 3)
示例#14
0
 def test_getters(self):
     s = ["first:xxx", "second:yyy", "third:zzz"]
     x = Scopes(s)
     self.assertCountEqual(x.scopes, s)
     self.assertEqual(x.get_string(), "first:xxx,second:yyy,third:zzz")
示例#15
0
 def test_create5(self):
     x = Scopes.create_from_file("scopes")
     self.assertTrue("channels:history" in x)
示例#16
0
 def test_create_ignore_empty_string_single(self):
     x = Scopes.create_from_string("")
     self.assertEqual(x.get_count(), 0)
示例#17
0
 def test_create3(self):
     s = ["first:,xxx", "second:yyy", "third:zzz"]
     with self.assertRaises(ValueError):
         x = Scopes(s)
示例#18
0
 def test_create4(self):
     x = Scopes.create_from_string("first:xxx,second:yyy,third:zzz")
     self.assertCountEqual(x.scopes,
                           ["first:xxx", "second:yyy", "third:zzz"])
示例#19
0
 def test_create2(self):
     x = Scopes(dict())
     self.assertEqual(x.scopes, set())
示例#20
0
 def test_create1(self):
     x = Scopes()
     self.assertEqual(x.scopes, set())
 def test_is_owner_false(self):
     x = Authorization("TEST01", "U101", "team1", "user1",
                       Scopes(["scope1"]), "token1")
     self.assertFalse(x.is_owner())
 def test_create_minimal(self):
     x = Authorization("TEST01", "U101", "team1", "user1", Scopes("scope1"),
                       "token1")
    def test_store_2(self):
        dt = pytz.utc.localize(datetime.utcnow())
        x = Authorization("TEST01", "U102", "team1", "user2", Scopes("scope1"),
                          "token1")

        x.store(self.connection)
示例#24
0
 def test_get_list(self):
     s = ["a", "d", "c", "b"]
     x = Scopes(s)
     self.assertEqual(x.get_list(), ["a", "b", "c", "d"])
示例#25
0
    def test_ne(self):
        s1 = Scopes(["a", "b", "c", "d"])
        s2 = Scopes(["a", "b", "c", "e"])

        self.assertNotEqual(s1, s2)