Exemplo n.º 1
0
    def test_get_meesages(self):
        self.assertFalse(
            Message.objects.filter(sender=self.user1,
                                   reciever=self.user2).exists())

        messages_1to2 = MessageFactory.create_batch(3,
                                                    sender=self.user1,
                                                    reciever=self.user2)
        messages_2to1 = MessageFactory.create_batch(5,
                                                    sender=self.user1,
                                                    reciever=self.user2)
        messages_1to2_2 = MessageFactory.create_batch(2,
                                                      sender=self.user1,
                                                      reciever=self.user2)

        response_user2 = self.user2_client.get(self.user1_path,
                                               data=self.example_data)
        response_user1 = self.user1_client.get(self.user2_path,
                                               data=self.example_data)
        self.assertEqual(response_user1.data["results"],
                         response_user2.data["results"])
        self.assertEqual(response_user1.data["count"], 10)

        result_ids = [x["id"] for x in response_user1.data["results"]]
        expected_ids = [
            x.id for x in messages_1to2 + messages_2to1 + messages_1to2_2
        ]
        expected_ids.reverse()
        self.assertEqual(expected_ids, result_ids)
Exemplo n.º 2
0
class TestMessageCategories(unittest.TestCase):
    def setUp(self):
        self.message = MessageFactory(user=None)
        self.category = CategoryFactory()

    def tearDown(self):
        self.message.delete()
        self.category.delete()

    def test_add_category(self):
        before = len(self.message.category.all())
        self.message.category.add(self.category)
        self.assertEqual(len(self.message.category.all()), before + 1)

    def test_added_category_stored(self):
        self.message.category.add(self.category)
        m = Message.objects.get(id=self.message.pk)
        self.assertIn(self.category, m.category.all())

    def test_added_category_twice(self):
        before = len(self.message.category.all())
        self.message.category.add(self.category)
        self.message.category.add(self.category)
        self.assertEqual(len(self.message.category.all()), before + 1)

    def test_remove_category(self):
        self.message.category.add(self.category)
        before = self.message.category.count()
        self.message.category.remove(self.category)
        self.assertNotIn(self.category, self.message.category.all())
        self.assertEqual(self.message.category.count(), before - 1)
Exemplo n.º 3
0
    def handle(self, *args, **options):

        if environ['DJANGO_SETTINGS_MODULE'] != "olaf.settings.dev":
            raise CommandError('This command can only be run in the development environment')

        user = User.objects.get(id=options['user_id'])
        phone_numbers = PhoneNumber.objects.filter(contact__user=user)

        # messages sent by the contacts of our user
        for phone_number in phone_numbers:
            MessageFactory.create_batch(random.randint(5, 25), sender=phone_number, user=user)

        print("Created messages for all contacts of user %d" % options['user_id'])
Exemplo n.º 4
0
    def test_blocked_user_meesages(self):
        self.assertFalse(
            Message.objects.filter(sender=self.user1,
                                   reciever=self.user2).exists())

        messages_not_blocked = MessageFactory(sender=self.user1,
                                              reciever=self.user2,
                                              is_blocked=False)
        MessageFactory(sender=self.user1, reciever=self.user2, is_blocked=True)

        response = self.user1_client.get(self.user2_path,
                                         data=self.example_data)
        self.assertEqual(response.data["count"], 1)
        self.assertEqual(response.data["results"][0]["id"],
                         messages_not_blocked.id)
Exemplo n.º 5
0
class TestMessageLocation(unittest.TestCase):
    def setUp(self):
        self.message = MessageFactory()

    def tearDown(self):
        user = self.message.user
        self.message.delete()
        user.delete()

    def test_location_latitude(self):
        self.assertIsNotNone(self.message.location.x)

    def test_location_longitude(self):
        self.assertIsNotNone(self.message.location.y)

    def test_location(self):
        self.assertIsNotNone(self.message.location)
Exemplo n.º 6
0
    def handle(self, *args, **options):

        if environ['DJANGO_SETTINGS_MODULE'] != "olaf.settings.dev":
            raise CommandError(
                'This command can only be run in the development environment')

        user = User.objects.get(id=options['user_id'])
        phone_numbers = PhoneNumber.objects.filter(contact__user=user)

        # messages sent by the contacts of our user
        for phone_number in phone_numbers:
            MessageFactory.create_batch(random.randint(5, 25),
                                        sender=phone_number,
                                        user=user)

        print("Created messages for all contacts of user %d" %
              options['user_id'])
Exemplo n.º 7
0
    def test_get_meesages_read_datetime_set(self):
        message = MessageFactory(sender=self.user1, reciever=self.user2)
        self.assertEqual(message.read_datetime, None)

        self.user1_client.get(self.user2_path, data=self.example_data)
        message = Message.objects.get(id=message.id)
        self.assertEqual(message.read_datetime, None)

        self.user2_client.get(self.user1_path, data=self.example_data)
        message = Message.objects.get(id=message.id)
        self.assertNotEqual(message.read_datetime, None)
Exemplo n.º 8
0
 def handle(self, *args, **options):
     n = options["nr_messages"]
     MessageFactory.create_batch(n)
Exemplo n.º 9
0
 def setUp(self):
     self.user = UserFactory()
     self.region = RegionFactory()
     self.message = MessageFactory.build(georegion=self.region)
Exemplo n.º 10
0
 def setUp(self):
     self.message = MessageFactory(user=None)
     self.category = CategoryFactory()
Exemplo n.º 11
0
 def setUp(self):
     self.message = MessageFactory()